diff options
author | Karel Zak | 2016-09-13 14:06:01 +0200 |
---|---|---|
committer | Karel Zak | 2016-09-13 14:06:01 +0200 |
commit | 19055a25ed2a28d005460ee41627d2595ae7ad34 (patch) | |
tree | ff37d6bd2ff5f214d74d305723bad0b83fe15319 /libsmartcols/src/table_print.c | |
parent | libsmartcols: add application to test library features (diff) | |
download | kernel-qcow2-util-linux-19055a25ed2a28d005460ee41627d2595ae7ad34.tar.gz kernel-qcow2-util-linux-19055a25ed2a28d005460ee41627d2595ae7ad34.tar.xz kernel-qcow2-util-linux-19055a25ed2a28d005460ee41627d2595ae7ad34.zip |
libsmartcols: add functions to control terminal usage
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols/src/table_print.c')
-rw-r--r-- | libsmartcols/src/table_print.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c index 7d5fe0ffa..ff8a23686 100644 --- a/libsmartcols/src/table_print.c +++ b/libsmartcols/src/table_print.c @@ -23,7 +23,6 @@ #include <ctype.h> #include "mbsalign.h" -#include "ttyutils.h" #include "carefulputc.h" #include "smartcolsP.h" @@ -1334,13 +1333,18 @@ static int initialize_printing(struct libscols_table *tb, struct libscols_buffer scols_table_set_symbols(tb, NULL); /* use default */ if (tb->format == SCOLS_FMT_HUMAN) - tb->is_term = isatty(STDOUT_FILENO) ? 1 : 0; + tb->is_term = tb->termforce == SCOLS_TERMFORCE_NEVER ? 0 : + tb->termforce == SCOLS_TERMFORCE_ALWAYS ? 1 : + isatty(STDOUT_FILENO); if (tb->is_term) { - tb->termwidth = get_terminal_width(80); - if (tb->termreduce > 0 && tb->termreduce < tb->termwidth) - tb->termwidth -= tb->termreduce; - bufsz = tb->termwidth; + size_t width = (size_t) scols_table_get_termwidth(tb); + + if (tb->termreduce > 0 && tb->termreduce < width) { + width -= tb->termreduce; + scols_table_set_termwidth(tb, width); + } + bufsz = width; } else bufsz = BUFSIZ; |