Add default keybindings for navigation

This commit is contained in:
rigormorrtiss 2021-08-03 14:07:23 +04:00
parent a5a6e1ebf6
commit c17ca03bda
2 changed files with 22 additions and 3 deletions

View file

@ -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()
}

View file

@ -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
}