From fc773a2fbff46648bf6eb4596e36cb7c2e735445 Mon Sep 17 00:00:00 2001 From: Mark D Horn Date: Wed, 19 Sep 2018 15:30:54 -0700 Subject: [PATCH] Enable Escape key to cancel to previous page Fixes #53 Signed-off-by: Mark D Horn --- tui/common.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tui/common.go b/tui/common.go index fc3eefe..5fb7bac 100644 --- a/tui/common.go +++ b/tui/common.go @@ -327,6 +327,19 @@ func (page *BasePage) setup(tui *Tui, id int, btns int, returnID int) { "Use [Tab] or the arrow keys [up and down] to navigate", Fixed) page.window.SetVisible(false) + + // Escape-key cancel's this screen and returns + // same as the default 'Cancel' button + page.window.OnKeyDown(func(ev clui.Event, data interface{}) bool { + if ev.Key == term.KeyEsc { + page.action = ActionCancelButton + page.GotoPage(returnID) + page.action = ActionNone + return true + } + + return false + }, nil) } func (page *BasePage) newWindow() {