Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(table): SuppressTrailingSpaces also removed spaces from the beginning #295

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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