Skip to content

Commit

Permalink
fix(table): grow table rows based on --columns (#760)
Browse files Browse the repository at this point in the history
* fix(table): grow table rows based on --columns

closes #411

* fix: merge
  • Loading branch information
caarlos0 authored Dec 11, 2024
1 parent a8cce1c commit 8d611cb
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions table/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,26 @@ func (o Options) Run() error {
}

rows := make([]table.Row, 0, len(data))
for _, row := range data {
if len(row) > len(columns) {
for row := range data {
if len(data[row]) > len(columns) {
return fmt.Errorf("invalid number of columns")
}
for i, col := range row {

// fixes the data in case we have more columns than rows:
for len(data[row]) < len(columns) {
data[row] = append(data[row], "")
}

for i, col := range data[row] {
if len(o.Widths) == 0 {
width := lipgloss.Width(col)
if width > columns[i].Width {
columns[i].Width = width
}
}
}
rows = append(rows, table.Row(row))

rows = append(rows, table.Row(data[row]))
}

if o.Print {
Expand Down

0 comments on commit 8d611cb

Please sign in to comment.