From ff4609e4320f51d202dc575733ffc5232b814ec1 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Fri, 25 Nov 2022 19:21:36 -0400 Subject: [PATCH] feat: add hilbish.cancel hook (closes #213) --- CHANGELOG.md | 1 + docs/hooks/hilbish.txt | 2 ++ main.go | 7 +++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11d44e8..7c02489 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,7 @@ disables commands being added to history. random errors introduced with the new Lua runtime (see [#197]) - `bait.release(name, catcher)` removes `handler` for the named `event` - `exec`, `clear` and `cat` builtin commands +- `hilbish.cancel` hook [#197]: https://github.com/Rosettea/Hilbish/issues/197 diff --git a/docs/hooks/hilbish.txt b/docs/hooks/hilbish.txt index d6d5542..3d6d2ea 100644 --- a/docs/hooks/hilbish.txt +++ b/docs/hooks/hilbish.txt @@ -5,3 +5,5 @@ + `hilbish.vimAction` -> actionName, args > Sent when the user does a "vim action," being something like yanking or pasting text. See `doc vim-mode actions` for more info. + ++ `hilbish.cancel` > Sent when the user cancels their input with Ctrl-C. diff --git a/main.go b/main.go index ee0f584..1b5e6b8 100644 --- a/main.go +++ b/main.go @@ -181,11 +181,14 @@ input: break } if err != nil { - if err != readline.CtrlC { + if err == readline.CtrlC { + fmt.Println("^C") + hooks.Emit("hilbish.cancel") + } else { // If we get a completely random error, print fmt.Fprintln(os.Stderr, err) } - fmt.Println("^C") + // TODO: Halt if any other error occurs continue } var priv bool