From: Karel Zak Date: Tue, 19 Feb 2013 13:10:24 +0000 (+0100) Subject: lib/tty: don't truncate output on non-terminals X-Git-Tag: v2.23-rc1~203 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3785056ca8115d4c0b402abf788219be6203ebb3;p=thirdparty%2Futil-linux.git lib/tty: don't truncate output on non-terminals for example: $ findmnt | cat $ lslocks > foo the output should not be truncated. Signed-off-by: Karel Zak --- diff --git a/include/tt.h b/include/tt.h index 212150a36b..603844f668 100644 --- a/include/tt.h +++ b/include/tt.h @@ -33,6 +33,7 @@ enum { struct tt { size_t ncols; /* number of columns */ size_t termwidth; /* terminal width */ + int is_term; /* is a tty? */ int flags; int first_run; diff --git a/lib/tt.c b/lib/tt.c index 310c47e9fa..cbe4e3b4d0 100644 --- a/lib/tt.c +++ b/lib/tt.c @@ -535,6 +535,9 @@ static void recount_widths(struct tt *tb, char *buf, size_t bufsz) extremes += cl->is_extreme; } + if (!tb->is_term) + return; + /* reduce columns with extreme fields */ if (width > tb->termwidth && extremes) { @@ -874,8 +877,11 @@ int tt_print_table(struct tt *tb) if (!tb) return -1; - if (tb->first_run && !tb->termwidth) { - tb->termwidth = get_terminal_width(); + if (tb->first_run) { + tb->is_term = isatty(STDOUT_FILENO); + + if (tb->is_term && !tb->termwidth) + tb->termwidth = get_terminal_width(); if (tb->termwidth <= 0) tb->termwidth = 80; }