From: Christian Heller Date: Sat, 7 Jun 2025 16:56:24 +0000 (+0200) Subject: On /connect, automatically switch TUI to new connection window. X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/static/test?a=commitdiff_plain;h=0402dcf7a8581c2071fa952f817fdd8208c02294;p=ircplom On /connect, automatically switch TUI to new connection window. --- diff --git a/ircplom.py b/ircplom.py index b9934c2..86c3b6c 100755 --- a/ircplom.py +++ b/ircplom.py @@ -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