From 8d611cb7dfe7ebec55a7da572adf3f20c3f54a37 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 10 Dec 2024 21:26:49 -0300 Subject: [PATCH] fix(table): grow table rows based on --columns (#760) * fix(table): grow table rows based on --columns closes #411 * fix: merge --- table/command.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/table/command.go b/table/command.go index 08dc725ab..ae52bbf91 100644 --- a/table/command.go +++ b/table/command.go @@ -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 {