From 128e57c561f86150ae03d46a82936e6ebe0be82a Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Thu, 7 Aug 2025 01:05:24 +0200 Subject: [PATCH] Minor refactoring. --- ircplom/client_tui.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/ircplom/client_tui.py b/ircplom/client_tui.py index 6faa715..cebabeb 100644 --- a/ircplom/client_tui.py +++ b/ircplom/client_tui.py @@ -16,8 +16,6 @@ CMD_SHORTCUTS['nick'] = 'window.nick' CMD_SHORTCUTS['privmsg'] = 'window.privmsg' CMD_SHORTCUTS['reconnect'] = 'window.reconnect' -_PROMPT_UPDATE_TRIGGER_KEYS = {'nick_confirmed', 'nickname'} - class _ClientWindow(Window, ClientQueueMixin): @@ -63,6 +61,11 @@ class _PrivmsgPromptWidget(PromptWidget): self._prefix = (' ' if nick_confirmed else '?') + nickname self.tainted = True + @classmethod + def prefix_update_keys(cls) -> set: + 'Set of .update_prefix args, useful for _ClientWindowsManager.' + return set(list(signature(cls.update_prefix).parameters.keys())[1:]) + def enter(self) -> str: to_return = super().enter() if (not to_return) or to_return[0:1] == '/': @@ -88,13 +91,17 @@ class _ClientWindowsManager: self.windows += [self._new_window(stream) for stream in (STREAM_SERVER, STREAM_RAW)] + def _if_privmsg_update_prefix(self, win: _ClientWindow) -> None: + if isinstance(win, _PrivmsgWindow): + win.prompt.update_prefix( + **{k: getattr(self, k) + for k in _PrivmsgPromptWidget.prefix_update_keys()}) + def _new_window(self, stream: str) -> _ClientWindow: win_class = (_PrivmsgWindow if stream[0:1] != STREAM_PREFIX_META else _ClientWindow) win = self._tui_new_window(win_class, stream=stream) - if isinstance(win, _PrivmsgWindow): - win.prompt.update_prefix( - **{k: getattr(self, k) for k in _PROMPT_UPDATE_TRIGGER_KEYS}) + self._if_privmsg_update_prefix(win) self.windows += [win] return win @@ -116,11 +123,9 @@ class _ClientWindowsManager: 'Apply settings in kwargs, follow represntation update triggres.' for k, v in kwargs.items(): setattr(self, k, v) - if _PROMPT_UPDATE_TRIGGER_KEYS & set(kwargs.keys()): - for prompt in [w.prompt for w in self.windows - if isinstance(w.prompt, _PrivmsgPromptWidget)]: - prompt.update_prefix(**{k: getattr(self, k) - for k in _PROMPT_UPDATE_TRIGGER_KEYS}) + if _PrivmsgPromptWidget.prefix_update_keys() & set(kwargs.keys()): + for win in self.windows: + self._if_privmsg_update_prefix(win) return True return False -- 2.30.2