1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Tue, 2 Feb 2021 01:47:58 +0900
Subject: table: drop trailing white spaces of the last cell in row
Fixes #18415.
(cherry picked from commit 71894e18313e41a72cecdc77fea5037f95d6903f)
---
src/shared/format-table.c | 6 ++++++
src/test/test-format-table.c | 40 ++++++++++++++++++++--------------------
2 files changed, 26 insertions(+), 20 deletions(-)
diff --git a/src/shared/format-table.c b/src/shared/format-table.c
index a13a198..2dc95e9 100644
--- a/src/shared/format-table.c
+++ b/src/shared/format-table.c
@@ -2155,6 +2155,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;
}
diff --git a/src/test/test-format-table.c b/src/test/test-format-table.c
index 24ee1df..b2943e6 100644
--- a/src/test/test-format-table.c
+++ b/src/test/test-format-table.c
@@ -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();
|