From 605847fd755b3ceb2a95b0b8d0e22719bea997cd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 6 Aug 2018 18:17:45 +0530 Subject: [PATCH] Add --no-response to kitty @ focus-window --- kitty/cmds.py | 12 ++++++++++-- kitty/remote_control.py | 10 ++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/kitty/cmds.py b/kitty/cmds.py index 857b03e79..9190f4064 100644 --- a/kitty/cmds.py +++ b/kitty/cmds.py @@ -477,11 +477,19 @@ def new_window(boss, window, payload): @cmd( 'Focus the specified window', 'Focus the specified window, if no window is specified, focus the window this command is run inside.', - options_spec=MATCH_WINDOW_OPTION, argspec='', + options_spec=MATCH_WINDOW_OPTION + '''\n\n +--no-response +type=bool-set +default=false +Dont wait for a response from kitty. This means that even if no matching window is found, +the command will exit with a success code. +''' ) def cmd_focus_window(global_opts, opts, args): - return {'match': opts.match} + if opts.no_response: + global_opts.no_command_response = True + return {'match': opts.match, 'no_response': opts.no_response} def focus_window(boss, window, payload): diff --git a/kitty/remote_control.py b/kitty/remote_control.py index 5e4abafbb..64d467aaf 100644 --- a/kitty/remote_control.py +++ b/kitty/remote_control.py @@ -19,14 +19,20 @@ from .utils import TTYIO, parse_address_spec def handle_cmd(boss, window, cmd): cmd = json.loads(cmd) v = cmd['version'] + no_response = cmd['no_response'] if tuple(v)[:2] > version[:2]: - if cmd['no_response']: + if no_response: return return {'ok': False, 'error': 'The kitty client you are using to send remote commands is newer than this kitty instance. This is not supported.'} c = cmap[cmd['cmd']] func = partial(c.impl(), boss, window) payload = cmd.get('payload') - ans = func() if payload is None else func(payload) + try: + ans = func() if payload is None else func(payload) + except Exception: + if no_response: # dont report errors if --no-response was used + return + raise response = {'ok': True} if ans is not None: response['data'] = ans