From 7b9baef2d46eb9945878c1b9f6b6337084679f72 Mon Sep 17 00:00:00 2001 From: Peter Rice Date: Sun, 8 Jun 2025 18:35:20 -0400 Subject: [PATCH] support empty prompt --- src/qbpm/menus.py | 7 ++++--- tests/test_choose.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/qbpm/menus.py b/src/qbpm/menus.py index c9b8e43..f507881 100644 --- a/src/qbpm/menus.py +++ b/src/qbpm/menus.py @@ -18,6 +18,7 @@ class Dmenu: return which(self.name) is not None def command(self, prompt: str, qb_args: str) -> str: + prompt = prompt or "''" return f"{self.name} {self.args.format(prompt=prompt, qb_args=qb_args)}" def commandline(self, profiles: list[str], prompt: str, qb_args: str) -> str: @@ -59,9 +60,9 @@ def custom_dmenu(command: str) -> Dmenu: split = command.split(" ", maxsplit=1) if len(split) == 1 or not split[1]: name = Path(command).name - for m in supported_menus(): - if isinstance(m, Dmenu) and m.name == name: - return m if m.name == command else replace(m, name=command) + for menu in supported_menus(): + if isinstance(menu, Dmenu) and menu.name == name: + return menu if menu.name == command else replace(menu, name=command) return Dmenu(split[0], split[1] if len(split) == 2 else "") diff --git a/tests/test_choose.py b/tests/test_choose.py index 4a8cc5a..36bdf3d 100644 --- a/tests/test_choose.py +++ b/tests/test_choose.py @@ -70,7 +70,7 @@ def test_custom_menu_default_args(tmp_path: Path): environ["DISPLAY"] = ":1" dmenu = find_menu(str(menu)) assert dmenu is not None - assert f"{menu} -dmenu" in dmenu.commandline(["p1", "p2"], "", "") + assert f"{menu} -dmenu -no-custom -p ''" in dmenu.commandline(["p1", "p2"], "", "") def test_custom_menu_custom_args(tmp_path: Path): @@ -80,4 +80,4 @@ def test_custom_menu_custom_args(tmp_path: Path): environ["DISPLAY"] = ":1" dmenu = find_menu(command) assert dmenu is not None - assert command in dmenu.commandline(["p1", "p2"], "", "") + assert dmenu.commandline(["p1", "p2"], "", "").endswith(command) -- 2.51.2