Get rid of kitty's special OSC 52 protocol

A better solution from an ecosystem perspective is to just work with the
original protocol. I have modified kitty's escape parser to special case
OSC 52 handling without changing its max escape code size.

Basically, it works by splitting up OSC 52 escape codes longer than the
max size into a series of partial OSC 52 escape codes. These get
dispatched to the UI layer where it accumulates them upto the 8MB limit
and then sends to clipboard when the partial sequence ends.

See https://github.com/ranger/ranger/issues/1861
This commit is contained in:
Kovid Goyal
2021-07-23 22:12:04 +05:30
parent 096c4c78c7
commit 8f214c51c0
12 changed files with 147 additions and 71 deletions

View File

@@ -50,12 +50,20 @@ class Callbacks:
def open_url(self, url: str, hyperlink_id: int) -> None:
self.open_urls.append((url, hyperlink_id))
def clipboard_control(self, data: str, is_partial: bool = False) -> None:
self.cc_buf.append((data, is_partial))
def clear(self) -> None:
self.wtcbuf = b''
self.iconbuf = self.titlebuf = self.colorbuf = self.ctbuf = ''
self.iutf8 = True
self.notifications = []
self.open_urls = []
self.cc_buf = []
self.bell_count = 0
def on_bell(self) -> None:
self.bell_count += 1
def on_activity_since_last_focus(self) -> None:
pass

View File

@@ -239,6 +239,11 @@ class TestParser(BaseTest):
pb('\033]8;moo\x07', ('Ignoring malformed OSC 8 code',))
pb('\033]8;id=xyz;\x07', ('set_active_hyperlink', 'xyz', None))
pb('\033]8;moo:x=z:id=xyz:id=abc;http://yay;.com\x07', ('set_active_hyperlink', 'xyz', 'http://yay;.com'))
c.clear()
payload = '1' * 1024
pb(f'\033]52;p;{payload}\x07', ('clipboard_control', 52, f'p;{payload}'))
c.clear()
pb('\033]52;p;xyz\x07', ('clipboard_control', 52, 'p;xyz'))
def test_desktop_notify(self):
reset_registry()

View File

@@ -794,6 +794,29 @@ class TestScreen(BaseTest):
self.ae(str(s.linebuf), '0\n5\n6\n7\n\n')
self.ae(str(s.historybuf), '')
def test_osc_52(self):
s = self.create_screen()
c = s.callbacks
def send(what: str):
return parse_bytes(s, f'\033]52;p;{what}\a'.encode('ascii'))
def t(q, use_pending_mode, *expected):
c.clear()
if use_pending_mode:
parse_bytes(s, b'\033[?2026h')
send(q)
if use_pending_mode:
self.ae(c.cc_buf, [])
parse_bytes(s, b'\033[?2026l')
self.ae(c.cc_buf, list(expected))
for use_pending_mode in (False, True):
t('XYZ', use_pending_mode, ('p;XYZ', False))
t('a' * 8192, use_pending_mode, ('p;' + 'a' * (8192 - 6), True), (';' + 'a' * 6, False))
t('', use_pending_mode, ('p;', False))
t('!', use_pending_mode, ('p;!', False))
def test_key_encoding_flags_stack(self):
s = self.create_screen()
c = s.callbacks