@@ -143,7 +143,6 @@ def on_hide(self, uid: str) -> bool:
143143
144144 def on_reload_css (self ) -> bool :
145145 if ARGS .css is None :
146- logger .warning ("no css file to reload" )
147146 return GLib .SOURCE_REMOVE
148147 self ._css_provider .load_from_path (ARGS .css )
149148 return GLib .SOURCE_REMOVE
@@ -163,11 +162,7 @@ def __str__(self) -> str:
163162
164163
165164def cmds_listener (app : MainApp ) -> None :
166- commands = [
167- "help" , "exit" , "quit" , "show" , "hide" , "list-uids" , "reload-css"
168- ]
169-
170- description = {
165+ commands = {
171166 "exit" : "Terminate the program." ,
172167 "help" : "Display help information about cmd." ,
173168 "hide" : "Hide a message." ,
@@ -203,20 +198,18 @@ def cmds_listener(app: MainApp) -> None:
203198 help = f"one of {{{ ',' .join (commands )} }}" )
204199
205200 parsers = {}
206- for cmd in commands :
201+ for cmd , description in commands . items () :
207202 parsers [cmd ] = cmd_parsers .add_parser (cmd ,
208203 prog = cmd ,
209204 add_help = False ,
210- description = description [ cmd ] )
205+ description = description )
211206 parsers [cmd ].error = ParsingError .throw # type: ignore[method-assign]
212207
213- parsers ["help" ].add_argument ("help_cmd" ,
214- default = None ,
215- choices = (["" ] + commands ),
216- nargs = "?" ,
208+ # yapf: disable
209+ parsers ["help" ].add_argument ("help_cmd" , default = None , nargs = "?" ,
210+ choices = (["" ] + list (commands )),
217211 metavar = "," .join (commands ))
218212
219- # yapf: disable
220213 parsers ["show" ].add_argument ("-b" , "--bottom" , dest = "position" , default = [],
221214 action = "append_const" , const = Gtk4LayerShell .Edge .BOTTOM ,
222215 help = "Display the message at the bottom of the screen." )
@@ -245,7 +238,6 @@ def cmds_listener(app: MainApp) -> None:
245238
246239 parsers ["hide" ].add_argument ("uid" , help = "the uid of the show command to hide." )
247240 # yapf: enable
248- # Process commands from stdin
249241
250242 while True :
251243 cmd_line : str = sys .stdin .readline ()
@@ -268,33 +260,41 @@ def cmds_listener(app: MainApp) -> None:
268260 continue
269261
270262 match args .command :
263+ case "exit" | "quit" :
264+ GLib .idle_add (app .on_exit )
265+ return
266+
271267 case "help" :
272268 if args .help_cmd :
273269 parsers [args .help_cmd ].print_help ()
274270 else :
275271 parser .print_help ()
276272
277- case "exit" | "quit" :
278- GLib .idle_add (app .on_exit )
279- return
273+ case "hide" :
274+ if args .uid in app .get_uids ():
275+ GLib .idle_add (app .on_hide , args .uid )
276+ else :
277+ print (f"unrecognised uid: { args .uid } " )
278+
279+ case "list-uids" :
280+ uids = app .get_uids ()
281+ if uids :
282+ print ("\n " .join (uids ))
283+
284+ case "reload-css" :
285+ if ARGS .css is None :
286+ print ("no css file to reload" )
287+ else :
288+ GLib .idle_add (app .on_reload_css )
280289
281290 case "show" :
282291 text = read_text (args .end_mark )
283292
284293 GLib .idle_add (app .on_show , args .uid , text , args .sec ,
285294 args .classes , args .output , args .position )
286295
287- case "hide" :
288- GLib .idle_add (app .on_hide , args .uid )
289-
290- case "reload-css" :
291- GLib .idle_add (app .on_reload_css )
292-
293- case "list-uids" :
294- print ("\n " .join (app .get_uids ()))
295-
296296 case _:
297- logger . warning ( "unknown command: %s" , cmd_line )
297+ assert False , f "unknown command: { cmd_line } "
298298
299299
300300def read_text (end_mark : str ) -> str :
0 commit comments