diff options
| author | Stefan Boberg <[email protected]> | 2026-03-30 18:01:54 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2026-03-30 18:01:54 +0200 |
| commit | af493983078cfa1b4f0e6cd20bb49ee57abf6ab7 (patch) | |
| tree | a1f083a49e48d49fbb10ab58eb36d7e207f4cde7 /src/zenutil/consoletui.cpp | |
| parent | Show global options and subcommands in help command pages (diff) | |
| download | zen-af493983078cfa1b4f0e6cd20bb49ee57abf6ab7.tar.xz zen-af493983078cfa1b4f0e6cd20bb49ee57abf6ab7.zip | |
Simplify pager search to inline incremental mode
- Remove separate '/' search mode — typing anywhere starts searching
- Search highlights and scrolls to matches live as you type
- Enter jumps to next match, Backspace edits query, Escape clears
- Remove 'q' quit shortcut since all keys are now search input
- Escape quits the pager when no search query is active
Diffstat (limited to 'src/zenutil/consoletui.cpp')
| -rw-r--r-- | src/zenutil/consoletui.cpp | 116 |
1 files changed, 49 insertions, 67 deletions
diff --git a/src/zenutil/consoletui.cpp b/src/zenutil/consoletui.cpp index 35c38e7b9..02488248d 100644 --- a/src/zenutil/consoletui.cpp +++ b/src/zenutil/consoletui.cpp @@ -825,7 +825,6 @@ TuiPager(std::string_view Title, const std::vector<std::string>& Lines) // Search state std::string SearchQuery; - bool SearchActive = false; // Currently typing a search query int32_t SearchMatchLine = -1; // Line of current match (-1 = none) bool SearchFailed = false; // True if last search found nothing bool SearchWrapped = false; // True if search wrapped around @@ -909,41 +908,43 @@ TuiPager(std::string_view Title, const std::vector<std::string>& Lines) TuiEraseLine(); printf("\033[7m"); // reverse video - if (SearchActive) + // Scroll percentage + if (TotalLines <= PageH) { - printf(" /%s", SearchQuery.c_str()); - TuiShowCursor(true); + printf(" (All)"); } - else if (SearchFailed) + else if (TopLine == 0) { - printf(" Pattern not found: %s", SearchQuery.c_str()); + printf(" (Top)"); } - else if (SearchWrapped) + else if (TopLine + PageH >= TotalLines) { - printf(" Search wrapped: %s", SearchQuery.c_str()); + printf(" (End)"); } else { - // Scroll percentage - if (TotalLines <= PageH) - { - printf(" (All)"); - } - else if (TopLine == 0) + uint32_t Pct = (TopLine * 100) / (TotalLines - PageH); + printf(" (%u%%)", Pct); + } + + if (!SearchQuery.empty()) + { + if (SearchFailed) { - printf(" (Top)"); + printf(" \033[0;7;31mno match:\033[0;7m %s", SearchQuery.c_str()); } - else if (TopLine + PageH >= TotalLines) + else if (SearchWrapped) { - printf(" (End)"); + printf(" search (wrapped): %s", SearchQuery.c_str()); } else { - uint32_t Pct = (TopLine * 100) / (TotalLines - PageH); - printf(" (%u%%)", Pct); + printf(" search: %s", SearchQuery.c_str()); } - - printf(" q:quit /:search n:next"); + } + else + { + printf(" Esc:quit Type to search Enter:next match"); } printf("\033[0m"); @@ -1005,39 +1006,6 @@ TuiPager(std::string_view Title, const std::vector<std::string>& Lines) { ConsoleKey Key = TuiReadKey(); - if (SearchActive) - { - // In search input mode - switch (Key) - { - case ConsoleKey::Enter: - SearchActive = false; - TuiShowCursor(false); - FindNext(TopLine, true); - break; - case ConsoleKey::Escape: - SearchActive = false; - SearchFailed = false; - SearchMatchLine = -1; - TuiShowCursor(false); - break; - case ConsoleKey::Backspace: - if (!SearchQuery.empty()) - { - SearchQuery.pop_back(); - } - break; - case ConsoleKey::Char: - SearchQuery += TuiReadKeyChar(); - break; - default: - break; - } - Render(); - continue; - } - - // Normal navigation mode SearchFailed = false; SearchWrapped = false; @@ -1087,29 +1055,43 @@ TuiPager(std::string_view Title, const std::vector<std::string>& Lines) break; case ConsoleKey::Char: + SearchQuery += TuiReadKeyChar(); + FindNext(TopLine, true); + break; + + case ConsoleKey::Backspace: + if (!SearchQuery.empty()) { - char ch = TuiReadKeyChar(); - if (ch == 'q' || ch == 'Q') + SearchQuery.pop_back(); + if (!SearchQuery.empty()) { - Done = true; + FindNext(TopLine, true); } - else if (ch == '/') + else { - SearchActive = true; - SearchQuery.clear(); SearchMatchLine = -1; } - else if (ch == 'n' || ch == 'N') - { - // Find next match - uint32_t Start = (SearchMatchLine >= 0) ? static_cast<uint32_t>(SearchMatchLine) + 1 : TopLine; - FindNext(Start, true); - } + } + break; + + case ConsoleKey::Enter: + { + // Jump to next match + uint32_t Start = (SearchMatchLine >= 0) ? static_cast<uint32_t>(SearchMatchLine) + 1 : TopLine; + FindNext(Start, true); break; } case ConsoleKey::Escape: - Done = true; + if (!SearchQuery.empty()) + { + SearchQuery.clear(); + SearchMatchLine = -1; + } + else + { + Done = true; + } break; case ConsoleKey::Resize: |