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): fixed table when a column contained a whitespace at the start or end #502

Merged
merged 1 commit into from
May 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions table_printer.go
Expand Up @@ -2,9 +2,10 @@ package pterm

import (
"encoding/csv"
"github.com/pterm/pterm/internal"
"io"
"strings"

"github.com/pterm/pterm/internal"
)

// DefaultTable contains standards, which can be used to print a TablePrinter.
Expand Down Expand Up @@ -183,8 +184,8 @@ func (p TablePrinter) Srender() (string, error) {
c.lines = strings.Split(cRaw, "\n")
c.height = len(c.lines)
for _, l := range c.lines {
if internal.GetStringMaxWidth(l) > c.width {
c.width = internal.GetStringMaxWidth(l)
if maxWidth := internal.GetStringMaxWidth(l); maxWidth > c.width {
c.width = maxWidth
}
}
r.cells = append(r.cells, c)
Expand Down Expand Up @@ -262,7 +263,7 @@ func (p TablePrinter) renderRow(t table, r row) string {
}

if i < len(c.lines) {
s += strings.TrimSpace(c.lines[i])
s += c.lines[i]
}

if j < len(r.cells)-1 {
Expand Down