From 4f56cce727adf4a390a676f9b36eade65f0bbc4e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 8 Jan 2018 10:29:34 +0530 Subject: [PATCH] Fix client eating up send-text when seding to same window --- kitty/remote_control.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/kitty/remote_control.py b/kitty/remote_control.py index 53a157b58..d348da945 100644 --- a/kitty/remote_control.py +++ b/kitty/remote_control.py @@ -13,7 +13,7 @@ from .constants import appname, version from .utils import read_with_timeout -def cmd(short_desc, desc=None, options_spec=None): +def cmd(short_desc, desc=None, options_spec=None, no_response=False): def w(func): func.short_desc = short_desc @@ -22,6 +22,7 @@ def cmd(short_desc, desc=None, options_spec=None): func.options_spec = options_spec func.is_cmd = True func.impl = lambda: globals()[func.__name__[4:]] + func.no_response = no_response return func return w @@ -51,7 +52,8 @@ def ls(boss, window): @cmd( - 'Send arbitrary text to the specified window' + 'Send arbitrary text to the specified window', + no_response=True ) def cmd_send_text(global_opts, opts, args): return {'text': ' '.join(args)} @@ -70,13 +72,15 @@ def handle_cmd(boss, window, cmd): v = cmd['version'] if tuple(v)[:2] > version[:2]: return {'ok': False, 'error': 'The kitty client you are using to send remote commands is newer than this kitty instance. This is not supported.'} - func = partial(cmap[cmd['cmd']].impl(), boss, window) + c = cmap[cmd['cmd']] + func = partial(c.impl(), boss, window) payload = cmd.get('payload') ans = func() if payload is None else func(payload) response = {'ok': True} if ans is not None: response['data'] = ans - return response + if not c.no_response: + return response global_options_spec = partial('''\ @@ -84,12 +88,14 @@ global_options_spec = partial('''\ '''.format, appname=appname) -def read_from_stdin(send): +def read_from_stdin(send, no_response): send = ('@kitty-cmd' + json.dumps(send)).encode('ascii') if not sys.stdout.isatty(): raise SystemExit('stdout is not a terminal') sys.stdout.buffer.write(b'\x1bP' + send + b'\x1b\\') sys.stdout.flush() + if no_response: + return {'ok': True} received = b'' dcs = re.compile(br'\x1bP@kitty-cmd([^\x1b]+)\x1b\\') @@ -137,7 +143,7 @@ def main(args): } if payload is not None: send['payload'] = payload - response = read_from_stdin(send) + response = read_from_stdin(send, func.no_response) if not response.get('ok'): if response.get('tb'): print(response['tb'], file=sys.stderr)