Allow remote control commands to be interrupted by ctrl-c while waiting for a response
This commit is contained in:
parent
5916d82580
commit
e9ce5c02d0
@ -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);
|
||||||
|
|||||||
@ -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)
|
||||||
|
try:
|
||||||
do_io(global_opts.to, send, True, 10)
|
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'):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user