From: Christian Heller Date: Mon, 29 Sep 2025 06:30:33 +0000 (+0200) Subject: Add very basic keyword highlighting. X-Git-Url: https://plomlompom.com/repos/?a=commitdiff_plain;h=d6df1838042c79e517987500b2d5d405d5d31ec7;p=ircplom Add very basic keyword highlighting. --- diff --git a/src/ircplom/client_tui.py b/src/ircplom/client_tui.py index 51398f2..5ae146c 100644 --- a/src/ircplom/client_tui.py +++ b/src/ircplom/client_tui.py @@ -324,11 +324,11 @@ class _UpdatingServerCapability(_UpdatingNode, ServerCapability): class _TuiClientDb(_UpdatingNode, SharedClientDbFields): + channels: _UpdatingDict[_UpdatingChannel] caps: _UpdatingDict[_UpdatingServerCapability] isupport: _UpdatingDict[str] motd: tuple[str, ...] = tuple() users: _UpdatingDict[_UpdatingUser] - channels: _UpdatingDict[_UpdatingChannel] def recursive_set_and_report_change(self, update: _Update) -> None: super().recursive_set_and_report_change(update) @@ -352,11 +352,13 @@ class _ClientWindowsManager: def __init__(self, tui_log: Callable, tui_new_window: Callable, - path_logs: Optional[Path] + path_logs: Optional[Path], + to_highlight: tuple[str, ...] ) -> None: self._tui_log = tui_log self._tui_new_window = tui_new_window self._path_logs = path_logs + self._to_highlight = to_highlight self.db = _TuiClientDb() self.windows: list[_ClientWindow] = [] @@ -417,6 +419,9 @@ class _ClientWindowsManager: prefix = _LOG_PREFIX_OUT if out else LOG_PREFIX_IN kwargs = {'alert': True} if alert else {} kwargs |= {'target': target} if target else {} + for word in [word for word in self._to_highlight if word in msg]: + prefix += '*' + break self._tui_log(msg, scope=scope, prefix=prefix, **kwargs) def update_db(self, update: _Update) -> bool: @@ -518,6 +523,7 @@ class ClientTui(BaseTui): _client_cls = ClientKnowingTui _path_config: Optional[Path] = _PATH_CONFIG _path_logs: Optional[Path] = _PATH_LOGS + _to_highlight: tuple[str, ...] = tuple() def __init__(self, **kwargs) -> None: super().__init__(**kwargs) @@ -532,6 +538,7 @@ class ClientTui(BaseTui): config = toml_load(f) else: self.log(f'No config at {self._path_config}, proceeding without.') + self._to_highlight = config.get('to_highlight', tuple()) for server_conf in config.get('server', []): self.log(f'Connecting: {server_conf}') hostname = server_conf['hostname'] @@ -560,7 +567,7 @@ class ClientTui(BaseTui): msg, client_id=client_id, **kw), tui_new_window=lambda win_cls, **kw: self._new_window( win_cls, _q_out=self._q_out, client_id=client_id, **kw), - path_logs=self._path_logs) + path_logs=self._path_logs, to_highlight=self._to_highlight) if getattr(self._client_mngrs[client_id], todo)(**kwargs) is not False: self.redraw_affected() diff --git a/src/tests/config.toml b/src/tests/config.toml index 68c5c90..6dff7f2 100644 --- a/src/tests/config.toml +++ b/src/tests/config.toml @@ -1,3 +1,5 @@ +to_highlight = ['quux'] + [[server]] hostname = 'irc.test0.net' nickname = 'foo' diff --git a/src/tests/config.txt b/src/tests/config.txt index e56ed80..b7cdeab 100644 --- a/src/tests/config.txt +++ b/src/tests/config.txt @@ -12,13 +12,13 @@ 1 $ port set to: [1234] 1 $ nick_wanted set to: [foo] 1 $ user_wanted set to: [baz] -1 $ realname set to: [quux] +1 $* realname set to: [quux] 1 $ password set to: [bar] 1 $ connection_state set to: [connecting] 1 $ connection_state set to: [connected] , $ CONNECTED 1 > CAP LS :302 -1 > USER baz 0 * :quux +1 >* USER baz 0 * :quux 1 > NICK :foo > /quit