diff --git a/cmd/application.go b/cmd/application.go index 5b0246f..2c3f9bb 100644 --- a/cmd/application.go +++ b/cmd/application.go @@ -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) { diff --git a/internal/config/keys.go b/internal/config/keys.go index 5bc1222..20570ea 100644 --- a/internal/config/keys.go +++ b/internal/config/keys.go @@ -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]",