Skip to content

Maximum width excluding spaces #9

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

Merged
merged 2 commits into from
Jul 14, 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
2 changes: 1 addition & 1 deletion guesswidth.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (g *GuessWidth) UpdateMaxWidth(columns []string) []Cols {
}

for n, col := range columns {
width := runewidth.StringWidth(col)
width := runewidth.StringWidth(strings.TrimSpace(col))
if width > g.Widths[n].Width {
g.Widths[n].Width = width
}
Expand Down
26 changes: 13 additions & 13 deletions guesswidth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func TestGuessWidth_ReadAll(t *testing.T) {
},
want2: []Cols{
{6, 1, 1},
{9, 0, 0},
{9, 1, 3},
{5, 0, 0},
{8, 1, 3},
{3, 0, 0},
},
},
Expand All @@ -63,16 +63,16 @@ noborus 721971 0.0 0.0 13716 3524 pts/3 R+ 10:39 0:00 ps aux`)),
{"noborus ", " 721971", " 0.0", " 0.0", " 13716", " 3524", " pts/3 ", " R+ ", " 10:39 ", " 0:00", "ps aux"},
},
want2: []Cols{
{9, 0, 0},
{7, 1, 4},
{5, 1, 4},
{5, 1, 4},
{11, 1, 4},
{7, 1, 4},
{9, 0, 0},
{5, 0, 1},
{8, 0, 0},
{5, 1, 4},
{7, 0, 0},
{6, 1, 4},
{4, 1, 4},
{4, 1, 4},
{10, 1, 4},
{6, 1, 4},
{5, 0, 0},
{4, 0, 1},
{5, 0, 0},
{4, 1, 4},
{25, 0, 0},
},
},
Expand All @@ -93,7 +93,7 @@ noborus 721971 0.0 0.0 13716 3524 pts/3 R+ 10:39 0:00 ps aux`)),
},
want2: []Cols{
{6, 1, 1},
{9, 0, 0},
{5, 0, 0},
{12, 1, 1},
},
},
Expand Down
Loading