fix(table): grow table rows based on --columns (#760)

* fix(table): grow table rows based on --columns

closes #411

* fix: merge
This commit is contained in:
Carlos Alexandro Becker 2024-12-10 21:26:49 -03:00 committed by GitHub
commit 8d611cb7df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -87,11 +87,17 @@ 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 {
@ -99,7 +105,8 @@ func (o Options) Run() error {
}
}
}
rows = append(rows, table.Row(row))
rows = append(rows, table.Row(data[row]))
}
if o.Print {