feat(cli): highlight action picker search

This commit is contained in:
ViditOstwal committed 2026-10-21 14:12:20 +05:30
1 parent a8877f0cdf
commit f74e87f6c2
2 files changed
+45 -7

No files matched your search

+23 -5
View File
@@ -126,15 +126,33 @@ def _draw_multi(
extra_lines = 0
sys.stdout.write(f"\033[2K{hint}\n")
if searchable:
match_count = ""
search_title = "SEARCH ACTIONS"
search_width = min(
52,
max(len(search_title) + 1, shutil.get_terminal_size().columns - 6),
)
if query:
count = len(rows)
noun = "match" if count == 1 else "matches"
match_count = f" · {count} {noun}"
sys.stdout.write(f"\033[2K {_GREEN}Search: {query}{match_count}{_RESET}\n")
extra_lines += 1
search_prompt = f"{query}█ · {count} {noun} · Esc to clear"
else:
search_prompt = "type to filter"
search_prompt = search_prompt[:search_width]
title_fill = "─" * (search_width - len(search_title) - 1)
sys.stdout.write("\033[2K\n")
sys.stdout.write(
f"\033[2K {_GREEN}╭─ {_BOLD}{search_title}{_GREEN} {title_fill}╮{_RESET}\n"
)
sys.stdout.write(
f"\033[2K {_GREEN}│ {_BOLD}{search_prompt:<{search_width}s}{_GREEN} │{_RESET}\n"
)
sys.stdout.write(f"\033[2K {_GREEN}╰{'─' * (search_width + 2)}╯{_RESET}\n")
sys.stdout.write("\033[2K\n")
extra_lines += 5
if searchable and query and not rows:
sys.stdout.write(f"\033[2K {_DIM}No matching actions{_RESET}\n")
sys.stdout.write(
f"\033[2K {_DIM}No matching actions. Press Esc to clear.{_RESET}\n"
)
extra_lines += 1
for pos in range(start, end):
i = rows[pos]
+22 -2
View File
@@ -86,14 +86,34 @@ def test_searchable_draw_shows_the_query_and_an_empty_match(monkeypatch) -> None
)
rendered = output.getvalue()
assert "Search:" in rendered
assert "SEARCH ACTIONS" in rendered
assert "missing" in rendered
assert "type to filter" in rendered
assert "No matching actions" in rendered
assert "Esc to clear" in rendered
assert "No matching actions. Press Esc to clear." in rendered
assert "0 matches" in rendered
assert "Send an email" not in rendered
def test_searchable_draw_shows_a_prominent_empty_search_prompt(monkeypatch) -> None:
output = StringIO()
monkeypatch.setattr(tui_picker.sys, "stdout", output)
tui_picker._draw_multi(
["Send an email (send-email)"],
cursor=0,
selected=set(),
searchable=True,
)
rendered = output.getvalue()
assert "SEARCH ACTIONS" in rendered
assert "type to filter" in rendered
assert "Esc to clear" not in rendered
assert "╭─" in rendered
assert "╰" in rendered
def test_numbered_search_keeps_original_indexes(monkeypatch) -> None:
prompts = iter(["draft", "1"])
monkeypatch.setattr(