home · contact · privacy
Refactor OSC-52 code. master
authorChristian Heller <c.heller@plomlompom.de>
Sun, 8 Jun 2025 11:21:10 +0000 (13:21 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 8 Jun 2025 11:21:10 +0000 (13:21 +0200)
ircplom.py

index 87ecac3ccb84522be45eca5679c22367acb01627..3c23a551c2fbb2f42a7577740ca61b2c64029306 100755 (executable)
@@ -36,6 +36,7 @@ CMD_SHORTCUTS = {
     'reconnect': 'window.reconnect'
 }
 PREFIX_B64 = 'b64:'
     'reconnect': 'window.reconnect'
 }
 PREFIX_B64 = 'b64:'
+OSC_52_PREFIX = ']52;c;'
 
 IRCSPEC_LINE_SEPARATOR = b'\r\n'
 IRCSPEC_TAG_ESCAPES = ((r'\:', ';'),
 
 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:
                     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:
                         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.'
 
     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()
 
 
         self.draw()