Skip to content

Commit

Permalink
Text output: removed trailing spaces for right-padding of tables (#2290)
Browse files Browse the repository at this point in the history
* Simplified table.Render method

* Removed right padding from tables
  • Loading branch information
cmaglie committed Sep 4, 2023
1 parent 0af0b44 commit 74547f3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package table
import (
"fmt"
"math"
"strings"
)

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

res := ""
for _, row := range t.rows {
separator := ""
line := ""
for x, cell := range row.cells {
selectedWidth := widths[x]
if x < len(t.columnsWidthMode) {
Expand All @@ -141,11 +142,13 @@ func (t *Table) Render() string {
if selectedWidth < minimum[x] {
selectedWidth = minimum[x]
}
res += separator
res += cell.Pad(selectedWidth)
separator = " "
if x > 0 {
line += " "
}
line += cell.Pad(selectedWidth)
}
res += "\n"

res += strings.TrimRight(line, " ") + "\n"
}
return res
}
Expand Down

0 comments on commit 74547f3

Please sign in to comment.