mirror of
https://github.com/charmbracelet/gum
synced 2026-03-14 13:45:45 +01:00
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:
parent
a8cce1cad9
commit
8d611cb7df
1 changed files with 11 additions and 4 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue