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>
#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
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