Skip to content

Commit 3716f5b

Browse files
committed
Add the -r flag to the hide command
hide can also take multiple uids. Bump version to 1.1
1 parent 1d628f4 commit 3716f5b

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
3+
## 1.1
4+
5+
* The hide command can now take multiple UIDs, and will hide all of them.
6+
* The hide command takes a new argument -r/--regex that indicates UIDs should be
7+
interpreted as regular expressions.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ This should display the two lines before `END` in the centre of the currently
6868
focused display, on top of all other windows. The text is transparent to all
6969
input events. If show is called with the `--markup` option, the text is
7070
interpreted as [Pango markup](https://docs.gtk.org/Pango/pango_markup.html)
71-
('<', '>' and '&' must be escaped as '&lt;', '&gt;', and '&amp;').
71+
('<', '>' and '&' must be escaped as '\&lt;', '\&gt;', and '\&amp;').
7272
The `--css` command line argument (e.g. `wlosd --css style.css`) can be used to
7373
pass a GTK4 style sheet (see
7474
[style.css](https://github.com/fshaked/wlosd/blob/main/style.css) for example,

wlosd/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1"
1+
__version__ = "1.1"

wlosd/wlosd.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from ctypes import CDLL
55
import logging
66
import os
7+
import re
78
import sys
89
import threading
910
import 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

Comments
 (0)