]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/ttyutils: use stdout for get_terminal_width()
authorKarel Zak <kzak@redhat.com>
Thu, 2 Jun 2016 10:31:45 +0000 (12:31 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 2 Jun 2016 10:31:45 +0000 (12:31 +0200)
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>
lib/ttyutils.c
libsmartcols/src/table_print.c

index 1a1d8bc388c683860e8af48e4742a71d503182e4..4e62c20d67f8edea1fead01afd1c8ed6ee30a99f 100644 (file)
@@ -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
 
index 20b015344f1429ee84619d2e7833a39df8908d48..8034a7834f68eea2d60af9964b912122a242994a 100644 (file)
@@ -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