cmd: add quit keybinding (#437)

Co-authored-by: ayn2op <ayn2op@gmail.com>
This commit is contained in:
Retropaint 2024-09-23 16:18:14 +08:00 • committed by GitHub
parent 0baadff870
commit 501cdf3aa4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View file

@ -3,6 +3,7 @@ package cmd
import (
"log/slog"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
@ -16,9 +17,22 @@ func newApplication() *Application {
}
app.EnableMouse(cfg.Mouse)
app.SetInputCapture(app.onInputCapture)
return app
}
func (app *Application) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
switch event.Name() {
case cfg.Keys.Quit:
app.Stop()
case "Ctrl+C":
// https://github.com/rivo/tview/blob/a64fc48d7654432f71922c8b908280cdb525805c/application.go#L153
return tcell.NewEventKey(tcell.KeyCtrlC, 0, tcell.ModNone)
}
return event
}
func (app *Application) Show(token string) error {
if token == "" {
loginForm := NewLoginForm(func(token string, err error) {

View file

@ -17,6 +17,7 @@ type (
MessageInput MessageInputKeys `toml:"message_input"`
Logout string `toml:"logout"`
Quit string `toml:"quit"`
}
GuildsTreeKeys struct {
@ -49,6 +50,7 @@ func defaultKeys() Keys {
ToggleGuildsTree: "Ctrl+B",
Logout: "Ctrl+D",
Quit: "Ctrl+C",
SelectPrevious: "Rune[k]",
SelectNext: "Rune[j]",