mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-05 04:36:07 +00:00
feat: add HelpView to table as a convenience
This commit is contained in:
+11
-1
@@ -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"
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -134,6 +136,7 @@ func New(opts ...Option) Model {
|
||||
viewport: viewport.New(0, 20),
|
||||
|
||||
KeyMap: DefaultKeyMap(),
|
||||
Help: help.New(),
|
||||
styles: DefaultStyles(),
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user