home · contact · privacy
Add very basic keyword highlighting.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 29 Sep 2025 06:30:33 +0000 (08:30 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 29 Sep 2025 06:30:33 +0000 (08:30 +0200)
src/ircplom/client_tui.py
src/tests/config.toml
src/tests/config.txt

index 51398f265865ecdbc8e4bb695a43d67e417f01fa..5ae146cc67802dc8327ec5de3b1261195caa74c1 100644 (file)
@@ -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()
 
index 68c5c908ae5b599236bce0818bf72d10367fbdb1..6dff7f2a50311c5ef6391879d16f385c8daae1a6 100644 (file)
@@ -1,3 +1,5 @@
+to_highlight = ['quux']
+
 [[server]]
 hostname = 'irc.test0.net'
 nickname = 'foo'
index e56ed802784759585af200f30f8f1e817f499d63..b7cdeabf0f8251b1d13b716d6c1ffea5f2a3c8c8 100644 (file)
 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