summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarel Zak2013-11-22 13:53:29 +0100
committerKarel Zak2014-03-11 11:35:12 +0100
commitb839bd4fa19b86989e74c4493ca51eb1721caea4 (patch)
tree242c41b17d30db3030b3dbf3c19d4eaf7c53678f /lib
parentlib/tt: add tb_get_nlines() (diff)
downloadkernel-qcow2-util-linux-b839bd4fa19b86989e74c4493ca51eb1721caea4.tar.gz
kernel-qcow2-util-linux-b839bd4fa19b86989e74c4493ca51eb1721caea4.tar.xz
kernel-qcow2-util-linux-b839bd4fa19b86989e74c4493ca51eb1721caea4.zip
lib/tt: add TT_FL_MAX to fill screen
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/tt.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/lib/tt.c b/lib/tt.c
index e94524e86..b5beb7ad7 100644
--- a/lib/tt.c
+++ b/lib/tt.c
@@ -216,6 +216,22 @@ struct tt *tt_new_table(int flags)
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)
@@ -587,6 +603,7 @@ static void recount_widths(struct tt *tb, char *buf, size_t bufsz)
}
}
+ /* Cool, we have extra space, use it! */
if (width < tb->termwidth) {
/* try to found extreme column which fits into available space
*/
@@ -617,7 +634,20 @@ static void recount_widths(struct tt *tb, char *buf, size_t bufsz)
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);
@@ -769,7 +799,7 @@ static void print_data(struct tt *tb, struct tt_column *cl, char *data)
}
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 */