Add --no-response to kitty @ focus-window

This commit is contained in:
Kovid Goyal
2018-08-06 18:17:45 +05:30
parent 6222273adc
commit 605847fd75
2 changed files with 18 additions and 4 deletions

View File

@@ -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):

View File

@@ -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