table: drop trailing white spaces of the last cell in row

Fixes #18415.
This commit is contained in:
Yu Watanabe
2021-02-19 14:04:32 +09:00
parent 1f3315b8bd
commit 71894e1831
2 changed files with 26 additions and 20 deletions
+6
View File
@@ -2258,6 +2258,12 @@ int table_print(Table *t, FILE *f) {
if (!aligned)
return -ENOMEM;
/* Drop trailing white spaces of last column when no cosmetics is set. */
if (j == display_columns - 1 &&
(!colors_enabled() || !table_data_color(d)) &&
(!urlify_enabled() || !d->url))
delete_trailing_chars(aligned, NULL);
free_and_replace(buffer, aligned);
field = buffer;
}
+20 -20
View File
@@ -29,7 +29,7 @@ static void test_issue_9549(void) {
printf("%s\n", formatted);
assert_se(streq(formatted,
"NAME TYPE RO USAGE CREATED MODIFIED \n"
"NAME TYPE RO USAGE CREATED MODIFIED\n"
"foooo raw no 673.6M Wed 2018-07-11 00:10:33 J… Wed 2018-07-11 00:16:00 JST\n"
));
}
@@ -72,7 +72,7 @@ static void test_multiline(void) {
"FOO BAR\n"
"three two\n"
"different lines\n"
"lines \n"));
"lines \n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, (size_t) -1);
@@ -82,7 +82,7 @@ static void test_multiline(void) {
"FOO BAR\n"
"three two\n"
"different lines\n"
"lines \n"));
"lines \n"));
formatted = mfree(formatted);
assert_se(table_add_many(table,
@@ -123,7 +123,7 @@ static void test_multiline(void) {
"FOO BAR\n"
"three two\n"
"different lines\n"
"lines \n"
"lines \n"
"short a\n"
" pair\n"
"short2 a\n"
@@ -138,7 +138,7 @@ static void test_multiline(void) {
"FOO BAR\n"
"three two\n"
"different lines\n"
"lines \n"
"lines \n"
"short a\n"
" pair\n"
"short2 a\n"
@@ -186,7 +186,7 @@ static void test_strv(void) {
"FOO BAR\n"
"three two\n"
"different lines\n"
"lines \n"));
"lines \n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, (size_t) -1);
@@ -196,7 +196,7 @@ static void test_strv(void) {
"FOO BAR\n"
"three two\n"
"different lines\n"
"lines \n"));
"lines \n"));
formatted = mfree(formatted);
assert_se(table_add_many(table,
@@ -237,7 +237,7 @@ static void test_strv(void) {
"FOO BAR\n"
"three two\n"
"different lines\n"
"lines \n"
"lines \n"
"short a\n"
" pair\n"
"short2 a\n"
@@ -252,7 +252,7 @@ static void test_strv(void) {
"FOO BAR\n"
"three two\n"
"different lines\n"
"lines \n"
"lines \n"
"short a\n"
" pair\n"
"short2 a\n"
@@ -333,7 +333,7 @@ static void test_strv_wrapped(void) {
assert_se(streq(formatted,
"FOO BAR\n"
"three different two lines\n"
"lines \n"
"lines \n"
"short a pair\n"
"short2 a eight line ćęłł\n"
" ___5___ ___6___…\n"));
@@ -345,7 +345,7 @@ static void test_strv_wrapped(void) {
assert_se(streq(formatted,
"FOO BAR\n"
"three different two lines\n"
"lines \n"
"lines \n"
"short a pair\n"
"short2 a eight line ćęłł\n"
" ___5___ ___6___\n"
@@ -358,7 +358,7 @@ static void test_strv_wrapped(void) {
assert_se(streq(formatted,
"FOO BAR\n"
"three different two lines\n"
"lines \n"
"lines \n"
"short a pair\n"
"short2 a eight line ćęłł\n"
" ___5___ ___6___\n"
@@ -493,17 +493,17 @@ int main(int argc, char *argv[]) {
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"));
" 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"));
" no fäää no fäää fäää\n"
" yes fäää yes fäää fäää\n"
" yes xxx yes xxx xxx\n"
"5min 5min \n"));
test_issue_9549();
test_multiline();