- Add height change detection (analogous to existing width detection)
- Auto-detect when content shrinks below maxLinesRendered and trigger
full re-render to clear leftover empty rows
- Only triggers when no overlays are active (overlays need padding)
Fixes empty rows appearing below footer when:
- Closing /tree or other selectors
- Clearing multi-line editor content
- Any component shrinking
Also adds regression tests for resize handling and content shrinkage.
Added comprehensive bug regression test that demonstrates:
1. The bug scenario (old implementation using startsWith() fails)
2. The fix works (new implementation using includes() passes)
Test covers:
- Terminal without image support scenario (bug trigger)
- Both Kitty and iTerm2 image protocols
- Very long lines (300KB+) matching crash scenario
- Integration with tool execution scenarios
- Negative cases (no false positives)
All 347 tests pass including 12 new bug regression tests.
Changed isImageLine() from using startsWith() to includes() to detect
Kitty and iTerm2 image escape sequences anywhere in a line, not just
at the start. This prevents TUI width checks from failing on lines
containing image data, which could cause crashes when rendering tool
results with images (e.g., when reading image files).
Also added comprehensive test coverage for isImageLine() including:
- Both iTerm2 and Kitty protocols
- Regression tests for long lines and terminals without image support
- Negative cases to ensure no false positives
Fixes crash: 'Rendered line exceeds terminal width' when image
escape sequences appear in output.
* fix(tui): blockquote multiline rendering and wrapping
Fix two bugs in blockquote rendering:
1. ANSI codes split incorrectly on newlines - when text tokens contain
newlines, applyDefaultStyle() wrapped the entire string including the
newline in ANSI codes. Any caller splitting by \n would break the codes.
Fixed by splitting text by newlines before styling in renderInlineTokens().
2. Wrapped blockquote lines lost the │ border - long blockquote lines
that wrapped to multiple lines only had the border on the first line.
Fixed by wrapping within the blockquote case and adding border to each line.
* test(tui): add test for inline formatting inside blockquotes
Add Bash/Readline-style character search:
- Ctrl+] enters forward jump mode, awaits next character, jumps to it
- Ctrl+Alt+] does the same but searches backward
- Multi-line search
- Case-sensitive matching
- Pressing the hotkey again cancels; control chars cancel and fall
through
* fix(tui): keep file suggestions open when typing in Tab-triggered mode
Previously, pressing Tab on an empty prompt or after a space would show
file suggestions, but typing a letter would dismiss them because the
text didn't look like a path pattern. Now the editor tracks whether
autocomplete was triggered via Tab (force mode) or naturally (regular
mode), and uses the appropriate suggestion method when updating.
* fix(tui): hide autocomplete when backspacing slash command to empty
Previously, typing / showed slash command suggestions, but pressing
Backspace to delete it showed file suggestions instead of hiding all
suggestions.
Instead of buffering `\` and waiting for the next key, let it be
inserted immediately. On Enter, check if preceded by `\` and treat as
newline.
Removed backslash handling from the Input component entirely.
When Tab triggers file autocomplete and there's exactly one matching
suggestion, apply it immediately without showing the menu. This makes
path completion faster by eliminating the extra Tab press to confirm.
Appended lines were not committed to terminal scrollback because the
renderer used cursor movement (CSI B) and carriage return without
linefeed. This caused earlier content to be overwritten when the
viewport filled up.
Changes:
- For appended lines, emit \r\n to create real scrollback lines
- When target row is below viewport, scroll with \r\n before positioning
- Add PI_TUI_WRITE_LOG env var for debugging raw ANSI output
- Add fullRedraws readonly property to TUI class
- Add viewport-overwrite-repro.ts test script
fixes#954
Add insertTextAtCursorInternal() to properly handle newlines by splitting
lines at the cursor position.
- Normalize line endings (CRLF/CR to LF)
- Handle single-line and multi-line insertion
- Position cursor at end of inserted text
- Call onChange only once at the end
Refactor handlePaste() to use insertTextAtCursorInternal() for
multi-line pastes, while retaining character-by-character insertion for
single-line pastes to preserve autocomplete triggering.
Autolinked emails like user@example.com were rendered as
'user@example.com (mailto:user@example.com)' because the comparison
token.text === token.href failed (text lacks mailto: prefix).
Now strips mailto: prefix before comparing, so autolinked emails
display without redundant URL in parentheses.
Ctrl+\ sends ASCII 28 (File Separator) in legacy terminals. This is
commonly used as SIGQUIT in Unix.
Ctrl+] sends ASCII 29 (Group Separator) in legacy terminals. This is
commonly used as the telnet escape character.
Ctrl+_ sends ASCII 31 (Unit Separator) in legacy terminals. On US
keyboards, - and _ are on the same physical key, so this also functions
as an alias for Ctrl+-.
Undo snapshots are captured for all edit operations:
- Word insertion, backspace, forward delete
- Word/line deletion (Ctrl+W, Ctrl+U, Ctrl+K, Alt+D)
- Yank/yank-pop, paste, autocomplete completion
- Cursor movement starts a new undo unit
- setText() pushes snapshot when content changes
Additionally, history browsing captures the undo state on first entry.
Adds deleteWordForward action bound to Alt+D, which deletes from cursor
to the end of the current word and saves to kill ring for later yanking.
Consecutive forward kills append to the same kill ring entry.
Add kill ring functionality with:
- Ctrl+W/U/K save deleted text to kill ring
- Ctrl+Y yanks (pastes) most recent deletion
- Alt+Y cycles through kill ring (after Ctrl+Y)
- Consecutive deletions accumulate into single entry
In legacy terminal mode (non-Kitty protocol), Alt+key is sent as ESC
followed by the key character. This was only supported for specific keys
(space, backspace, arrows) but not for regular letters.
Add support for Alt+letter sequences to enable keybindings like Alt+Y.
The Editor component now accepts TUI as the first constructor parameter,
enabling it to query terminal dimensions. When content exceeds available
height, the editor scrolls vertically keeping the cursor visible.
Features:
- Max editor height is 30% of terminal rows (minimum 5 lines)
- Page Up/Down keys scroll by page size
- Scroll indicators show lines above/below: ─── ↑ 5 more ───
Breaking change: Editor constructor signature changed from
new Editor(theme)
to
new Editor(tui, theme)
fixes#732
Add OverlayOptions for configurable positioning (anchor, margins, offsets,
percentages). Add OverlayHandle for programmatic visibility control with
hide/setHidden/isHidden. Add visible callback for responsive overlays.
Extension API: ctx.ui.custom() now accepts overlayOptions and onHandle callback.
Examples: overlay-qa-tests.ts (10 test commands), doom-overlay (DOOM at 35 FPS).
- Skills registered as /skill:name commands for quick access
- Toggle via /settings or skills.enableSkillCommands in settings.json
- Fuzzy matching for all slash command autocomplete (type /skbra for /skill:brave-search)
- Moved fuzzy module from coding-agent to tui package for reuse
Closes#630 by @Dwsy (reimplemented with fixes)
Adds StdinBuffer class (adapted from OpenTUI, MIT license) to split
batched stdin into individual sequences before they reach components.
This fixes key presses being dropped when batched with release events,
which commonly occurs over SSH due to network buffering.
- Each handleInput() call now receives a single event
- matchesKey() and isKeyRelease() work correctly without batching awareness
- Properly buffers incomplete escape sequences across chunks
- Handles bracketed paste mode
Addresses #538
Add setTitle() method to Terminal interface for setting window title.
Uses standard OSC escape sequence \x1b]0;...\x07 for broad terminal
compatibility (macOS Terminal, iTerm2, Kitty, WezTerm, Ghostty, etc.).
Changes:
- Add setTitle(title: string) to Terminal interface
- Implement in ProcessTerminal using OSC sequence
- Implement no-op in VirtualTerminal for testing
- Use in interactive mode to set title as "pi - <dirname>"
Previously, the Editor component used character-level (grapheme-level)
wrapping, which broke words mid-character at line boundaries. This
created an ugly visual experience when typing or pasting long text.
Now the Editor uses word-aware wrapping:
- Wraps at word boundaries when possible
- Falls back to character-level wrapping for tokens wider than the
available width (e.g., long URLs)
- Strips leading whitespace at line starts
- Preserves multiple spaces within lines
Added wordWrapLine() helper function that tokenizes text into words
and whitespace runs, then builds chunks that fit within the specified
width while respecting word boundaries.
Also updated buildVisualLineMap() to use the same word wrapping logic
for consistent cursor navigation.
Added tests for:
- Word boundary wrapping
- Leading whitespace stripping
- Long token (URL) character-level fallback
- Multiple space preservation
- Edge cases (empty string, exact fit)
- Skip trailing whitespace before deleting word (readline behavior)
- Make word navigation grapheme-aware using Intl.Segmenter
- Add Ctrl+Left/Right and Alt+Left/Right word navigation to Input
- Accept full Unicode input while rejecting control characters (C0/C1/DEL)
- Extract shared utilities to utils.ts (getSegmenter, isWhitespaceChar, isPunctuationChar)
- Fix unsafe cast in Editor.forceFileAutocomplete with runtime type check
- Add comprehensive tests for word deletion and navigation
Enable the Kitty keyboard protocol on terminal start to receive enhanced
key sequences that include modifier information. This fixes Shift+Enter
not working in Ghostty, Kitty, WezTerm, and other modern terminals.
Changes:
- Enable Kitty protocol on start (\x1b[>1u), disable on stop (\x1b[<u)
- Add centralized key definitions in packages/tui/src/keys.ts
- Support both legacy and Kitty sequences for all modifier+key combos:
- Shift+Enter, Alt+Enter for newlines
- Shift+Tab for thinking level cycling
- Ctrl+C, Ctrl+A, Ctrl+E, Ctrl+K, Ctrl+U, Ctrl+W, Ctrl+O, Ctrl+P, Ctrl+T
- Alt+Backspace for word deletion
- Export Keys constants and helper functions from @mariozechner/pi-tui