Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions menu/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ func (k KeyMap) FullHelp() [][]key.Binding {
}

func (m Model) handleKeyMsg(keyMsg tea.KeyMsg, msg tea.Msg) (tea.Model, tea.Cmd) {

if m.help.ShowAll && !key.Matches(keyMsg, DefaultKeyMap.Help) {
if m.autoHideHelp && m.help.ShowAll && !key.Matches(keyMsg, DefaultKeyMap.Help) {
m.help.ShowAll = false // toggle help view
switch { //override escape to only close help
case keyMsg.String() == tea.KeyEscape.String():
Expand Down
26 changes: 18 additions & 8 deletions menu/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ type Model struct {
width int
height int
help.KeyMap
keys KeyMap
help help.Model
keys KeyMap
help help.Model
autoHideHelp bool
}

// New setups up a new menu model
Expand All @@ -64,12 +65,13 @@ func New(title string, choices []Choice, selected *Choice) Model {
defaultHeight := 20

model := Model{
list: list.New([]list.Item{}, delegation, defaultWidth, defaultHeight),
delegate: delegation,
keys: DefaultKeyMap,
help: help.New(),
width: defaultWidth,
height: defaultHeight,
list: list.New([]list.Item{}, delegation, defaultWidth, defaultHeight),
delegate: delegation,
keys: DefaultKeyMap,
help: help.New(),
autoHideHelp: true,
width: defaultWidth,
height: defaultHeight,
}

model.list.Styles.Title = styles.ListTitleStyle
Expand Down Expand Up @@ -161,6 +163,14 @@ func (m *Model) SetShowTitle(display bool) {
m.list.SetShowTitle(display)
}

func (m *Model) SetShowHelp(display bool) {
m.help.ShowAll = display
}

func (m *Model) SetAutoHideHelp(hide bool) {
m.autoHideHelp = hide
}

// View renders the menu. When no choices are present, nothing is rendered.
func (m Model) View() string {
var help string
Expand Down