From 5db30c0e8dc1b336951eb9afb2450913a958043b Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Thu, 23 May 2019 07:37:25 -0700 Subject: [PATCH] Add help screen to main app --- main.go | 9 +++++++++ wtf/focus_tracker.go | 23 +++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 6863a873..73f6ba4d 100644 --- a/main.go +++ b/main.go @@ -55,6 +55,15 @@ func keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { return nil } + // If no specific widget has focus, then allow key presses to fall through to the app + if !focusTracker.IsFocused { + switch string(event.Rune()) { + case "/": + fmt.Println(">> OUCH") + return nil + } + } + return event } diff --git a/wtf/focus_tracker.go b/wtf/focus_tracker.go index d5417e02..14388984 100644 --- a/wtf/focus_tracker.go +++ b/wtf/focus_tracker.go @@ -18,18 +18,22 @@ const ( // FocusTracker is used by the app to track which onscreen widget currently has focus, // and to move focus between widgets. type FocusTracker struct { - App *tview.Application - Idx int - Widgets []Wtfable - config *config.Config + App *tview.Application + Idx int + IsFocused bool + Widgets []Wtfable + + config *config.Config } func NewFocusTracker(app *tview.Application, widgets []Wtfable, config *config.Config) FocusTracker { focusTracker := FocusTracker{ - App: app, - Idx: -1, - Widgets: widgets, - config: config, + App: app, + Idx: -1, + IsFocused: false, + Widgets: widgets, + + config: config, } focusTracker.assignHotKeys() @@ -57,6 +61,7 @@ func (tracker *FocusTracker) FocusOn(char string) bool { tracker.focus(tracker.Idx) hasFocusable = true + tracker.IsFocused = true break } } @@ -149,6 +154,8 @@ func (tracker *FocusTracker) blur(idx int) { view.Blur() view.SetBorderColor(ColorFor(widget.BorderColor())) + + tracker.IsFocused = false } func (tracker *FocusTracker) decrement() {