Merge pull request #13936 from keszybz/format-table-uninhibited

Output tables at full width if piped
This commit is contained in:
Anita Zhang 2019-11-05 15:03:15 -08:00 committed by GitHub
commit f03378805f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 10 deletions

View File

@ -25,7 +25,7 @@ int reset_all_signal_handlers(void) {
/* On Linux the first two RT signals are reserved by
* glibc, and sigaction() will return EINVAL for them. */
if ((sigaction(sig, &sa, NULL) < 0))
if (sigaction(sig, &sa, NULL) < 0)
if (errno != EINVAL && r >= 0)
r = -errno;
}

View File

@ -2,6 +2,7 @@
#include <ctype.h>
#include <net/if.h>
#include <unistd.h>
#include "alloc-util.h"
#include "fd-util.h"
@ -1611,10 +1612,12 @@ int table_print(Table *t, FILE *f) {
}
/* Calculate effective table width */
if (t->width == (size_t) -1)
table_effective_width = pager_have() ? table_requested_width : MIN(table_requested_width, columns());
else
if (t->width != (size_t) -1)
table_effective_width = t->width;
else if (pager_have() || !isatty(STDOUT_FILENO))
table_effective_width = table_requested_width;
else
table_effective_width = MIN(table_requested_width, columns());
if (table_maximum_width != (size_t) -1 && table_effective_width > table_maximum_width)
table_effective_width = table_maximum_width;

View File

@ -1,5 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <unistd.h>
#include "alloc-util.h"
#include "format-table.h"
#include "string-util.h"
@ -154,12 +156,20 @@ int main(int argc, char *argv[]) {
assert_se(table_format(t, &formatted) >= 0);
printf("%s\n", formatted);
assert_se(streq(formatted,
" no a long f… no a long f… a long fi…\n"
" no fäää no fäää fäää \n"
" yes fäää yes fäää fäää \n"
" yes xxx yes xxx xxx \n"
"5min 5min \n"));
if (isatty(STDOUT_FILENO))
assert_se(streq(formatted,
" no a long f… no a long f… a long fi…\n"
" no fäää no fäää fäää \n"
" yes fäää yes fäää fäää \n"
" yes xxx yes xxx xxx \n"
"5min 5min \n"));
else
assert_se(streq(formatted,
" no a long field no a long field a long field\n"
" no fäää no fäää fäää \n"
" yes fäää yes fäää fäää \n"
" yes xxx yes xxx xxx \n"
"5min 5min \n"));
test_issue_9549();