diff --git a/discordo.go b/discordo.go index 7ff0070..4ebe9f6 100644 --- a/discordo.go +++ b/discordo.go @@ -58,7 +58,7 @@ func main() { channelsTreeView = ui.NewChannelsTreeView(channelsTreeNode, onChannelsTreeViewSelected, config.Theme) messagesTextView = ui.NewMessagesTextView(onMessagesTextViewChanged, config.Theme) mainFlex = ui.NewMainFlex(guildsDropDown, channelsTreeView, messagesTextView) - app = ui.NewApp() + app = ui.NewApp(onAppInputCapture) token := util.GetPassword("token") if token != "" { @@ -76,6 +76,23 @@ func main() { } } +func onAppInputCapture(event *tcell.EventKey) *tcell.EventKey { + switch event.Name() { + case "Ctrl+G": + app.SetFocus(guildsDropDown) + case "Ctrl+J": + app.SetFocus(channelsTreeView) + case "Ctrl+K": + app.SetFocus(messagesTextView) + case "Ctrl+L": + if messageInputField != nil { + app.SetFocus(messageInputField) + } + } + + return event +} + func onMessagesTextViewChanged() { app.Draw() } diff --git a/ui/app.go b/ui/app.go index 7289152..845bd76 100644 --- a/ui/app.go +++ b/ui/app.go @@ -1,12 +1,14 @@ package ui import ( + "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) -func NewApp() *tview.Application { +func NewApp(onAppInputCapture func(event *tcell.EventKey) *tcell.EventKey) *tview.Application { app := tview.NewApplication(). - EnableMouse(true) + EnableMouse(true). + SetInputCapture(onAppInputCapture) return app }