mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-25 17:52:02 +02:00
Add --no-response to kitty @ focus-window
This commit is contained in:
@@ -477,11 +477,19 @@ def new_window(boss, window, payload):
|
|||||||
@cmd(
|
@cmd(
|
||||||
'Focus the specified window',
|
'Focus the specified window',
|
||||||
'Focus the specified window, if no window is specified, focus the window this command is run inside.',
|
'Focus the specified window, if no window is specified, focus the window this command is run inside.',
|
||||||
options_spec=MATCH_WINDOW_OPTION,
|
|
||||||
argspec='',
|
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):
|
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):
|
def focus_window(boss, window, payload):
|
||||||
|
|||||||
@@ -19,14 +19,20 @@ from .utils import TTYIO, parse_address_spec
|
|||||||
def handle_cmd(boss, window, cmd):
|
def handle_cmd(boss, window, cmd):
|
||||||
cmd = json.loads(cmd)
|
cmd = json.loads(cmd)
|
||||||
v = cmd['version']
|
v = cmd['version']
|
||||||
|
no_response = cmd['no_response']
|
||||||
if tuple(v)[:2] > version[:2]:
|
if tuple(v)[:2] > version[:2]:
|
||||||
if cmd['no_response']:
|
if no_response:
|
||||||
return
|
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.'}
|
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']]
|
c = cmap[cmd['cmd']]
|
||||||
func = partial(c.impl(), boss, window)
|
func = partial(c.impl(), boss, window)
|
||||||
payload = cmd.get('payload')
|
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}
|
response = {'ok': True}
|
||||||
if ans is not None:
|
if ans is not None:
|
||||||
response['data'] = ans
|
response['data'] = ans
|
||||||
|
|||||||
Reference in New Issue
Block a user