Skip to content

Commit

Permalink
feat: add HelpView to table as a convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Aug 20, 2024
1 parent c1d9f7d commit 235075a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package table
import (
"strings"

"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
Expand All @@ -13,6 +14,7 @@ import (
// Model defines a state for the table widget.
type Model struct {
KeyMap KeyMap
Help help.Model

cols []Column
rows []Row
Expand All @@ -35,7 +37,7 @@ type Column struct {
}

// KeyMap defines keybindings. It satisfies to the help.KeyMap interface, which
// is used to render the menu.
// is used to render the help menu.
type KeyMap struct {
LineUp key.Binding
LineDown key.Binding
Expand Down Expand Up @@ -134,6 +136,7 @@ func New(opts ...Option) Model {
viewport: viewport.New(0, 20),

KeyMap: DefaultKeyMap(),
Help: help.New(),
styles: DefaultStyles(),
}

Expand Down Expand Up @@ -251,6 +254,13 @@ func (m Model) View() string {
return m.headersView() + "\n" + m.viewport.View()
}

// HelpView is a helper method for rendering the help menu from the keymap.
// Note that this view is not rendered by default and you must call it
// manually in your application, where applicable.
func (m Model) HelpView() string {
return m.Help.View(m.KeyMap)
}

// UpdateViewport updates the list content based on the previously defined
// columns and rows.
func (m *Model) UpdateViewport() {
Expand Down

0 comments on commit 235075a

Please sign in to comment.