home · contact · privacy
Allow slash-free direct chatting in PRIVMSG windows.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 5 Aug 2025 00:43:22 +0000 (02:43 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 5 Aug 2025 00:43:22 +0000 (02:43 +0200)
ircplom/client_tui.py

index c7e60c2fadd9698094e1a25c84ac69c63a50981c..6245571bc3d3bb79d0cb1f1f3ad799beeeb627ab 100644 (file)
@@ -64,14 +64,33 @@ class _ClientWindow(Window, ClientQueueMixin):
                    payload=IrcMessage(verb='PRIVMSG', params=(target, msg)))
 
 
+class _PrivmsgPromptWidget(_ClientPromptWidget):
+
+    def enter(self) -> str:
+        to_return = super().enter()
+        if (not to_return) or to_return[0:1] == '/':
+            return to_return
+        return f'/window.chat {to_return}'
+
+
+class _PrivmsgWindow(_ClientWindow):
+    prompt: _PrivmsgPromptWidget
+
+    def cmd__chat(self, msg: str) -> None:
+        'PRIVMSG to .chat.'
+        self.cmd__privmsg(self.chat, msg)
+
+
 class ClientTui(BaseTui):
     'TUI expanded towards Client features.'
 
     def _new_client_window(self, client_id: UUID, chat: str = ''
                            ) -> _ClientWindow:
         new_idx = len(self.windows)
-        win = _ClientWindow(idx=new_idx, term=self.term, q_out=self.q_out,
-                            client_id=client_id, chat=chat)
+        win_class = (_PrivmsgWindow if (chat and chat[0].isalpha())
+                     else _ClientWindow)
+        win = win_class(idx=new_idx, term=self.term, q_out=self.q_out,
+                        client_id=client_id, chat=chat)
         self.windows += [win]
         self._switch_window(new_idx)
         return win