Dont allow abort while waiting for query response

This commit is contained in:
Kovid Goyal 2022-12-31 13:36:24 +05:30
parent 22d69d24d0
commit 31df90a64e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -131,6 +131,8 @@ func print_error(format string, args ...any) {
fmt.Fprintf(os.Stderr, format, args...) fmt.Fprintf(os.Stderr, format, args...)
fmt.Fprintln(os.Stderr) fmt.Fprintln(os.Stderr)
} else { } else {
lp.QueueWriteString("\r")
lp.ClearToEndOfLine()
lp.QueueWriteString(fmt.Sprintf(format, args...)) lp.QueueWriteString(fmt.Sprintf(format, args...))
lp.QueueWriteString("\r\n") lp.QueueWriteString("\r\n")
} }
@ -308,6 +310,21 @@ func on_wakeup() error {
return nil 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) { func main(cmd *cli.Command, o *Options, args []string) (rc int, err error) {
opts = o opts = o
err = parse_place() err = parse_place()