home · contact · privacy
In connection window, prefix prompt with nickname (after '?' for 'unconfirmed').
authorChristian Heller <c.heller@plomlompom.de>
Wed, 11 Jun 2025 12:39:21 +0000 (14:39 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 11 Jun 2025 12:39:21 +0000 (14:39 +0200)
ircplom.py

index bdf41716601f3649a88dd9ec5c7b25a869d60a77..a603d0ed530fdc537eb19db44a6af295c591aa67 100755 (executable)
@@ -237,7 +237,7 @@ class IrcConnection:
         self._socket: Optional[socket] = None
         self._assumed_open = False
         self._loop: Optional[ConnectionLoop] = None
-        self._broadcast(EventType.CONN_WINDOW, self._idx)
+        self._broadcast(EventType.CONN_WINDOW, self._login.nick)
         self._start_connecting()
 
     def _start_connecting(self) -> None:
@@ -540,6 +540,7 @@ class PromptWidget(ScrollableWidget):
     'Keyboard-controlled command input field.'
     _y: int
     _width: int
+    _prompt: str = PROMPT_TEMPLATE
 
     def __init__(self, *args, **kwargs) -> None:
         super().__init__(*args, **kwargs)
@@ -549,6 +550,10 @@ class PromptWidget(ScrollableWidget):
     def set_geometry(self, measurements: YX) -> None:
         self._y, self._width = measurements
 
+    def update_prompt(self, new_prefix: str) -> None:
+        'Set as new prompt string new_prefix followed by PROMPT_TEMPLATE.'
+        self._prompt = f'{new_prefix}{PROMPT_TEMPLATE}'
+
     def append(self, to_append: str) -> None:
         self._cursor_x += len(to_append)
         self._input_buffer = (self._input_buffer[:self._cursor_x - 2]
@@ -558,21 +563,21 @@ class PromptWidget(ScrollableWidget):
         self.draw()
 
     def draw(self) -> None:
-        prompt = PROMPT_TEMPLATE[:]
+        prefix = self._prompt[:]
         content = self._input_buffer[:]
         if self._cursor_x > len(self._input_buffer):
             content += ' '
         half_width = self._width // 2
         offset = 0
-        if len(prompt) + len(content) > self._width\
+        if len(prefix) + len(content) > self._width\
                 and self._cursor_x > half_width:
-            prompt += PROMPT_ELL_IN
+            prefix += PROMPT_ELL_IN
             if self._cursor_x > len(content) - half_width:
-                offset = len(content) - self._width + len(prompt)
+                offset = len(content) - self._width + len(prefix)
             else:
-                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:]}'
+                offset = self._cursor_x - half_width + (len(prefix) // 2)
+        cursor_x_to_write = len(prefix) - 1 + self._cursor_x - offset
+        to_write = f'{prefix}{content[offset:]}'
         if len(to_write) > self._width:
             to_write = (to_write[:self._width - len(PROMPT_ELL_OUT)]
                         + PROMPT_ELL_OUT)
@@ -786,8 +791,11 @@ class TuiLoop(Loop):
                 window.set_geometry()
             self.window.draw()
         elif event.type_ == EventType.CONN_WINDOW:
-            conn_win = ConnectionWindow(self.broadcast, event.payload[0],
-                                        len(self._windows), self._term)
+            conn_win = ConnectionWindow(broadcast=self.broadcast,
+                                        conn_idx=event.payload[0],
+                                        idx=len(self._windows),
+                                        term=self._term)
+            conn_win.prompt.update_prompt(f'?{event.payload[1]} ')
             self._windows += [conn_win]
             self._conn_windows += [conn_win]
             self._switch_window(conn_win.idx)