summaryrefslogtreecommitdiffstats
path: root/libsmartcols/src/table_print.c
diff options
context:
space:
mode:
authorKarel Zak2016-09-13 14:06:01 +0200
committerKarel Zak2016-09-13 14:06:01 +0200
commit19055a25ed2a28d005460ee41627d2595ae7ad34 (patch)
treeff37d6bd2ff5f214d74d305723bad0b83fe15319 /libsmartcols/src/table_print.c
parentlibsmartcols: add application to test library features (diff)
downloadkernel-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.c16
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;