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: show indicator on help keybindings (opt-in) #839

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions table/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,11 @@ func (o Options) Run() error {
defer cancel()

m := model{
table: table,
showHelp: o.ShowHelp,
help: help.New(),
keymap: defaultKeymap(),
table: table,
showHelp: o.ShowHelp,
hideIndicator: o.HideIndicator,
help: help.New(),
keymap: defaultKeymap(),
}
tm, err := tea.NewProgram(
m,
Expand Down
1 change: 1 addition & 0 deletions table/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Options struct {
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"`
HideIndicator bool `help:"Hide indicator on help keybinds" default:"false" negatable:"" env:"GUM_TABLE_HIDE_INDICATOR"`
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"`

Expand Down
25 changes: 18 additions & 7 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package table

import (
"fmt"

"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/table"
Expand Down Expand Up @@ -62,16 +64,25 @@ func defaultKeymap() keymap {
}

type model struct {
table table.Model
selected table.Row
quitting bool
showHelp bool
help help.Model
keymap keymap
table table.Model
selected table.Row
quitting bool
showHelp bool
hideIndicator bool
help help.Model
keymap keymap
}

func (m model) Init() tea.Cmd { return nil }

func (m model) inidicatorView() string {
if m.hideIndicator {
return ""
}

return m.help.Styles.FullDesc.Render(fmt.Sprintf("%d/%d%s", m.table.Cursor()+1, len(m.table.Rows()), m.help.ShortSeparator))
}

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd

Expand Down Expand Up @@ -102,7 +113,7 @@ func (m model) View() string {
}
s := m.table.View()
if m.showHelp {
s += "\n" + m.help.View(m.keymap)
s += "\n" + m.inidicatorView() + m.help.View(m.keymap)
}
return s
}
Loading