From 96a252f0ef34159016403bc6d9807e33f0e61c16 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Wed, 13 Aug 2025 08:31:56 +0200 Subject: [PATCH] Only enable /part for channel windows. --- ircplom/client_tui.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/ircplom/client_tui.py b/ircplom/client_tui.py index c209f00..60fd1aa 100644 --- a/ircplom/client_tui.py +++ b/ircplom/client_tui.py @@ -53,10 +53,6 @@ class _ClientWindow(Window, ClientQueueMixin): 'Attempt joining a channel.' self._send_msg('JOIN', (channel,)) - def cmd__part(self, channel: str) -> None: - 'Attempt joining a channel.' - self._send_msg('PART', (channel,)) - def cmd__privmsg(self, target: str, msg: str) -> None: 'Send chat message msg to target.' self._send_msg('PRIVMSG', (target, msg), log_target=target, to_log=msg) @@ -71,7 +67,7 @@ class _ClientWindow(Window, ClientQueueMixin): self._send_msg(verb, tuple(params)) -class _PrivmsgPromptWidget(PromptWidget): +class _ChatPrompt(PromptWidget): _nickname: str = '' _nick_confirmed: bool = False @@ -95,8 +91,8 @@ class _PrivmsgPromptWidget(PromptWidget): return f'/window.chat {to_return}' -class _PrivmsgWindow(_ClientWindow): - prompt: _PrivmsgPromptWidget +class _ChatWindow(_ClientWindow): + prompt: _ChatPrompt def __init__(self, chatname: str, get_nick_data: Callable, **kwargs ) -> None: @@ -117,6 +113,13 @@ class _PrivmsgWindow(_ClientWindow): self.cmd__privmsg(target=self.chatname, msg=msg) +class _ChannelWindow(_ChatWindow): + + def cmd__part(self) -> None: + 'Attempt joining a channel.' + self._send_msg('PART', (self.chatname,)) + + @dataclass class _ClientWindowsManager: _tui_log: Callable @@ -132,7 +135,8 @@ class _ClientWindowsManager: def _new_win(self, scope: LogScope, chatname: str = '') -> _ClientWindow: kwargs = {'scope': scope, 'log': self.log, 'win_cls': _ClientWindow} if scope == LogScope.CHAT: - kwargs['win_cls'] = _PrivmsgWindow + kwargs['win_cls'] = (_ChannelWindow if chatname[0] == '#' + else _ChatWindow) kwargs['chatname'] = chatname kwargs['get_nick_data'] = lambda: self._db.get_force('nickname') win = self._tui_new_window(**kwargs) @@ -143,8 +147,7 @@ class _ClientWindowsManager: 'Return client window of scope.' for win in [w for w in self.windows if w.scope == scope]: if scope == LogScope.CHAT: - if isinstance(win, _PrivmsgWindow)\ - and win.chatname == chatname: + if isinstance(win, _ChatWindow) and win.chatname == chatname: return win continue return win @@ -173,7 +176,7 @@ class _ClientWindowsManager: if changes[i]: self.log(f'changing {t[0]}{key} to: [{t[1]}]', scope=scope) for win in [w for w in self.windows - if isinstance(w, _PrivmsgWindow)]: + if isinstance(w, _ChatWindow)]: win.set_prompt_prefix() return bool([w for w in self.windows if w.tainted]) -- 2.30.2