]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: add reduce term width functionality
authorKarel Zak <kzak@redhat.com>
Wed, 19 Mar 2014 16:20:57 +0000 (17:20 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 3 Apr 2014 10:29:16 +0000 (12:29 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/libsmartcols.h.in
libsmartcols/src/smartcolsP.h
libsmartcols/src/table.c
libsmartcols/src/table_print.c

index c5875fd1c6aa1b5e6e806bf1448b587023eabcbe..93b205e2f0e694a42655093cf4f01fc0ff1386ee 100644 (file)
@@ -134,6 +134,7 @@ extern int scols_table_set_symbols(struct libscols_table *tb, struct libscols_sy
 
 extern int scols_table_set_stream(struct libscols_table *tb, FILE *stream);
 extern FILE *scols_table_get_stream(struct libscols_table *tb);
+extern int scols_table_reduce_termwidth(struct libscols_table *tb, size_t reduce);
 
 /* table_print.c */
 extern int scols_print_table(struct libscols_table *tb);
index d8cf2ee56a02698c839bba605845925ff7273d19..d7211438e67036d4d13ae1d2ef7e8b5044bc1301 100644 (file)
@@ -104,6 +104,7 @@ struct libscols_table {
        size_t  ncols;          /* number of columns */
        size_t  nlines;         /* number of lines */
        size_t  termwidth;      /* terminal width */
+       size_t  termreduce;     /* extra blank space */
        int     is_term;        /* is a tty? */
        int     flags;
        int     first_run;
index 5c45aeeebf7b6f95774d8f5883c02bdfb00622a6..770aaccc2f77c21ff1525736865d0865d6323052 100644 (file)
@@ -270,6 +270,16 @@ FILE *scols_table_get_stream(struct libscols_table *tb)
        return tb ? tb->out: NULL;
 }
 
+int scols_table_reduce_termwidth(struct libscols_table *tb, size_t reduce)
+{
+       assert(tb);
+       if (!tb)
+               return -EINVAL;
+
+       tb->termreduce = reduce;
+       return 0;
+}
+
 /*
  * @tb: table
  * @: number of column (0..N)
index 8504c2c4d24184100ffc6821618af28fec42ab76..2edd185b456865da34da460460a934b9d6708257 100644 (file)
@@ -558,6 +558,7 @@ int scols_print_table(struct libscols_table *tb)
                        tb->termwidth = get_terminal_width();
                if (tb->termwidth <= 0)
                        tb->termwidth = 80;
+               tb->termwidth -= tb->termreduce;
        }
 
        line_sz = tb->termwidth;