Commit graph

68 commits

Author SHA1 Message Date
Sviatoslav Abakumov
9090268b7d
fix(tui): rewrite word wrap as single-pass with backtracking 2026-01-23 22:31:41 +04:00
Richard Gill
7dc652f304
Autocomplete allow searchs with /'s like: folder1/folder2 (#882)
* Extend fd autocomplete tests

* Renamed fixture type in autocomplete test
2026-01-21 23:23:51 +01:00
Michael Renner
620239bd3f
fix(tui): prevent duplicate URL display for autolinked emails (#888)
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.
2026-01-21 23:20:00 +01:00
Armin Ronacher
d37b5a52d7
More fuzzy finder (#860) 2026-01-19 22:22:51 +01:00
Sviatoslav Abakumov
fb1242829d feat(tui): add legacy terminal support for Ctrl+symbol keys
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+-.
2026-01-19 00:18:47 +01:00
Sviatoslav Abakumov
bacf334bc4 feat(tui): add undo support to Editor with the Ctrl+- hotkey
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.
2026-01-19 00:18:47 +01:00
Sviatoslav Abakumov
505894f4ea feat(tui): add Alt+D to delete word forward (kill)
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.
2026-01-17 21:11:20 +01:00
Sviatoslav Abakumov
9fb7434a06 feat(tui): implement Emacs-style kill ring for Editor
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
2026-01-17 21:11:20 +01:00
Sviatoslav Abakumov
bafddc27ed feat(tui): add legacy Alt+letter key sequence support
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.
2026-01-17 21:11:20 +01:00
Mario Zechner
356a482527 fix(tui): add vertical scrolling to Editor when content exceeds terminal height
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
2026-01-16 04:12:21 +01:00
Mario Zechner
be26d362fa Fix alt+backspace in Kitty mode and clamp Codex effort (refs #752) 2026-01-16 01:30:46 +01:00
Richard Gill
ce7e73b503
Centralize frontmatter parsing + parse frontmatter with yaml library (#728)
* Add frontmatter utility and tidy coding agent prompts

* Add frontmatter parsing utilities and tests

* Parse frontmatter with YAML parser

* Simplify frontmatter parsing utilities

* strip body in 1 place

* Improve frontmatter parsing error handling

* Normalize multiline skill and select-list descriptions
2026-01-16 00:31:53 +01:00
Richard Gill
131f1a25f3
Expand keymap coverage and add key tests (#752) 2026-01-16 00:21:37 +01:00
Danila Poyarkov
15a9670db5
fix: keyboard shortcuts on non-Latin keyboard layouts (#718) 2026-01-14 10:28:58 +01:00
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
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
Ogulcan Celik
a5441706f3 fix(tui): numbered list items showing "1." when code blocks break list continuity 2026-01-12 17:09:51 +01:00
Mario Zechner
da6a2fb5ea test(tui): cover style reset cases 2026-01-11 19:01:16 +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
Mario Zechner
178a3a563f fix(tui): handle split Shift+Enter in VS Code 2026-01-11 04:03:42 +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
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
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
robinwander
786a326a71 fix(tui): trim trailing whitespace in wrapped lines to prevent width overflow 2026-01-04 22:15:25 -06: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
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
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
Ahmed Kamal
0427445242
Fix Ctrl+W to use standard readline word deletion behavior (#306)
- 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
2025-12-25 04:09:47 +01:00
Mario Zechner
d5fd685901 Enable more biome lints and fix things 2025-12-21 22:56:20 +01:00
Mario Zechner
65c292b7dd Fix outdated editor tests for grapheme-aware cursor movement 2025-12-19 21:41:28 +01:00
Ahmed Kamal
4a4531f887 Add Kitty keyboard protocol support for Shift+Enter and other modifier keys
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
2025-12-18 19:20:30 +02:00
Ahmed Kamal
c1113deea9
Fix markdown tables overflowing/wrapping in TUI (width-aware rendering) (#206)
Fix markdown tables overflowing/wrapping in TUI
2025-12-17 17:13:27 +01:00
Markus Ylisiurunen
4b04c87b3d
add new getCursor and getLines methods to editor (#201) 2025-12-16 20:13:43 +01:00
Markus Ylisiurunen
92577316e0
Fix double new line issues in markdown rendering (#199)
* prevent double blank lines after markdown elements

* prevent double blank lines after markdown elements
2025-12-16 00:25:06 +01:00
Nico Bailon
f603a377ae add PI_NO_IMAGES env var to disable inline image rendering 2025-12-12 19:35:54 -08:00
Markus Ylisiurunen
db886746b4
prevent double blank lines after markdown code blocks (#173) 2025-12-13 02:04:49 +01:00
Mario Zechner
d7f84469a7 Fix editor crash with wide characters (emojis, CJK)
Editor text wrapping now uses grapheme-aware width calculation instead
of string length. Fixes crash when pasting text containing emojis like
 or CJK characters that are 2 terminal columns wide.
2025-12-06 21:24:26 +01:00
Mario Zechner
ee83284dcf Fix wrap-ansi test to use node:test instead of vitest 2025-12-06 00:48:46 +01:00
Mario Zechner
30dd31d787 Merge feat/scroll-previous-prompts with history load on resume 2025-12-05 22:02:16 +01:00
Mario Zechner
6ec1391ebb fix: escape codes not properly wrapped during line wrapping
- ANSI codes now attach to next visible content, not trailing whitespace
- Rewrote AnsiCodeTracker to track individual attributes
- Line-end resets only turn off underline, preserving background colors
- Added vitest config to exclude node:test files

fixes #109
2025-12-05 21:49:44 +01:00
Nico Bailon
c550ed2bca feat(tui): add prompt history navigation with Up/Down arrows
Browse previously submitted prompts using Up/Down arrow keys, similar to
shell history and Claude Code's prompt history feature.

- Up arrow when editor is empty: browse to older prompts
- Down arrow when browsing: return to newer prompts or clear editor
- Cursor movement within multi-line history entries supported
- History is session-scoped, stores up to 100 entries
- Consecutive duplicates are not added to history

Includes 15 new tests for history navigation behavior.
2025-12-05 07:57:42 -08:00
Peter Steinberger
c43f1d307c Add CI workflow and fix workspace tests 2025-12-02 12:53:53 +00:00
Mario Zechner
85adcf22bf Release v0.8.0 2025-11-21 03:12:42 +01:00
Mario Zechner
b3d4478b61 Release v0.7.23 2025-11-20 11:59:17 +01:00
Mario Zechner
1b28780155 Release v0.7.21 2025-11-19 00:56:16 +01:00
Mario Zechner
22d8a0ae4a Release v0.7.18 2025-11-18 22:08:44 +01:00
Mario Rodler
b37d601317 test(editor): Simplify and refine Unicode handling tests for clarity and consistency 2025-11-16 21:05:49 +01:00