Skip to content

Trim trailing whitespace in table UI #1136

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 3 commits into from
Jun 18, 2020
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
7 changes: 6 additions & 1 deletion pkg/lib/strings/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package strings

import (
"strings"
"unicode"

"github.com/cortexlabs/cortex/pkg/lib/cast"
)
Expand Down Expand Up @@ -53,10 +54,14 @@ func EnsureBlankLineIfNotEmpty(str string) string {
return str + "\n\n"
}

func RemoveTrailingNewLines(str string) string {
func TrimTrailingNewLines(str string) string {
return strings.TrimRight(str, "\n")
}

func TrimTrailingWhitespace(str string) string {
return strings.TrimRightFunc(str, unicode.IsSpace)
}

func EnsureSingleTrailingNewLine(str string) string {
return strings.TrimRight(str, "\n") + "\n"
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/lib/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func (t *Table) Format(opts ...*Opts) (string, error) {
headerStr += strings.Repeat(" ", maxColWidths[colNum]+t.Spacing-len(header.Title))
}
}
headerStr = s.TrimTrailingWhitespace(headerStr)

ellipses := "..."
rowStrs := make([]string, len(rows))
Expand All @@ -185,7 +186,7 @@ func (t *Table) Format(opts ...*Opts) (string, error) {
rowStr += strings.Repeat(" ", maxColWidths[colNum]+t.Spacing-len(val))
}
}
rowStrs[rowNum] = rowStr
rowStrs[rowNum] = s.TrimTrailingWhitespace(rowStr)
}

if *mergedOpts.Sort {
Expand Down