home · contact · privacy
On /connect, automatically switch TUI to new connection window. master
authorChristian Heller <c.heller@plomlompom.de>
Sat, 7 Jun 2025 16:56:24 +0000 (18:56 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 7 Jun 2025 16:56:24 +0000 (18:56 +0200)
ircplom.py

index b9934c2d7f18d8ad5580cc6c7afe71dd6e8a0895..86c3b6ca304612204354d77f6a8ed255234250d0 100755 (executable)
@@ -580,7 +580,7 @@ class Window(Widget):
     _y_status: int
 
     def __init__(self, idx: int, term: Terminal) -> None:
-        self._idx = idx
+        self.idx = idx
         self._term = term
         self.log = LogWidget(self._term.wrap, self._term.write_yx)
         self.prompt = PromptWidget(self._term.write_yx)
@@ -594,7 +594,7 @@ class Window(Widget):
         self.prompt.set_geometry(YX(self._term.size.y - 1, self._term.size.x))
 
     def draw(self) -> None:
-        idx_box = f'[{self._idx}]'
+        idx_box = f'[{self.idx}]'
         status_line = idx_box + '=' * (self._term.size.x - len(idx_box))
         self._term.clear()
         self.log.draw()
@@ -640,6 +640,7 @@ class TuiLoop(Loop):
             conn_win = Window(len(self._windows), self._term)
             self._windows += [conn_win]
             self._conn_windows += [conn_win]
+            self._switch_window(conn_win.idx)
         elif event.type_ == 'ALERT':
             self.window.log.append(f'{event.type_} {event.payload}')
             self.window.log.draw()
@@ -675,6 +676,10 @@ class TuiLoop(Loop):
         'Currently selected Window.'
         return self._windows[self._window_idx]
 
+    def _switch_window(self, idx: int) -> None:
+        self._window_idx = idx
+        self.window.draw()
+
     def cmd__connect(self,
                      hostname: str,
                      username: str,
@@ -747,8 +752,7 @@ class TuiLoop(Loop):
             window_idx = int(towards)
             if not 0 <= window_idx < n_windows:
                 return f'unavailable window idx: {window_idx}'
-        self._window_idx = window_idx
-        self.window.draw()
+        self._switch_window(window_idx)
         return None