Commit graph

163 commits

Author SHA1 Message Date
Nico Bailon
a4ccff382c feat(tui): overlay positioning API with CSS-like values
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).
2026-01-12 22:44:58 -08:00
Nico Bailon
d29f268f46 feat(tui): add pad parameter to truncateToWidth, overlay QA tests 2026-01-12 10:01:53 -08:00
Nico Bailon
0c0aac6599 feat(tui): add OverlayOptions API and fix width overflow crash
Adds positioning/sizing options for overlays and fixes crash when compositing
lines with complex ANSI sequences exceed terminal width.
2026-01-12 10:01:34 -08:00
ninlds
ec2b7b5a00 Add fuzzy search to settings list 2026-01-12 18:10:33 +01:00
Ogulcan Celik
a5441706f3 fix(tui): numbered list items showing "1." when code blocks break list continuity 2026-01-12 17:09:51 +01:00
Aliou Diallo
638fbc459b
feat(coding-agent): add page-up/down navigation to session selector (#662)
* feat(tui): add pageUp/pageDown key support and selectPageUp/selectPageDown actions

* feat(coding-agent): add page-up/down navigation to session selector
2026-01-12 17:01:46 +01:00
Mario Zechner
c07126c0fd fix(tui): remove Kitty protocol query timeout
The 100ms timeout was causing Kitty protocol detection to fail when the
terminal response was delayed (e.g., due to event loop blocking during
startup). This resulted in shift+enter not working in some scenarios.

Changes:
- Remove timeout-based Kitty detection, process input immediately
- Detect Kitty response in stdinBuffer output (handles split data)
- Add modifyOtherKeys fallback for terminals without Kitty support
  (matches xterm format \x1b[27;modifier;keycode~)
2026-01-11 22:51:30 +01:00
Mario Zechner
6d495348c5 fix(tui): reset styles per line 2026-01-11 18:36:48 +01:00
Mario Zechner
9655907624 feat: Add skill slash commands and fuzzy matching for all commands
- 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)
2026-01-11 17:56:11 +01:00
Jian Zhang
b57eafaadb fix(tui): ensure cursor moves to end of content on exit to prevent visual artifacts 2026-01-11 17:25:26 +01:00
Mario Zechner
178a3a563f fix(tui): handle split Shift+Enter in VS Code 2026-01-11 04:03:42 +01:00
Ogulcan Celik
eb15f326c1 fix(tui): skip key release/repeat check for bracketed paste content
Pasted content containing Kitty key release patterns (e.g., :3F in bluetooth
MAC addresses) was incorrectly detected as a key release event and dropped.

The fix checks for bracketed paste markers before running pattern checks.
Also applied to isKeyRepeat() for consistency.

Closes #623
2026-01-11 03:14:59 +01:00
Ogulcan Celik
df3a220d6b fix(tui): reduce flicker by only re-rendering changed lines (#617) 2026-01-11 03:02:35 +01:00
Mario Zechner
3bb115a39c fix(tui): cursor position tracking when content shrinks with unchanged lines 2026-01-11 03:00:23 +01:00
Mario Zechner
d7394eb109 Fix TUI rendering with wrong dimensions after suspend/resume
- Send SIGWINCH to self on terminal start to refresh stale dimensions (Unix only)
- Change requestRender(true) to set previousWidth = -1 to trigger widthChanged
- Update first render condition to skip when widthChanged is true

Fixes #599
2026-01-11 02:47:28 +01:00
Mario Zechner
f9064c2f69 feat(tui): add overlay compositing for ctx.ui.custom() (#558)
Adds overlay rendering capability to the TUI, enabling floating modal
components that render on top of existing content without clearing the screen.

- Add showOverlay(), hideOverlay(), hasOverlay() methods to TUI
- Implement ANSI-aware line compositing via extractSegments()
- Support overlay stack (multiple overlays, later on top)
- Add { overlay: true } option to ctx.ui.custom()
- Add overlay-test.ts example extension

Also fixes pre-existing bug where bash tool output cached visual lines
at fixed terminal width, causing crashes on terminal resize.

Co-authored-by: Nico Bailon <nico.bailon@gmail.com>
2026-01-08 22:40:42 +01:00
Mario Zechner
f3b7b0b179 fix(tui): handle batched input over SSH with StdinBuffer
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
2026-01-07 17:50:06 +01:00
Mario Zechner
09471ebc7d feat(coding-agent): add ctx.ui.setEditorComponent() extension API
- Add setEditorComponent() to ctx.ui for custom editor components
- Add CustomEditor base class for extensions (handles app keybindings)
- Add keybindings parameter to ctx.ui.custom() factory (breaking change)
- Add modal-editor.ts example (vim-like modes)
- Add rainbow-editor.ts example (animated text highlighting)
- Update docs: extensions.md, tui.md Pattern 7
- Clean up terminal on TUI render errors
2026-01-07 16:11:49 +01:00
Mario Zechner
41fe329cdd fix(tui): filter key release events by default
Components must set wantsKeyRelease=true to receive release events.
Fixes double-processing of keys in editors when Kitty protocol flag 2 is enabled.
2026-01-07 01:31:24 +01:00
Mario Zechner
7a44cf0db0 fix(tui): matchesKey now matches Kitty sequences for unmodified letter keys
Needed for key release events which come as CSI sequences even for plain letters.
2026-01-07 00:57:10 +01:00
Mario Zechner
a2f032a426 feat(tui): add Kitty keyboard protocol flag 2 support for key release events
- Enable flag 2 in Kitty protocol for event type reporting
- Add isKeyRelease() and isKeyRepeat() functions
- Parse event type suffix (:1/:2/:3) in Kitty sequences
- Export KeyEventType type
2026-01-07 00:41:44 +01:00
Mario Zechner
4d87196801 fix(tui): remove alt+enter from newLine default keybinding
alt+enter is used by coding-agent for follow-up messages.
Having it also mapped to newLine caused a conflict.
2026-01-05 23:17:34 +01:00
Mario Zechner
c5d54a8413 feat(tui): query Kitty keyboard protocol support before enabling
- Query terminal with CSI ? u before enabling Kitty protocol
- Only enable protocol if terminal responds (100ms timeout)
- Mode-aware key parsing: when Kitty active, interpret legacy
  sequences as custom terminal mappings (e.g. \x1b\r = shift+enter)
- Add Terminal Setup section to README with Ghostty/wezterm config

fixes #439
2026-01-05 22:52:13 +01:00
Mario Zechner
9b12719ab1 Improve OAuth login UI with consistent dialog component
- Add LoginDialogComponent with proper borders (top/bottom DynamicBorder)
- Refactor all OAuth providers to use racing approach (browser callback vs manual paste)
- Add onEscape handler to Input component for cancellation
- Add abortable sleep for GitHub Copilot polling (instant cancel on Escape)
- Show OS-specific click hint (Cmd+click on macOS, Ctrl+click elsewhere)
- Clear content between login phases (fixes GitHub Copilot two-phase flow)
- Use InteractiveMode's showStatus/showError for result messages
- Reorder providers: Anthropic, ChatGPT, GitHub Copilot, Gemini CLI, Antigravity
2026-01-05 19:58:44 +01:00
robinwander
786a326a71 fix(tui): trim trailing whitespace in wrapped lines to prevent width overflow 2026-01-04 22:15:25 -06:00
Kao Félix
b836a9d2ee
feat(tui): add symbol key support to keybinding system (#450)
- Added SymbolKey type with 32 symbol keys
- Added symbol key constants to Key helper (Key.backtick, Key.comma, Key.period, etc.)
- Updated matchesKey() and parseKey() to handle symbol key input
- Added documentation in coding-agent README with examples
2026-01-04 20:37:08 +01:00
Helmut Januschka
e3c2616713 fix(tui): add legacy terminal support for shift+letter shortcuts
In legacy terminals, Shift+P produces uppercase 'P' instead of
Kitty protocol sequences. Add fallback to check uppercase letters
for shift+letter combinations.
2026-01-04 18:13:29 +01:00
Aliou Diallo
0d477d39f9
fix(tui): expand paste markers when opening external editor (#444)
* fix(tui): expand paste markers when opening external editor

Add getExpandedText() method to Editor that substitutes paste markers
with actual content. Use it in Ctrl-G external editor flow so users
see full pasted content instead of [paste #N ...] placeholders.

* docs: add changelog entries for #444
2026-01-04 18:11:42 +01:00
Mario Zechner
5c5084481b feat(coding-agent): clipboard image paste support via Ctrl+V (fixes #419) 2026-01-04 01:05:22 +01:00
Mario Zechner
f2b89d5ec5 Merge branch 'feat/ctrl-n-external-editor' - configurable keybindings (#405) 2026-01-03 22:51:12 +01:00
Helmut Januschka
38b7f21e01 feat: add type-safe KeyId for matchesKey function
- Add KeyId union type covering all valid key combinations
- Add Key helper object for autocomplete (Key.ctrl('c'), Key.escape, etc.)
- Update matchesKey signature to use KeyId instead of string
- Catches typos like 'esacpe' at compile time
2026-01-03 16:03:35 +01:00
Mario Zechner
69a8ecd5b3 fix: slash command autocomplete triggers for . - _ prefixes
fixes #422
2026-01-03 15:44:36 +01:00
Helmut Januschka
2bd7b79a9b fix: selectCancel should include both escape and ctrl+c 2026-01-03 08:23:56 +01:00
Helmut Januschka
7574fed2f2 feat: use keybindings in all selectors and lists
Update all selector/list components to use EditorKeybindingsManager:
- model-selector, session-selector, oauth-selector, user-message-selector
- hook-selector, hook-input, hook-editor, tree-selector
- select-list, settings-list, cancellable-loader

This allows users to configure selectUp, selectDown, selectConfirm,
selectCancel actions in keybindings.json
2026-01-03 08:23:56 +01:00
Helmut Januschka
8f2682578b feat: configurable keybindings for all editor and app actions
All keybindings configurable via ~/.pi/agent/keybindings.json

Editor actions:
- cursorUp, cursorDown, cursorLeft, cursorRight
- cursorWordLeft, cursorWordRight, cursorLineStart, cursorLineEnd
- deleteCharBackward, deleteCharForward, deleteWordBackward
- deleteToLineStart, deleteToLineEnd
- newLine, submit, tab
- selectUp, selectDown, selectConfirm, selectCancel

App actions:
- interrupt, clear, exit, suspend
- cycleThinkingLevel, cycleModelForward, cycleModelBackward
- selectModel, expandTools, toggleThinking, externalEditor

Also adds support for numpad Enter key (Kitty protocol codepoint 57414
and SS3 M sequence)

Example emacs-style keybindings.json:
{
  "cursorUp": ["up", "ctrl+p"],
  "cursorDown": ["down", "ctrl+n"],
  "cursorLeft": ["left", "ctrl+b"],
  "cursorRight": ["right", "ctrl+f"],
  "deleteCharForward": ["delete", "ctrl+d"],
  "cycleModelForward": "ctrl+o"
}
2026-01-03 08:23:56 +01:00
Mario Zechner
2b054cdb7c Merge PR #382: word wrapping in Editor component 2026-01-03 00:48:28 +01:00
Mario Zechner
e1b0b37ba4 tui: wrap settings descriptions instead of truncating 2026-01-03 00:45:28 +01:00
Mario Zechner
3506ac81f2
Merge pull request #411 from nathyong/feature/shift-backspace
tui: fix shift+space/backspace/delete on kitty-protocol terminals
2026-01-03 00:28:58 +01:00
Kao Félix
5c3c8e6f7e
Add terminal title support to TUI framework (#407)
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>"
2026-01-02 22:00:34 +01:00
nathyong
c9b08d7643 tui: fix shift+space/backspace/delete on kitty-protocol terminals
Kitty and other smart terminals send a specific CSI u control code for
these shifted special keys, which are interpreted as a no-op by the
editor component. These should send the underlying key instead, matching
the behaviour of other TUI programs (e.g. readline, vim insert mode).

On less smart terminals, these key combinations are the same as the
non-shifted versions, and so already work with the existing code.
2026-01-03 06:58:56 +11:00
cursive
d97a96493c
fix(tui): Strip OSC 8 hyperlink sequences in visibleWidth (#396) 2026-01-02 10:32:36 +01:00
nathyong
6e4270a286 tui: only check for emojis in visibleWidth when necessary
The initial render of a session, and any re-draws caused by terminal
resizing are noticeably slow, especially on conversations with 20+
turns and many tool calls.

From profiling with `bun --cpu-prof` (available since bun 1.3.2), the
majority of the rendering (90%) is spent on detection of emojis in the
string-width library, running the expensive `/\p{RGI_Emoji}$/v`
regular expression on every individual grapheme cluster in the entire
scrollback. I believe it essentially expands to a fixed search against
every possible emoji sequence, hence the amount of CPU time spent in it.

This change replaces the `stringWidth` from string-width with a
`graphemeWidth` function that performs a similar check, but avoids
running the `/\p{RGI_Emoji}$/v` regex for emoji detection unless it
contains codepoints that could be emojis.

The `visibleWidth` function also has two more optimisations:
- Short-circuits string length detection for strings that are entirely
  printable ASCII characters
- Adds a cache for non-ASCII segments to avoid recomputing string length
  when resizing
2026-01-02 01:56:11 +01:00
Mario Zechner
1d9fa13d58 Fix crash on Unicode format characters in visibleWidth
Strip all Unicode format characters (category Cf) before passing to
string-width. These are invisible control characters that crash
string-width but have no visible width anyway.

Closes #390
2026-01-01 22:33:09 +01:00
Mr. Rc
bbf23bd5f1
Fix characters (#372)
* Fix cat command

* Fix text rendering crash from undefined code points in bash output

* Revert unintentional model parameter changes from fix cat command commit
2026-01-01 02:16:29 +01:00
Mario Zechner
6f7c10e323 Add setEditorText/getEditorText to hook UI context, improve custom() API
- Add setEditorText() and getEditorText() to HookUIContext for prompt generator pattern
- custom() now accepts async factories for fire-and-forget work
- Add CancellableLoader component to tui package
- Add BorderedLoader component for hooks with cancel UI
- Export HookAPI, HookContext, HookFactory from main package
- Update all examples to import from packages instead of relative paths
- Update hooks.md and custom-tools.md documentation

fixes #350
2026-01-01 00:04:56 +01:00
Nick Seelert
dde5f25170 feat(tui): implement word wrapping in Editor component
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)
2025-12-30 23:05:35 -05:00
Mario Zechner
71cbae6371 Export wrapTextWithAnsi utility and add handleInput docs
- Export wrapTextWithAnsi from tui package
- Add 'Handling Input' section to README with key detection example
- Document wrapTextWithAnsi in utilities section
2025-12-30 23:28:38 +01:00
Mario Zechner
e4df5d14b5 Tree selector improvements: active line highlight and tool filter
- Add inverse background highlight for selected/active line
- Add 'no-tools' filter mode to hide tool results
- Add isShiftCtrlO to cycle filters backwards
- Filter order: default → no-tools → user-only → labeled-only → all
2025-12-30 22:42:25 +01:00
Mario Zechner
9427211f99 fix(tui): render HTML tags as plain text in Markdown component
Handles both block-level and inline HTML tags that were previously
silently dropped.

fixes #359
2025-12-30 22:42:24 +01:00
Mario Zechner
544814875e Add global debug key (Shift+Ctrl+D), iterative tree sorting to avoid stack overflow 2025-12-30 22:42:22 +01:00