From: Christian Heller Date: Wed, 6 Aug 2025 22:22:15 +0000 (+0200) Subject: Minor refactoring. X-Git-Url: https://plomlompom.com/repos/booking/static/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/new_day?a=commitdiff_plain;ds=inline;p=ircplom Minor refactoring. --- diff --git a/ircplom/client_tui.py b/ircplom/client_tui.py index cdbb379..ad52f58 100644 --- a/ircplom/client_tui.py +++ b/ircplom/client_tui.py @@ -131,20 +131,12 @@ class ClientTui(BaseTui): super().__init__(**kwargs) self._client_mngrs: dict[str, _ClientWindowsManager] = {} - def _new_window(self, win_class, **kwargs) -> Window: - new_idx = len(self._windows) - win = win_class(idx=new_idx, term=self._term, _q_out=self._q_out, - **kwargs) - self._windows += [win] - self._switch_window(new_idx) - return win - def for_client_do(self, client_id: str, todo: str, **kwargs) -> None: 'Forward todo to appropriate ClientTuiMgr.' if client_id not in self._client_mngrs: self._client_mngrs[client_id] = _ClientWindowsManager( new_window=lambda cls, **kwargs: self._new_window( - cls, client_id=client_id, **kwargs)) + cls, _q_out=self._q_out, client_id=client_id, **kwargs)) client_data = self._client_mngrs[client_id] method = getattr(client_data, todo) if method(**kwargs) or signature(method).return_annotation is None: diff --git a/ircplom/tui_base.py b/ircplom/tui_base.py index 6a92b32..d5e0987 100644 --- a/ircplom/tui_base.py +++ b/ircplom/tui_base.py @@ -362,13 +362,22 @@ class BaseTui(QueueMixin): super().__init__(**kwargs) self._term = term self._window_idx = 0 - self._windows = [Window(idx=self._window_idx, term=self._term)] + self._windows: list[Window] = [] + self._new_window() self._log = Logger( lambda msg: # pylint: disable=unnecessary-lambda # to keep … self.window.log.append(msg)) # … up-to-date _what_ window's .log self._set_screen() signal(SIGWINCH, lambda *_: self._set_screen()) + def _new_window(self, win_class=Window, **kwargs) -> Window: + new_idx = len(self._windows) + win = win_class(idx=new_idx, term=self._term, **kwargs) + self._windows += [win] + if new_idx != self._window_idx: + self._switch_window(new_idx) + return win + def redraw_affected(self) -> None: 'On focused window call .draw_tainted, then flush screen.' self.window.draw_tainted()