From 8b0af6e07915d4d9c9065dfbd0ba73579b2dd32d Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Sat, 9 Jan 2016 12:12:23 -0600 Subject: [PATCH] If first option is disabled, start at next Also, accept 'space' as confirmation --- termbox_menu.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/termbox_menu.go b/termbox_menu.go index 44e7485..d509454 100644 --- a/termbox_menu.go +++ b/termbox_menu.go @@ -15,7 +15,7 @@ type Menu struct { disabledBg, disabledFg termbox.Attribute isDone bool bordered bool - vimMode bool + vimMode bool } // CreateMenu Creates a menu with the specified attributes @@ -252,7 +252,7 @@ func (i *Menu) DisableVimMode() *Menu { // HandleKeyPress handles the termbox event and returns whether it was consumed func (i *Menu) HandleKeyPress(event termbox.Event) bool { - if event.Key == termbox.KeyEnter { + if event.Key == termbox.KeyEnter || event.Key == termbox.KeySpace { i.isDone = true return true } @@ -310,6 +310,11 @@ func (i *Menu) Draw() { } } + // If the currently selected option is disabled, move to the next + if i.GetSelectedOption().IsDisabled() { + i.SelectNextOption() + } + // Print the options if len(i.options) > 0 { for idx := range i.options {