home · contact · privacy
Minor refactoring. master
authorChristian Heller <c.heller@plomlompom.de>
Wed, 6 Aug 2025 22:22:15 +0000 (00:22 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 6 Aug 2025 22:22:15 +0000 (00:22 +0200)
ircplom/client_tui.py
ircplom/tui_base.py

index cdbb379c00d12791339686365e2c49c3e1d46d50..ad52f58efdb391a4026526df9edc032b7ca39d3e 100644 (file)
@@ -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:
index 6a92b324da4e03215c08c8e4f83a83db01e54c6e..d5e09873179068431b6713f290b1d6639884b12d 100644 (file)
@@ -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()