Fix kitty @ send-text not working with text larger than 1024 bytes when using --listen-on

Fixes #2607
This commit is contained in:
Kovid Goyal 2020-04-29 21:48:09 +05:30
parent aa9c3cd634
commit fcc0707174
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 25 additions and 9 deletions

View File

@ -21,6 +21,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- Report modifier key state when sending wheel events to the terminal program - Report modifier key state when sending wheel events to the terminal program
- Fix kitty @ send-text not working with text larger than 1024 bytes when using
--listen-on (:iss:`2607`)
0.17.3 [2020-04-23] 0.17.3 [2020-04-23]
-------------------- --------------------

View File

@ -354,16 +354,29 @@ class Boss:
except (Exception, SystemExit) as e: except (Exception, SystemExit) as e:
self.show_error(_('remote_control mapping failed'), str(e)) self.show_error(_('remote_control mapping failed'), str(e))
def peer_message_received(self, msg_bytes: bytes) -> Optional[bytes]: def handle_peer_cmd(self, msg_bytes: bytes) -> Optional[bytes]:
msg = msg_bytes.decode('utf-8') cmd_prefix_b = b'\x1bP@kitty-cmd'
cmd_prefix = '\x1bP@kitty-cmd' pl = len(cmd_prefix_b)
if msg.startswith(cmd_prefix): terminator = b'\x1b\\'
cmd = msg[len(cmd_prefix):-2] tl = len(terminator)
resp = b''
pos = 0
while msg_bytes[pos:pos+pl] == cmd_prefix_b:
idx = msg_bytes.find(terminator, pos + pl)
if idx < pos + pl:
break
cmd = msg_bytes[pos+pl:idx].decode('utf-8')
response = self._handle_remote_command(cmd, from_peer=True) response = self._handle_remote_command(cmd, from_peer=True)
if response is None: if response is not None:
return None resp += cmd_prefix_b + json.dumps(response).encode('utf-8') + b'\x1b\\'
return (cmd_prefix + json.dumps(response) + '\x1b\\').encode('utf-8') pos = idx + tl
data = json.loads(msg) return resp or None
def peer_message_received(self, msg_bytes: bytes) -> Optional[bytes]:
cmd_prefix_b = b'\x1bP@kitty-cmd'
if msg_bytes.startswith(cmd_prefix_b):
return self.handle_peer_cmd(msg_bytes)
data = json.loads(msg_bytes.decode('utf-8'))
if isinstance(data, dict) and data.get('cmd') == 'new_instance': if isinstance(data, dict) and data.get('cmd') == 'new_instance':
from .cli_stub import CLIOptions from .cli_stub import CLIOptions
startup_id = data.get('startup_id') startup_id = data.get('startup_id')