diff --git a/table/command.go b/table/command.go index ed32fa77c..4c49f977f 100644 --- a/table/command.go +++ b/table/command.go @@ -37,6 +37,8 @@ func (o Options) Run() error { transformer := unicode.BOMOverride(encoding.Nop.NewDecoder()) reader := csv.NewReader(transform.NewReader(input, transformer)) + reader.LazyQuotes = o.LazyQuotes + reader.FieldsPerRecord = o.FieldsPerRecord separatorRunes := []rune(o.Separator) if len(separatorRunes) != 1 { return fmt.Errorf("separator must be single character") @@ -95,7 +97,16 @@ func (o Options) Run() error { data[row] = append(data[row], "") } - rows = append(rows, table.Row(data[row])) + for i, col := range row { + if len(o.Widths) == 0 { + width := lipgloss.Width(col) + if width > columns[i].Width { + columns[i].Width = width + } + } + } + + rows = append(rows, table.Row(data[row])) } if o.Print { diff --git a/table/options.go b/table/options.go index 1b1844a95..5949c92c4 100644 --- a/table/options.go +++ b/table/options.go @@ -8,14 +8,16 @@ import ( // Options is the customization options for the table command. type Options struct { - Separator string `short:"s" help:"Row separator" default:","` - Columns []string `short:"c" help:"Column names"` - Widths []int `short:"w" help:"Column widths"` - Height int `help:"Table height" default:"0"` - Print bool `short:"p" help:"static print" default:"false"` - File string `short:"f" help:"file path" default:""` - Border string `short:"b" help:"border style" default:"rounded" enum:"rounded,thick,normal,hidden,double,none"` - ShowHelp bool `help:"Show help keybinds" default:"true" negatable:"" env:"GUM_TABLE_SHOW_HELP"` + Separator string `short:"s" help:"Row separator" default:","` + Columns []string `short:"c" help:"Column names"` + Widths []int `short:"w" help:"Column widths"` + Height int `help:"Table height" default:"0"` + Print bool `short:"p" help:"static print" default:"false"` + File string `short:"f" help:"file path" default:""` + Border string `short:"b" help:"border style" default:"rounded" enum:"rounded,thick,normal,hidden,double,none"` + ShowHelp bool `help:"Show help keybinds" default:"true" negatable:"" env:"GUM_TABLE_SHOW_HELP"` + LazyQuotes bool `help:"If LazyQuotes is true, a quote may appear in an unquoted field and a non-doubled quote may appear in a quoted field" default:"false" env:"GUM_TABLE_LAZY_QUOTES"` + FieldsPerRecord int `help:"Sets the number of expected fields per record" default:"0" env:"GUM_TABLE_FIELDS_PER_RECORD"` BorderStyle style.Styles `embed:"" prefix:"border." envprefix:"GUM_TABLE_BORDER_"` CellStyle style.Styles `embed:"" prefix:"cell." envprefix:"GUM_TABLE_CELL_"`