mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
When receiving contiguous non-empty OSC 52 clipboard writes, combine them.
Max combined text is set at 1MB. Allows sending texts larger than the escape code size limit.
This commit is contained in:
@@ -235,7 +235,15 @@ def write_to_clipboard(data, use_primary=False) -> str:
|
||||
if isinstance(data, str):
|
||||
data = data.encode('utf-8')
|
||||
from base64 import standard_b64encode
|
||||
return '\x1b]52;{};{}\x07'.format('p' if use_primary else 'c', standard_b64encode(data).decode('ascii'))
|
||||
fmt = 'p' if use_primary else 'c'
|
||||
|
||||
def esc(chunk):
|
||||
return '\x1b]52;{};{}\x07'.format(fmt, chunk)
|
||||
ans = esc('!') # clear clipboard buffer
|
||||
for chunk in (data[i:i+512] for i in range(0, len(data), 512)):
|
||||
chunk = standard_b64encode(chunk).decode('ascii')
|
||||
ans += esc(chunk)
|
||||
return ans
|
||||
|
||||
|
||||
def request_from_clipboard(use_primary=False) -> str:
|
||||
|
||||
Reference in New Issue
Block a user