From: Christian Heller Date: Wed, 11 Jun 2025 19:01:32 +0000 (+0200) Subject: On /disconnect, prefix nickname in prompt with '?' again; overhaul ConnectionWindow... X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%22https:/validator.w3.org/condition?a=commitdiff_plain;h=118e9bd1748c5f41b9d03e6c2901c5a7f6c7703c;p=ircplom On /disconnect, prefix nickname in prompt with '?' again; overhaul ConnectionWindow prompt construction structure. --- diff --git a/ircplom.py b/ircplom.py index 86ee2c5..dfd39cb 100755 --- a/ircplom.py +++ b/ircplom.py @@ -553,10 +553,6 @@ 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 - 1] @@ -640,6 +636,24 @@ class PromptWidget(ScrollableWidget): return to_return +class ConnectionPromptWidget(PromptWidget): + 'PromptWidget with attributes, methods for dealing with an IrcConnection.' + _nickname: str = '' + + def update_prompt(self, + nick_confirmed=False, + nick: Optional[str] = None + ) -> None: + 'Update nickname-relevant knowledge to go into prompt string.' + self._prompt = '' + if nick: + self._nickname = nick + if self._nickname: + self._prompt += ' ' if nick_confirmed else '?' + self._prompt += self._nickname + self._prompt += PROMPT_TEMPLATE + + class LogWidget(ScrollableWidget): 'Collects line-shaped messages, scrolls and wraps them for display.' _view_size: YX @@ -707,12 +721,13 @@ class LogWidget(ScrollableWidget): class Window(Widget): 'Collects a log and a prompt meant for the same content stream.' _y_status: int + prompt: PromptWidget def __init__(self, idx: int, term: Terminal) -> None: self.idx = idx self._term = term self.log = LogWidget(self._term.wrap, self._term.write) - self.prompt = PromptWidget(self._term.write) + self.prompt = self.__annotations__['prompt'](self._term.write) if hasattr(self._term, 'size'): self.set_geometry() @@ -739,6 +754,7 @@ class Window(Widget): class ConnectionWindow(Window): 'Window with attributes and methods for dealing with an IrcConnection.' + prompt: ConnectionPromptWidget def __init__(self, broadcast: Callable[[EventType, Any], None], @@ -766,7 +782,7 @@ class TuiLoop(Loop): self._term = term self._windows = [Window(0, self._term)] self._window_idx = 0 - self._conn_windows: list[Window] = [] + self._conn_windows: list[ConnectionWindow] = [] super().__init__(*args, **kwargs) self.put(Event(EventType.SET_SCREEN)) @@ -799,7 +815,8 @@ class TuiLoop(Loop): conn_idx=event.payload[0], idx=len(self._windows), term=self._term) - conn_win.prompt.update_prompt(f'?{event.payload[1]} ') + conn_win.prompt.update_prompt(nick_confirmed=False, + nick=event.payload[1]) self._windows += [conn_win] self._conn_windows += [conn_win] self._switch_window(conn_win.idx) @@ -819,7 +836,13 @@ class TuiLoop(Loop): self.window.log.draw() elif event.type_ == EventType.NICK_SET: conn_win = self._conn_windows[event.payload[0]] - conn_win.prompt.update_prompt(f' {event.payload[1]} ') + conn_win.prompt.update_prompt(nick_confirmed=True, + nick=event.payload[1]) + if conn_win == self.window: + self.window.prompt.draw() + elif event.type_ == EventType.DISCONNECTED: + conn_win = self._conn_windows[event.payload[0]] + conn_win.prompt.update_prompt(nick_confirmed=False) if conn_win == self.window: self.window.prompt.draw() elif event.type_ == EventType.KEYBINDING: