From: Christian Heller Date: Sun, 10 Aug 2025 11:00:32 +0000 (+0200) Subject: Ensure /reconnect on "already connected" failure complains directly back into calling... X-Git-Url: https://plomlompom.com/repos/booking/static/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/foo.html?a=commitdiff_plain;h=56a76b8c7c84a49a09ed5212a9221036f9ec7bb5;p=ircplom Ensure /reconnect on "already connected" failure complains directly back into calling window. --- diff --git a/ircplom/client.py b/ircplom/client.py index bd6b9a6..e62e95e 100644 --- a/ircplom/client.py +++ b/ircplom/client.py @@ -187,10 +187,9 @@ class Client(ABC, ClientQueueMixin): self.update_login(nick_confirmed=False, nickname=self.conn_setup.nickname) self._log(f'connecting {self.conn_setup}') - self.start_connecting() + self._start_connecting() - def start_connecting(self) -> None: - 'Start thread to set up _IrcConnection at .conn.' + def _start_connecting(self) -> None: def connect(self) -> None: try: diff --git a/ircplom/client_tui.py b/ircplom/client_tui.py index 35b8403..45aa9df 100644 --- a/ircplom/client_tui.py +++ b/ircplom/client_tui.py @@ -16,6 +16,8 @@ CMD_SHORTCUTS['nick'] = 'window.nick' CMD_SHORTCUTS['privmsg'] = 'window.privmsg' CMD_SHORTCUTS['reconnect'] = 'window.reconnect' +_STREAM_SAME = '=' + class _ClientWindow(Window, ClientQueueMixin): @@ -37,7 +39,7 @@ class _ClientWindow(Window, ClientQueueMixin): def cmd__reconnect(self) -> None: 'Attempt reconnection.' - self._client_trigger('start_connecting') + self._client_trigger('reconnect') def cmd__nick(self, new_nick: str) -> None: 'Attempt nickname change.' @@ -186,8 +188,20 @@ class _ClientKnowingTui(Client): self._put(TuiEvent.affector('for_client_do').kw( client_id=self.client_id, todo=todo, **kwargs)) + def reconnect(self) -> None: + 'Catch /reconnect, only initiate if not connected, else complain back.' + if self.conn: + self._log('not re-connecting since already connected', + stream=_STREAM_SAME, alert=True) + return + self._start_connecting() + def _do_log(self, msg: str, stream: str = STREAM_SERVER) -> None: - self._client_tui_trigger('log', stream=stream, msg=msg) + if stream == _STREAM_SAME: + self._put(TuiEvent.affector('_log').kw(msg=msg)) + self._put(TuiEvent.affector('redraw_affected')) + else: + self._client_tui_trigger('log', stream=stream, msg=msg) def update_login(self, nick_confirmed: bool, nickname: str = '') -> None: super().update_login(nick_confirmed, nickname)