diff --git a/docs/clipboard.rst b/docs/clipboard.rst index 260da3c31..2162e442c 100644 --- a/docs/clipboard.rst +++ b/docs/clipboard.rst @@ -47,7 +47,8 @@ The terminal emulator will reply with a sequence of escape codes of the form:: Here, the ``status=DATA`` packets deliver the data (as base64 encoded bytes) associated with each MIME type. The terminal emulator should chunk up the data -for an individual type, into chunks of size **no more** than 4096 bytes. All +for an individual type, into chunks of size **no more** than 4096 bytes (4096 +is the size of a chunk *before* base64 encoding). All the chunks for a given type must be transmitted sequentially and only once they are done the chunks for the next type, if any, should be sent. The end of data is indicated by a ``status=DONE`` packet. @@ -90,7 +91,8 @@ following sequence of packets:: The final packet with no mime and no data indicates end of transmission. The data for every MIME type should be split into chunks of no more than 4096 -bytes. All the chunks for a given MIME type must be sent sequentially, before +bytes (4096 is the size of the data before base64 encoding). +All the chunks for a given MIME type must be sent sequentially, before sending chunks for the next MIME type. After the transmission is complete, the terminal replies with a single packet indicating success:: diff --git a/kitty/clipboard.py b/kitty/clipboard.py index 74f638a81..4ccc33ab0 100644 --- a/kitty/clipboard.py +++ b/kitty/clipboard.py @@ -24,6 +24,8 @@ from .fast_data_types import ( ) from .utils import log_error +READ_RESPONSE_CHUNK_SIZE = 4096 + class Tempfile: @@ -462,8 +464,8 @@ class ClipboardRequestManager: assert w is not None mv = memoryview(data) while mv: - w.screen.send_escape_code_to_child(ESC_OSC, rr.encode_response(payload=mv[:4096], mime=current_mime)) - mv = mv[4096:] + w.screen.send_escape_code_to_child(ESC_OSC, rr.encode_response(payload=mv[:READ_RESPONSE_CHUNK_SIZE], mime=current_mime)) + mv = mv[READ_RESPONSE_CHUNK_SIZE:] for mime in rr.mime_types: current_mime = mime