From 7d5f151758a953615c365f289f0ca8c7c1c71086 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Wed, 24 Sep 2025 06:08:06 +0200 Subject: [PATCH] Reduce reliance on wobbly kwargs. --- ircplom/client_tui.py | 46 ++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/ircplom/client_tui.py b/ircplom/client_tui.py index 35f89b6..3479ca9 100644 --- a/ircplom/client_tui.py +++ b/ircplom/client_tui.py @@ -308,7 +308,7 @@ class _TuiClientDb(_UpdatingNode, SharedClientDbFields): toks += [':['] toks += [f':{update.value.sender}' if update.value.sender else 'NICK:me'] - toks += [f':] {update.value.content}'] + toks += [f':] {update.value.content}'] update.results += [(_LogScope.CHAT, toks)] @@ -363,13 +363,20 @@ class _ClientWindowsManager: ret.sort(key=lambda w: w.idx) return ret - def log(self, msg: str, scope: _LogScope, **kwargs) -> None: + def log(self, + msg: str, + scope: _LogScope, + alert=False, + target='', + out: Optional[bool] = None + ) -> None: 'From parsing scope, kwargs, build prefix before sending to logger.' prefix = '$' - if 'out' in kwargs: - prefix = _LOG_PREFIX_OUT if kwargs['out'] else _LOG_PREFIX_IN - kw = {k: v for k, v in kwargs.items() if k in {'log_target', 'alert'}} - self._tui_log(msg, scope=scope, prefix=prefix, **kw) + if out is not None: + prefix = _LOG_PREFIX_OUT if out else _LOG_PREFIX_IN + kwargs = {'alert': True} if alert else {} + kwargs |= {'target': target} if target else {} + self._tui_log(msg, scope=scope, prefix=prefix, **kwargs) def update_db(self, update: _Update) -> bool: 'Apply update to .db, and if changing anything, log and trigger.' @@ -384,15 +391,15 @@ class _ClientWindowsManager: nuh = self.db.users[content] content = str(nuh) if transform == 'NUH' else nuh.nick msg += content - log_kwargs: dict[str, str | bool] = {} + out: Optional[bool] = None + target = '' if update.full_path == ('message',): - log_kwargs['log_target'] = (update.value.target - or update.value.sender) - log_kwargs['out'] = not bool(update.value.sender) + target = update.value.target or update.value.sender + out = not bool(update.value.sender) elif scope in {_LogScope.CHAT, _LogScope.USER, _LogScope.USER_NO_CHANNELS}: - log_kwargs['log_target'] = update.full_path[1] - self.log(msg, scope=scope, **log_kwargs) + target = update.full_path[1] + self.log(msg, scope=scope, target=target, out=out) for win in [w for w in self.windows if isinstance(w, _ChatWindow)]: win.set_prompt_prefix() return bool([w for w in self.windows if w.tainted]) @@ -408,7 +415,7 @@ class ClientTui(BaseTui): def _log_target_wins(self, **kwargs) -> Sequence[Window]: if (scope := kwargs.get('scope', None)): return self._client_mngrs[kwargs['client_id']].windows_for( - scope, kwargs.get('log_target', '')) + scope, kwargs.get('target', '')) return super()._log_target_wins(**kwargs) def log(self, msg: str, **kwargs) -> tuple[tuple[int, ...], str]: @@ -518,13 +525,20 @@ class ClientKnowingTui(Client): except TargetUserOffline as e: name = f'{e}' self._log(f'{name} not online', scope=_LogScope.CHAT, - log_target=name, alert=True) + target=name, alert=True) def _alert(self, msg: str) -> None: self._log(msg, scope=_LogScope.DEBUG, alert=True) - def _log(self, msg: str, scope: _LogScope, **kwargs) -> None: - self._client_tui_trigger('log', scope=scope, msg=msg, **kwargs) + def _log(self, + msg: str, + scope: _LogScope, + alert=False, + target='', + out: Optional[bool] = None + ) -> None: + self._client_tui_trigger('log', scope=scope, msg=msg, alert=alert, + target=target, out=out) def _on_update(self, *path) -> None: for path, value in self.db.into_endnode_updates(path): -- 2.30.2