Bounded cache of candidate sets from previous DB loads. Backspacing (or
re-typing) a query restores a previous set by moving it out of the cache
instead of re-scanning the table, which costs ~100ms at 500k rows.
The pure recall UI state machine: entries, cache, query, selection,
scroll, keymaps, and frame rendering โ everything except the terminal
itself. Constructible without a tty, so key handling, scroll math, cache
coverage, and drawing (into any Write) are all unit-testable.
The terminal adapter: raw mode, /dev/tty, keyboard enhancement, and the
restore-exactly-once guard. The only piece of recall that needs a real
terminal; everything behind it renders to a plain Write.
Highlight a command using pre-computed match indices from fuzzy matching.
Returns spans with (text, is_highlight) pairs.
Terminal columns a character occupies: 2 for East Asian wide, 0 for
combining marks and controls.
Deduplicate history entries by command string, keeping the most recent occurrence.
Entries are already sorted by timestamp (most recent first), so we keep the first
occurrence of each command, accumulating the number of collapsed duplicates in
its use_count for the frequency component of scoring. Trailing whitespace is
ignored for dedup since โdf -hโ and โdf -h โ are visually identical and
semantically the same.
Switch the terminal into recall mode: alternate screen, hidden cursor,
and (off Windows) the kitty keyboard protocol for instant Escape.
Returns whether keyboard enhancement was requested, for the matching pop.
Sanitize a string for safe terminal display by removing ANSI escape sequences
and control characters that could affect cursor position or terminal state.