From 31df90a64e7afba068c651c762d579fd9a683581 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 31 Dec 2022 13:36:24 +0530 Subject: [PATCH] Dont allow abort while waiting for query response --- tools/cmd/icat/main.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/cmd/icat/main.go b/tools/cmd/icat/main.go index 98110a076..271537887 100644 --- a/tools/cmd/icat/main.go +++ b/tools/cmd/icat/main.go @@ -131,6 +131,8 @@ func print_error(format string, args ...any) { fmt.Fprintf(os.Stderr, format, args...) fmt.Fprintln(os.Stderr) } else { + lp.QueueWriteString("\r") + lp.ClearToEndOfLine() lp.QueueWriteString(fmt.Sprintf(format, args...)) lp.QueueWriteString("\r\n") } @@ -308,6 +310,21 @@ func on_wakeup() error { return nil } +func on_key_event(event *loop.KeyEvent) error { + if event.MatchesPressOrRepeat("ctrl+c") { + event.Handled = true + if query_in_flight { + print_error("Waiting for response from terminal, aborting now could lead to corruption") + return nil + } + return fmt.Errorf("Aborted by user") + } + if event.MatchesPressOrRepeat("ctrl+z") { + event.Handled = true + } + return nil +} + func main(cmd *cli.Command, o *Options, args []string) (rc int, err error) { opts = o err = parse_place()