TT_FL_ASCII = (1 << 2),
TT_FL_NOHEADINGS = (1 << 3),
TT_FL_EXPORT = (1 << 4),
+ TT_FL_MAX = (1 << 5), /* maximalize column width if possible */
/*
* Column flags
*/
- TT_FL_TRUNC = (1 << 5), /* truncate fields data if necessary */
- TT_FL_TREE = (1 << 6), /* use tree "ascii art" */
- TT_FL_RIGHT = (1 << 7), /* align to the right */
- TT_FL_STRICTWIDTH = (1 << 8), /* don't reduce width if column is empty */
- TT_FL_NOEXTREMES = (1 << 9), /* ignore extreme fields when count column width*/
+ TT_FL_TRUNC = (1 << 10), /* truncate fields data if necessary */
+ TT_FL_TREE = (1 << 11), /* use tree "ascii art" */
+ TT_FL_RIGHT = (1 << 12), /* align to the right */
+ TT_FL_STRICTWIDTH = (1 << 13), /* don't reduce width if column is empty */
+ TT_FL_NOEXTREMES = (1 << 14), /* ignore extreme fields when count column width*/
- TT_FL_FREEDATA = (1 << 10), /* free() data in tt_free_table() */
+ TT_FL_FREEDATA = (1 << 15), /* free() data in tt_free_table() */
};
struct tt {
};
extern struct tt *tt_new_table(int flags);
+extern int tt_get_flags(struct tt *tb);
+extern void tt_set_flags(struct tt *tb, int flags);
extern void tt_free_table(struct tt *tb);
extern void tt_remove_lines(struct tt *tb);
extern int tt_print_table(struct tt *tb);
return tb;
}
+/*
+ * Be careful, the best way is to use:
+ *
+ * tt_set_flags(tb, tb_get_flags(tb) | TT_FL_xxx));
+ */
+void tt_set_flags(struct tt *tb, int flags)
+{
+ if (tb)
+ tb->flags = flags;
+}
+
+int tt_get_flags(struct tt *tb)
+{
+ return tb ? tb->flags : 0;
+}
+
void tt_set_stream(struct tt *tb, FILE *out)
{
if (!tb)
}
}
+ /* Cool, we have extra space, use it! */
if (width < tb->termwidth) {
/* try to found extreme column which fits into available space
*/
break;
}
}
- if (width < tb->termwidth) {
+
+ if (width < tb->termwidth && (tb->flags & TT_FL_MAX)) {
+ /* try enlarge all columns */
+ while (width < tb->termwidth) {
+ list_for_each(p, &tb->tb_columns) {
+ struct tt_column *cl =
+ list_entry(p, struct tt_column, cl_columns);
+ cl->width++;
+ width++;
+ if (width == tb->termwidth)
+ break;
+ }
+ }
+ } else if (width < tb->termwidth) {
/* enalarge the last column */
struct tt_column *cl = list_entry(
tb->tb_columns.prev, struct tt_column, cl_columns);
}
width = cl->width;
- if (is_last_column(tb, cl) && len < width)
+ if (is_last_column(tb, cl) && len < width && !(tb->flags & TT_FL_MAX))
width = len;
/* truncate data */