Allow remote control commands to be interrupted by ctrl-c while waiting for a response

This commit is contained in:
Kovid Goyal 2022-08-10 17:00:04 +05:30
parent 5916d82580
commit e9ce5c02d0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 9 additions and 1 deletions

View File

@ -54,6 +54,7 @@ read_response(int fd, monotonic_t timeout, PyObject *ans) {
switch(state) { switch(state) {
case START: case START:
if (ch == 0x1b) state = STARTING_ESC; if (ch == 0x1b) state = STARTING_ESC;
if (ch == 0x03) { PyErr_SetString(PyExc_KeyboardInterrupt, "User pressed Ctrl-c"); return false; }
break; break;
#define CASE(curr, q, next) case curr: state = ch == q ? next : START; break; #define CASE(curr, q, next) case curr: state = ch == q ? next : START; break;
CASE(STARTING_ESC, 'P', P); CASE(STARTING_ESC, 'P', P);

View File

@ -467,8 +467,15 @@ def main(args: List[str]) -> None:
original_send_cmd['cancel_async'] = True original_send_cmd['cancel_async'] = True
if encrypter is not None: if encrypter is not None:
send = encrypter(original_send_cmd) send = encrypter(original_send_cmd)
do_io(global_opts.to, send, True, 10) try:
do_io(global_opts.to, send, True, 10)
except KeyboardInterrupt:
sys.excepthook = lambda *a: print('Interrupted by user', file=sys.stderr)
raise
raise SystemExit(f'Timed out after {response_timeout} seconds waiting for response from kitty') raise SystemExit(f'Timed out after {response_timeout} seconds waiting for response from kitty')
except KeyboardInterrupt:
sys.excepthook = lambda *a: print('Interrupted by user', file=sys.stderr)
raise
if no_response: if no_response:
return return
if not response.get('ok'): if not response.get('ok'):