diff options
author | Karel Zak | 2016-06-02 12:31:45 +0200 |
---|---|---|
committer | Karel Zak | 2016-06-02 12:31:45 +0200 |
commit | 8f0ac5792191499292a2d23c8ebd743695af70b7 (patch) | |
tree | 0f4d515176e0376e9a71fd897d52706ddf740c71 | |
parent | tests: check for mount(8) in minix test (diff) | |
download | kernel-qcow2-util-linux-8f0ac5792191499292a2d23c8ebd743695af70b7.tar.gz kernel-qcow2-util-linux-8f0ac5792191499292a2d23c8ebd743695af70b7.tar.xz kernel-qcow2-util-linux-8f0ac5792191499292a2d23c8ebd743695af70b7.zip |
lib/ttyutils: use stdout for get_terminal_width()
We use the function to be sure with *output* width. Note that the
current code (with STDIN) is broken because in some situations
libsmartcols is not able to detect terminal width and fall back to
default 80.
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r-- | lib/ttyutils.c | 4 | ||||
-rw-r--r-- | libsmartcols/src/table_print.c | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/lib/ttyutils.c b/lib/ttyutils.c index 1a1d8bc38..4e62c20d6 100644 --- a/lib/ttyutils.c +++ b/lib/ttyutils.c @@ -15,11 +15,11 @@ int get_terminal_width(int default_width) #if defined(TIOCGWINSZ) struct winsize w_win; - if (ioctl (STDIN_FILENO, TIOCGWINSZ, &w_win) == 0) + if (ioctl (STDOUT_FILENO, TIOCGWINSZ, &w_win) == 0) width = w_win.ws_col; #elif defined(TIOCGSIZE) struct ttysize t_win; - if (ioctl (STDIN_FILENO, TIOCGSIZE, &t_win) == 0) + if (ioctl (STDOUT_FILENO, TIOCGSIZE, &t_win) == 0) width = t_win.ts_cols; #endif diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c index 20b015344..8034a7834 100644 --- a/libsmartcols/src/table_print.c +++ b/libsmartcols/src/table_print.c @@ -1255,7 +1255,7 @@ static int initialize_printing(struct libscols_table *tb, struct libscols_buffer if (tb->is_term) { tb->termwidth = get_terminal_width(80); - if (tb->termreduce < tb->termwidth) + if (tb->termreduce > 0 && tb->termreduce < tb->termwidth) tb->termwidth -= tb->termreduce; bufsz = tb->termwidth; } else |