Skip to content

feat(gui): find in the terminal with ⌘F / Ctrl+Shift+F - #152

Open
sachin56 wants to merge 1 commit into
timhartmann7:mainfrom
sachin56:feat/gui-terminal-search
Open

sachin56 wants to merge 1 commit into
timhartmann7:mainfrom
sachin56:feat/gui-terminal-search

Conversation

@sachin56

@sachin56 sachin56 commented Oct 9, 2026 •

Copy link
Copy Markdown

Problem

The desktop terminal has no way to search its output. Finding an error in a long log or build output means scrolling the scrollback by eye.

Solution

A find bar over the terminal tab, using xterm's official search addon (@xterm/addon-search 0.16, the release that pairs with @xterm/xterm 6).

  • ⌘F on macOS, Ctrl+Shift+F on Windows and Linux. A bare Ctrl+F stays ^F for the shell (readline's forward-char, less).
  • Every match in the scrollback is highlighted and counted ("2 of 7", or "1000+" past the addon's highlight limit). Enter / Shift+Enter step through them.
  • Aa toggles case-sensitive matching, .* toggles regex. A pattern that doesn't compile shows "Invalid pattern".
  • A one-line selection pre-fills the query.
  • Highlights follow new output while the bar is open (the addon re-runs the search on onWriteParsed).
  • Esc closes the bar and returns the keyboard to the terminal. An open bar keeps focus across tab switches, dialogs and the palette, like the terminal itself does.
  • Works on a tab whose session has ended. Enter in the bar steps through matches and does not close that tab.
  • Match colours live in terminalTheme.ts beside the xterm theme, derived from --status-warn, and follow the theme toggle.

Two things a reviewer may want to know about:

  1. allowProposedApi: true is now set on the terminal. Highlighting uses registerDecoration, which xterm 6 still gates as proposed API. Without it, every search with highlights throws.
  2. Workaround for an addon bug. In addon-search 0.16, findNext stores the new options before shouldUpdateHighlighting compares them with the previous ones, so toggling case or regex (or the theme's colours) never re-highlights. The bar calls clearDecorations() when those change, which drops the addon's cached term and forces a fresh pass.

The current match shows as the terminal selection plus an outline rather than a solid fill. The addon also selects the match, and the selection is painted over the decoration. VS Code's terminal looks the same.

Changes

  • screens/TerminalFind.svelte: the find bar (new)
  • screens/terminalFind.ts: count label and selection seeding, kept pure for tests (new)
  • screens/terminalInput.ts: isFindShortcut, with the same non-Latin-layout physical-key handling as isCopyShortcut
  • screens/TerminalView.svelte: loads the addon, routes the shortcut, focus hand-off
  • theme/terminalTheme.ts: searchColours (the addon only accepts #RRGGBB, so the colours can't be CSS tokens)
  • CHANGELOG.md (Unreleased → Features), README.md (Real terminals)

No Rust changes.

Test plan

  • npm run check: 0 errors, 0 warnings
  • npm test: all pass, including new unit tests for isFindShortcut, the count label, selection seeding and the highlight colours
  • npx playwright test: all 141 pass. New e2e cases in e2e/terminal.spec.ts cover:
    • open, count, step, the case toggle, and Esc returning focus, with nothing written to the shell
    • "No results", invalid regex, and a valid regex
    • selection seeding, and re-pressing the shortcut while the bar is open
    • bare Ctrl+F still sending ^F
    • find on an ended session
    • ⌘F on macOS, where Ctrl+Shift+F is left alone
  • Manually in cargo tauri dev on macOS (Intel): ⌘F opens the bar, highlights and stepping work against a live SSH session
  • Not tried on Windows or Linux builds

The desktop terminal had no way to search its output. A find bar now
opens over the terminal tab and searches the scrollback through xterm's
search addon: every match is highlighted and counted, Enter and
Shift+Enter step through them, and Aa / .* toggle case and regex. A
one-line selection seeds the query, highlights follow new output, and
Esc hands the keyboard back to the shell.

Bare Ctrl+F still reaches the shell as ^F on Windows and Linux. Find
also works on a tab whose session has ended.

addon-search 0.16 records new options before comparing them with the
last ones, so a case/regex/theme change never re-highlights; the bar
drops the addon's cached query when they change. Match highlighting
uses registerDecoration, which xterm 6 still gates behind
allowProposedApi.
@sachin56
sachin56 force-pushed the feat/gui-terminal-search branch from 608dd1e to bf78743 Compare October 9, 2026 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant