]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/tt: add reduce term width functionality
authorKarel Zak <kzak@redhat.com>
Fri, 22 Nov 2013 13:06:44 +0000 (14:06 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 11 Mar 2014 10:35:12 +0000 (11:35 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/tt.h
lib/tt.c

index b1fbf927e56f3da125aecda243a225f6c7461c35..781b953aeb9a75f04610d741b239dade0d552700 100644 (file)
@@ -37,6 +37,7 @@ struct tt {
        FILE    *out;           /* output stream */
        size_t  ncols;          /* number of columns */
        size_t  termwidth;      /* terminal width */
+       size_t  termreduce;     /* reduce the original termwidth */
        int     is_term;        /* is a tty? */
        int     flags;
        int     first_run;
@@ -80,6 +81,7 @@ struct tt_line {
 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_set_termreduce(struct tt *tb, size_t re);
 extern void tt_free_table(struct tt *tb);
 extern void tt_remove_lines(struct tt *tb);
 extern int tt_print_table(struct tt *tb);
index b5beb7ad734ec8e50e762369e9dcbc055b78d351..3cca4817f6a1e6a6e4a3c8f14d9a967509e906e1 100644 (file)
--- a/lib/tt.c
+++ b/lib/tt.c
@@ -239,6 +239,17 @@ void tt_set_stream(struct tt *tb, FILE *out)
        tb->out = out;
 }
 
+/*
+ * Reduce terminal size, the final table size will be
+ * termwidth - termreduce.
+ */
+void tt_set_termreduce(struct tt *tb, size_t re)
+{
+       if (!tb)
+               return;
+       tb->termreduce = re;
+}
+
 size_t tb_get_nlines(struct tt *tb)
 {
        struct list_head *p;
@@ -943,6 +954,8 @@ int tt_print_table(struct tt *tb)
                        tb->termwidth = get_terminal_width();
                if (tb->termwidth <= 0)
                        tb->termwidth = 80;
+
+               tb->termwidth -= tb->termreduce;
        }
 
        line_sz = tb->termwidth;