home · contact · privacy
Ensure /reconnect on "already connected" failure complains directly back into calling...
authorChristian Heller <c.heller@plomlompom.de>
Sun, 10 Aug 2025 11:00:32 +0000 (13:00 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 10 Aug 2025 11:00:32 +0000 (13:00 +0200)
ircplom/client.py
ircplom/client_tui.py

index bd6b9a639a39a4b294924f44e5edfc0591ef7a5b..e62e95e65daed497c0ea9731d3ac8cb1b49b3f7e 100644 (file)
@@ -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:
index 35b840327c0a5c4b6b0a78c53baa433c75345ae9..45aa9df4ccb8ccff00a03cd2b032be60f3842ed5 100644 (file)
@@ -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)