home · contact · privacy
Fix client prompt prefix syncs. master
authorChristian Heller <c.heller@plomlompom.de>
Mon, 4 Aug 2025 16:06:47 +0000 (18:06 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 4 Aug 2025 16:06:47 +0000 (18:06 +0200)
ircplom/client_tui.py
ircplom/tui_base.py

index fca810007f9ff7629421a27873945dad757c3b35..ced61290cf15fb781196995a517eaa7c5ed46e57 100644 (file)
@@ -4,8 +4,8 @@ from dataclasses import dataclass
 from uuid import UUID
 # ourselves
 from ircplom.events import PayloadMixin
-from ircplom.tui_base import (BaseTui, Window, TuiEvent, CMD_SHORTCUTS,
-                              PROMPT_TEMPLATE)
+from ircplom.tui_base import (BaseTui, PromptWidget, TuiEvent, Window,
+                              CMD_SHORTCUTS)
 from ircplom.irc_conn import IrcMessage
 from ircplom.client import (CHAT_GLOB, IrcConnSetup, Client,
                             ClientIdMixin, ClientQueueMixin,
@@ -18,8 +18,26 @@ CMD_SHORTCUTS['privmsg'] = 'window.privmsg'
 CMD_SHORTCUTS['reconnect'] = 'window.reconnect'
 
 
+class _ClientPromptWidget(PromptWidget):
+    _prefix: str = ''
+
+    @property
+    def prefix(self) -> str:
+        return self._prefix + super().prefix
+
+    @prefix.setter
+    def prefix(self, to_set: str) -> None:
+        self._prefix = to_set
+        self.tainted = True
+
+    def prefix_copy_to(self, other: '_ClientPromptWidget') -> None:
+        'Copy over .prefix to other.'
+        other.prefix = self._prefix
+
+
 class _ClientWindow(Window, ClientQueueMixin):
     client_id_name = 'client_id'
+    prompt: _ClientPromptWidget
 
     def __init__(self, client_id: UUID, chat: str = '', **kwargs) -> None:
         self.client_id = client_id
@@ -78,7 +96,7 @@ class ClientTui(BaseTui):
             return candidates[0]
         win = self._new_client_window(client_id=client_id, chat=chat)
         if client_wins:
-            win.prompt.prefix = client_wins[0].prompt.prefix
+            client_wins[0].prompt.prefix_copy_to(win.prompt)
         return win
 
     def cmd__connect(self, hostname: str, nickname: str, realname: str
@@ -115,12 +133,9 @@ class _ClientPromptEvent(_ClientWindowEvent, PayloadMixin):
     payload: tuple[str, str]
 
     def affect(self, target: ClientTui) -> None:
-        new_prefix = ((' ' if self.payload[0] else '?')
-                      + f'{self.payload[1]}{PROMPT_TEMPLATE}')
+        new_prefix = (' ' if self.payload[0] else '?') + self.payload[1]
         for win in target.client_wins(self.client_id):
-            prompt = win.prompt
-            prompt.prefix = new_prefix
-            prompt.tainted = True
+            win.prompt.prefix = new_prefix
         target.redraw_affected()
 
 
index d3a0379a022440daa1a1a933a58ae8958a8dc640..5a758d6ddb65f2396d74ed1231bcca876104f20b 100644 (file)
@@ -167,7 +167,8 @@ class _LogWidget(_ScrollableWidget):
             self._history_idx = history_idx_to_wrapped_idx - len(self._history)
 
 
-class _PromptWidget(_ScrollableWidget):
+class PromptWidget(_ScrollableWidget):
+    'Manages/displays keyboard input field.'
     _y: int
     _width: int
     _history_idx: int = 0
@@ -176,9 +177,13 @@ class _PromptWidget(_ScrollableWidget):
 
     def __init__(self, **kwargs) -> None:
         super().__init__(**kwargs)
-        self.prefix = PROMPT_TEMPLATE
         self._reset_buffer('')
 
+    @property
+    def prefix(self) -> str:
+        'Main input prefix.'
+        return PROMPT_TEMPLATE[:]
+
     @property
     def _input_buffer(self) -> str:
         return self._input_buffer_unsafe[:]
@@ -283,7 +288,7 @@ class _PromptWidget(_ScrollableWidget):
 class Window(_Widget):
     'Widget filling entire screen with sub-widgets like .prompt, .log.'
     _y_status: int
-    prompt: _PromptWidget
+    prompt: PromptWidget
 
     def __init__(self, idx: int, term: 'Terminal', **kwargs) -> None:
         super().__init__(**kwargs)