From: Christian Heller Date: Sun, 8 Jun 2025 11:21:10 +0000 (+0200) Subject: Refactor OSC-52 code. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%22https:/validator.w3.org/task?a=commitdiff_plain;h=45aac9a3ed1b5111ac0c5cdcdcc46db09843ec67;p=ircplom Refactor OSC-52 code. --- diff --git a/ircplom.py b/ircplom.py index 87ecac3..3c23a55 100755 --- a/ircplom.py +++ b/ircplom.py @@ -36,6 +36,7 @@ CMD_SHORTCUTS = { 'reconnect': 'window.reconnect' } PREFIX_B64 = 'b64:' +OSC_52_PREFIX = ']52;c;' IRCSPEC_LINE_SEPARATOR = b'\r\n' IRCSPEC_TAG_ESCAPES = ((r'\:', ';'), @@ -145,11 +146,10 @@ class Terminal: n_gotchs_unprocessed -= 1 n_gotchs_unprocessed -= n_chs_blessed_key if unhandleds: - if unhandleds[:6] == [93, 53, 50, 59, 99, 59]: - if len(unhandleds) > 6: - encoded = ''.join([chr(c) for c in unhandleds[:6]]) - else: - encoded = '' + fused = ''.join([chr(n) for n in unhandleds]) + if fused.startswith(OSC_52_PREFIX): + encoded = fused[len(OSC_52_PREFIX):] + if not encoded: while True: gotch = self._blessed.getch() if ord(gotch) == 7: @@ -647,7 +647,7 @@ class Window(Widget): def cmd__paste(self) -> None: 'Write OSC 52 ? sequence to get encoded clipboard paste into stdin.' - self._term.write_yx(YX(self._y_status, 0), '\033]52;c;?\007') + self._term.write_yx(YX(self._y_status, 0), f'\033{OSC_52_PREFIX}?\007') self.draw()