summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2026-03-04 08:25:53 +0300
committerGrail Finder <wohilas@gmail.com>2026-03-04 08:25:53 +0300
commit58ccd63f4a76a8ee6ee44d30347b9a6b12833ebf (patch)
tree75156f8f08f09d590b295c72b027c64eaff38ecd /main.go
parent3611d7eb592eabc5bd6a074a16394d05c4315bfa (diff)
Fix: avoid raw terminal after ctrl+c exit
Diffstat (limited to 'main.go')
-rw-r--r--main.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/main.go b/main.go
index 5459089..334b59b 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,7 @@
package main
import (
+ "github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
@@ -19,9 +20,23 @@ var (
toolCollapsed = true
statusLineTempl = "help (F12) | chat: [orange:-:b]%s[-:-:-] (F1) | [%s:-:b]tool use[-:-:-] (ctrl+k) | model: [%s:-:b]%s[-:-:-] (ctrl+l) | [%s:-:b]skip LLM resp[-:-:-] (F10) | API: [orange:-:b]%s[-:-:-] (ctrl+v)\nwriting as: [orange:-:b]%s[-:-:-] (ctrl+q) | bot will write as [orange:-:b]%s[-:-:-] (ctrl+x)"
focusSwitcher = map[tview.Primitive]tview.Primitive{}
+ app *tview.Application
)
func main() {
+ app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
+ if event.Key() == tcell.KeyCtrlC {
+ logger.Info("caught Ctrl+C via tcell event")
+ go func() {
+ if err := pwShutDown(); err != nil {
+ logger.Error("shutdown failed", "err", err)
+ }
+ app.Stop()
+ }()
+ return nil // swallow the event
+ }
+ return event
+ })
pages.AddPage("main", flex, true, true)
if err := app.SetRoot(pages,
true).EnableMouse(cfg.EnableMouse).EnablePaste(true).Run(); err != nil {