44from ctypes import CDLL
55import logging
66import os
7+ import re
78import sys
89import threading
910import typing as t
@@ -157,14 +158,15 @@ def on_show(self, uid: str, text: str, is_markup: bool,
157158
158159 return GLib .SOURCE_REMOVE
159160
160- def on_hide (self , uid : str ) -> bool :
161- self .cancel_hide_timer (uid )
162- if uid not in self ._windows :
163- logger .warning ("no such id: %s" , uid )
164- return GLib .SOURCE_REMOVE
161+ def on_hide (self , uids : list [str ]) -> bool :
162+ for uid in uids :
163+ self .cancel_hide_timer (uid )
164+ if uid not in self ._windows :
165+ logger .warning ("no such id: %s" , uid )
166+ continue
165167
166- self ._windows [uid ].destroy ()
167- del self ._windows [uid ]
168+ self ._windows [uid ].destroy ()
169+ del self ._windows [uid ]
168170 return GLib .SOURCE_REMOVE
169171
170172 def on_reload_css (self ) -> bool :
@@ -191,7 +193,7 @@ def cmds_listener(app: MainApp) -> None:
191193 commands = {
192194 "exit" : "Terminate the program." ,
193195 "help" : "Display help information about cmd." ,
194- "hide" : "Hide a message ." ,
196+ "hide" : "Hide messages ." ,
195197 "list-uids" : "List all currently showing uids." ,
196198 "quit" : "Terminate the program." ,
197199 "reload-css" : "Reload and reapply the css file." ,
@@ -266,7 +268,10 @@ def cmds_listener(app: MainApp) -> None:
266268 " to replace the message (by another show"
267269 " command) or hide it." )
268270
269- parsers ["hide" ].add_argument ("uid" , help = "the uid of the show command to hide." )
271+ parsers ["hide" ].add_argument ("-r" , "--regex" , action = "store_true" ,
272+ help = "Interpret uid as a (Python's re library) regular expression." )
273+ parsers ["hide" ].add_argument ("uids" , metavar = "uid" , nargs = "+" ,
274+ help = "uids to hide." )
270275 # yapf: enable
271276
272277 while True :
@@ -301,10 +306,15 @@ def cmds_listener(app: MainApp) -> None:
301306 parser .print_help ()
302307
303308 case "hide" :
304- if args .uid in app .get_uids ():
305- GLib .idle_add (app .on_hide , args .uid )
309+ if args .regex :
310+ hide_uids = [
311+ uid for uid in app .get_uids () if any (
312+ re .search (pattern , uid ) for pattern in args .uids )
313+ ]
306314 else :
307- print (f"unrecognised uid: { args .uid } " )
315+ hide_uids = [ uid for uid in args .uids if uid in app .get_uids () ]
316+
317+ GLib .idle_add (app .on_hide , hide_uids )
308318
309319 case "list-uids" :
310320 uids = app .get_uids ()
0 commit comments