Skip to content

Commit 74547f3

Browse files
authored
Text output: removed trailing spaces for right-padding of tables (#2290)
* Simplified table.Render method * Removed right padding from tables
1 parent 0af0b44 commit 74547f3

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Diff for: table/table.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package table
1818
import (
1919
"fmt"
2020
"math"
21+
"strings"
2122
)
2223

2324
// ColumnWidthMode is used to configure columns type
@@ -127,7 +128,7 @@ func (t *Table) Render() string {
127128

128129
res := ""
129130
for _, row := range t.rows {
130-
separator := ""
131+
line := ""
131132
for x, cell := range row.cells {
132133
selectedWidth := widths[x]
133134
if x < len(t.columnsWidthMode) {
@@ -141,11 +142,13 @@ func (t *Table) Render() string {
141142
if selectedWidth < minimum[x] {
142143
selectedWidth = minimum[x]
143144
}
144-
res += separator
145-
res += cell.Pad(selectedWidth)
146-
separator = " "
145+
if x > 0 {
146+
line += " "
147+
}
148+
line += cell.Pad(selectedWidth)
147149
}
148-
res += "\n"
150+
151+
res += strings.TrimRight(line, " ") + "\n"
149152
}
150153
return res
151154
}

0 commit comments

Comments
 (0)