Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding Return Column to table command #415

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions table/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,14 @@ func (o Options) Run() error {

m := tm.(model)

if err = writer.Write([]string(m.selected)); err != nil {
return fmt.Errorf("failed to write selected row: %w", err)
if o.ReturnColumn > 0 && o.ReturnColumn <= len(m.selected) {
if err = writer.Write([]string{m.selected[o.ReturnColumn-1]}); err != nil {
return fmt.Errorf("failed to write col %d of selected row: %w", o.ReturnColumn, err)
}
} else {
if err = writer.Write([]string(m.selected)); err != nil {
return fmt.Errorf("failed to write selected row: %w", err)
}
}

writer.Flush()
Expand Down
2 changes: 2 additions & 0 deletions table/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
Widths []int `short:"w" help:"Column widths"`
Height int `help:"Table height" default:"10"`
Print bool `short:"p" help:"static print" default:"false"`
File string `short:"f" help:"file path" default:""`

Check failure on line 12 in table/options.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

other declaration of File

Check failure on line 12 in table/options.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

other declaration of File

Check failure on line 12 in table/options.go

View workflow job for this annotation

GitHub Actions / snapshot / snapshot

other declaration of File
Border string `short:"b" help:"border style" default:"rounded" enum:"rounded,thick,normal,hidden,double,none"`

BorderStyle style.Styles `embed:"" prefix:"border." envprefix:"GUM_TABLE_BORDER_"`
CellStyle style.Styles `embed:"" prefix:"cell." envprefix:"GUM_TABLE_CELL_"`
HeaderStyle style.Styles `embed:"" prefix:"header." envprefix:"GUM_TABLE_HEADER_"`
SelectedStyle style.Styles `embed:"" prefix:"selected." set:"defaultForeground=212" envprefix:"GUM_TABLE_SELECTED_"`
File string `short:"f" help:"file path" default:""`

Check failure on line 19 in table/options.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

File redeclared

Check failure on line 19 in table/options.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

File redeclared

Check failure on line 19 in table/options.go

View workflow job for this annotation

GitHub Actions / snapshot / snapshot

File redeclared
ReturnColumn int `short:"r" help:"Which column number should be returned instead of whole row as string. Default=0 returns whole Row" default:"0"`
}