]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/tty: don't truncate output on non-terminals
authorKarel Zak <kzak@redhat.com>
Tue, 19 Feb 2013 13:10:24 +0000 (14:10 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 19 Feb 2013 13:10:24 +0000 (14:10 +0100)
 for example:

$ findmnt | cat
$ lslocks > foo

 the output should not be truncated.

Signed-off-by: Karel Zak <kzak@redhat.com>
include/tt.h
lib/tt.c

index 212150a36b3a75d4e7d32a50a6fd430993298d9e..603844f668c134e6e85a737be233a99d7d2058e1 100644 (file)
@@ -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;
 
index 310c47e9fac93f6dcd73b2fbd467e15a1bcdbbf4..cbe4e3b4d05fc0782cbcfe19969695659c05c8d6 100644 (file)
--- 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;
        }