diff --git a/menu/keys.go b/menu/keys.go index 37a5077..a8c37f4 100644 --- a/menu/keys.go +++ b/menu/keys.go @@ -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(): diff --git a/menu/model.go b/menu/model.go index e52acf7..0008e62 100644 --- a/menu/model.go +++ b/menu/model.go @@ -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 @@ -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 @@ -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