home · contact · privacy
Minor code re-organization.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 10 Jun 2025 02:32:41 +0000 (04:32 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 10 Jun 2025 02:32:41 +0000 (04:32 +0200)
ircplom.py

index 0e1381d10255e34d14bc0d9cba0a7e75183d2c87..e4493ec99f8b83228070692e8b77e6599196e199 100755 (executable)
@@ -16,7 +16,6 @@ from typing import (
 from blessed import Terminal as BlessedTerminal
 
 
-PORT = 6667
 TIMEOUT_CONNECT = 5
 TIMEOUT_LOOP = 0.1
 CONN_RECV_BUFSIZE = 1024
@@ -38,6 +37,7 @@ CMD_SHORTCUTS = {
     'disconnect': 'window.disconnect',
     'reconnect': 'window.reconnect'
 }
+
 B64_PREFIX = 'b64:'
 OSC52_PREFIX = ']52;c;'
 PASTE_DELIMITER = '\007'
@@ -46,6 +46,7 @@ PROMPT_TEMPLATE = '> '
 PROMPT_ELL_IN = '<…'
 PROMPT_ELL_OUT = '…>'
 
+PORT = 6667
 IRCSPEC_LINE_SEPARATOR = b'\r\n'
 IRCSPEC_TAG_ESCAPES = ((r'\:', ';'),
                        (r'\s', ' '),
@@ -563,14 +564,14 @@ class PromptWidget(ScrollableWidget):
         if self._cursor_x > len(self._input_buffer):
             content += ' '
         half_width = self._width // 2
-        to_write = f'{prompt}{content}'
         offset = 0
-        if len(to_write) > self._width and self._cursor_x > half_width:
-            prompt = f'{PROMPT_TEMPLATE}{PROMPT_ELL_IN}'
+        if len(prompt) + len(content) > self._width\
+                and self._cursor_x > half_width:
+            prompt += PROMPT_ELL_IN
             if self._cursor_x > len(content) - half_width:
                 offset = len(content) - self._width + len(prompt)
             else:
-                offset = self._cursor_x - half_width + len(prompt) // 2
+                offset = self._cursor_x - half_width + (len(prompt) // 2)
         cursor_x_to_write = len(prompt) - 1 + self._cursor_x - offset
         to_write = f'{prompt}{content[offset:]}'
         if len(to_write) > self._width: