mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Improve keyboard handling in main.go
This commit is contained in:
parent
ce7234179c
commit
f183a854c8
9
main.go
9
main.go
@ -40,22 +40,29 @@ func disableAllWidgets(widgets []wtf.Wtfable) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
func keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||||
|
// These keys are global keys used by the app. Widgets should not implement these keys
|
||||||
switch event.Key() {
|
switch event.Key() {
|
||||||
case tcell.KeyCtrlR:
|
case tcell.KeyCtrlR:
|
||||||
refreshAllWidgets(runningWidgets)
|
refreshAllWidgets(runningWidgets)
|
||||||
|
return nil
|
||||||
case tcell.KeyTab:
|
case tcell.KeyTab:
|
||||||
focusTracker.Next()
|
focusTracker.Next()
|
||||||
|
return nil
|
||||||
case tcell.KeyBacktab:
|
case tcell.KeyBacktab:
|
||||||
focusTracker.Prev()
|
focusTracker.Prev()
|
||||||
|
return nil
|
||||||
case tcell.KeyEsc:
|
case tcell.KeyEsc:
|
||||||
focusTracker.None()
|
focusTracker.None()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function checks to see if any widget has been assigned the pressed key as its
|
||||||
|
// focus key
|
||||||
if focusTracker.FocusOn(string(event.Rune())) {
|
if focusTracker.FocusOn(string(event.Rune())) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no specific widget has focus, then allow key presses to fall through to the app
|
// If no specific widget has focus, then allow the key presses to fall through to the app
|
||||||
if !focusTracker.IsFocused {
|
if !focusTracker.IsFocused {
|
||||||
switch string(event.Rune()) {
|
switch string(event.Rune()) {
|
||||||
case "/":
|
case "/":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user