From 6735efc5bab3318b93106a0a76e20cc24428abf2 Mon Sep 17 00:00:00 2001 From: Ilya Lesikov Date: Thu, 25 Jan 2024 16:52:07 +0300 Subject: [PATCH] fix(table): SuppressTrailingSpaces also removed spaces from the start Signed-off-by: Ilya Lesikov --- table/render_test.go | 12 ++++++------ table/table.go | 7 ++++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/table/render_test.go b/table/render_test.go index 86df53a..d5969eb 100644 --- a/table/render_test.go +++ b/table/render_test.go @@ -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`) } diff --git a/table/table.go b/table/table.go index 4b3f21d..54c33ff 100644 --- a/table/table.go +++ b/table/table.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "strings" + "unicode" "github.com/jedib0t/go-pretty/v6/text" ) @@ -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") }