Fix client eating up send-text when seding to same window
This commit is contained in:
parent
7dea6e0ef4
commit
4f56cce727
@ -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,12 +72,14 @@ 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
|
||||
if not c.no_response:
|
||||
return response
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user