Skip to content

Commit

Permalink
fix(table): SuppressTrailingSpaces also removed spaces from the start
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Lesikov <ilya@lesikov.com>
  • Loading branch information
ilya-lesikov committed Jan 29, 2024
1 parent 79388bd commit 6735efc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 6 additions & 6 deletions table/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1222,10 +1222,10 @@ func TestTable_Render_SuppressTrailingSpaces(t *testing.T) {

tw.Style().Options = OptionsNoBordersAndSeparators
compareOutput(t, tw.Render(), `
ID TEXT1 DATE TEXT2
U2 Hey 2021-04-19 13:37 Yuh yuh yuh
S12 Uhhhh 2021-04-19 13:37 Some dummy data here
R123 Lobsters 2021-04-19 13:37 I like lobsters
R123 Some big name here and it's pretty big 2021-04-19 13:37 Abcdefghijklmnopqrstuvwxyz
R123 Small name 2021-04-19 13:37 Abcdefghijklmnopqrstuvwxyz`)
ID TEXT1 DATE TEXT2
U2 Hey 2021-04-19 13:37 Yuh yuh yuh
S12 Uhhhh 2021-04-19 13:37 Some dummy data here
R123 Lobsters 2021-04-19 13:37 I like lobsters
R123 Some big name here and it's pretty big 2021-04-19 13:37 Abcdefghijklmnopqrstuvwxyz
R123 Small name 2021-04-19 13:37 Abcdefghijklmnopqrstuvwxyz`)
}
7 changes: 6 additions & 1 deletion table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"strings"
"unicode"

"github.com/jedib0t/go-pretty/v6/text"
)
Expand Down Expand Up @@ -691,7 +692,11 @@ func (t *Table) render(out *strings.Builder) string {
var trimmed []string
sc := bufio.NewScanner(strings.NewReader(outStr))
for sc.Scan() {
trimmed = append(trimmed, strings.TrimSpace(sc.Text()))
trimmed = append(trimmed, strings.TrimRightFunc(
sc.Text(), func(r rune) bool {
return unicode.IsSpace(r)
},
))
}
outStr = strings.Join(trimmed, "\n")
}
Expand Down

0 comments on commit 6735efc

Please sign in to comment.