home · contact · privacy
Minor code polishing. master
authorChristian Heller <c.heller@plomlompom.de>
Wed, 26 Nov 2025 05:33:04 +0000 (06:33 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 26 Nov 2025 05:33:04 +0000 (06:33 +0100)
src/ircplom/tui_base.py

index cfd2e612f080bc9837ea9e9c42370ab53748f9bb..7c55ebf9761f1ef4404e5f44081a19b422fc5418 100644 (file)
@@ -204,12 +204,12 @@ class _Widget(ABC):
         self.taint()
         self._sizes = sizes
 
-    def make_x_scroll(self, padchar: str, cursor_x: int, left: str, right: str
-                      ) -> tuple[int, str]:
+    def _make_x_scroll(self, padchar: str, cursor_x: int, left: str, right: str
+                       ) -> tuple[int, str]:
         'Build line of static left, right scrolled with cursor_x if too large.'
-        to_write = left
+        to_write = left[:]
         offset = 0
-        width_gap = self._sizes.x - len(left) - len(right)
+        width_gap = self._sizes.x - len(left + right)
         if width_gap < 0:
             half_width = (self._sizes.x - len(left)) // 2
             if cursor_x > half_width:
@@ -435,14 +435,13 @@ class PromptWidget(_ScrollableWidget):
         self._input_buffer_unsafe = content[:]
 
     def _draw(self) -> None:
-        prefix = self.prefix[:]
         content = self.input_buffer
         if self._cursor_x == len(self.input_buffer):
             content += ' '
-        x_cursor, to_write = self.make_x_scroll(padchar=' ',
-                                                cursor_x=self._cursor_x,
-                                                left=prefix,
-                                                right=content)
+        x_cursor, to_write = self._make_x_scroll(padchar=' ',
+                                                 cursor_x=self._cursor_x,
+                                                 left=self.prefix[:],
+                                                 right=content)
         self._write(self._sizes.y,
                     FormattingString(to_write[:x_cursor])
                     + FormattingString(to_write[x_cursor]).attrd('reverse')
@@ -519,7 +518,7 @@ class _StatusLine(_Widget):
 
     def _draw(self) -> None:
         cursor_x = 0
-        focused = None
+        focus = None
         win_listing = ''
         for w in self._windows:
             win_listing += ' ' if w.idx > 0 else '('
@@ -529,15 +528,15 @@ class _StatusLine(_Widget):
             if w.history.has_unread_highlight:
                 item = f'*{item}'
             if w.idx == self.idx_focus:
-                focused = w
+                focus = w
                 item = f'[{item}]'
                 cursor_x = len(win_listing) + (len(item) // 2)
             win_listing += item
-        assert isinstance(focused, Window)
-        self._write(self._sizes.y, self.make_x_scroll(padchar='=',
-                                                      cursor_x=cursor_x,
-                                                      left=focused.title + ')',
-                                                      right=win_listing)[1])
+        assert isinstance(focus, Window)
+        self._write(self._sizes.y, self._make_x_scroll(padchar='=',
+                                                       cursor_x=cursor_x,
+                                                       left=focus.title + ')',
+                                                       right=win_listing)[1])
 
 
 class Window: