Chunk up overly large send text inputs

This commit is contained in:
Kovid Goyal 2018-01-09 02:51:22 +05:30
parent 3e85497c2c
commit 2f9784809d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 22 additions and 4 deletions

View File

@ -240,7 +240,7 @@ def tab_separator(x):
x = x[1:-1]
break
if not x.strip():
x = defaults.tab_separator
x = ('\xa0' * len(x)) if x else defaults.tab_separator
return x

View File

@ -5,6 +5,7 @@
import json
import re
import sys
import types
from functools import partial
from .cli import emph, parse_args
@ -77,14 +78,26 @@ for that window is used.
' escaping rules. So you can use escapes like |_ \\x1b| to send control codes'
' and |_ \\u21fa| to send unicode characters. If you use the |_ --match| option'
' the text will be sent to all matched windows. By default, text is sent to'
' only the currently active window. Note that sending more than ~ 2KB of text'
' will not work, so split up large texts into multiple invocations.',
' only the currently active window.',
options_spec=MATCH_WINDOW_OPTION,
no_response=True
)
def cmd_send_text(global_opts, opts, args):
text = ' '.join(args)
limit = 1024
if len(text) <= limit:
return {'text': ' '.join(args), 'match': opts.match}
# Overly large escape sequences are ignored by kitty, so chunk up the
# data
def chunks():
nonlocal text
while text:
yield {'text': text[:limit], 'match': opts.match}
text = text[limit:]
return chunks()
def send_text(boss, window, payload):
windows = [boss.active_window]
@ -222,6 +235,11 @@ def main(args):
'cmd': cmd,
'version': version,
}
if func.no_response and isinstance(payload, types.GeneratorType):
for item in payload:
send['payload'] = item
read_from_stdin(send, func.no_response)
return
if payload is not None:
send['payload'] = payload
response = read_from_stdin(send, func.no_response)