@ashx-j/lunr-tui 0.2.38 → 0.2.40-dev.54.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +43 -17
  2. package/THIRD_PARTY_NOTICES +33 -0
  3. package/dist/components/editor.d.ts +2 -1
  4. package/dist/components/editor.d.ts.map +1 -1
  5. package/dist/components/editor.js +4 -2
  6. package/dist/components/editor.js.map +1 -1
  7. package/dist/components/select-list.d.ts.map +1 -1
  8. package/dist/components/select-list.js +14 -2
  9. package/dist/components/select-list.js.map +1 -1
  10. package/dist/components/settings-list.d.ts +18 -1
  11. package/dist/components/settings-list.d.ts.map +1 -1
  12. package/dist/components/settings-list.js +45 -5
  13. package/dist/components/settings-list.js.map +1 -1
  14. package/dist/editor-component.d.ts +2 -2
  15. package/dist/editor-component.d.ts.map +1 -1
  16. package/dist/editor-component.js.map +1 -1
  17. package/dist/index.d.ts +2 -2
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +2 -2
  20. package/dist/index.js.map +1 -1
  21. package/dist/keybindings.d.ts +2 -2
  22. package/dist/keybindings.d.ts.map +1 -1
  23. package/dist/keybindings.js +2 -2
  24. package/dist/keybindings.js.map +1 -1
  25. package/dist/keys.d.ts.map +1 -1
  26. package/dist/keys.js +7 -0
  27. package/dist/keys.js.map +1 -1
  28. package/dist/stdin-buffer.d.ts +8 -2
  29. package/dist/stdin-buffer.d.ts.map +1 -1
  30. package/dist/stdin-buffer.js +11 -5
  31. package/dist/stdin-buffer.js.map +1 -1
  32. package/dist/terminal.d.ts +16 -0
  33. package/dist/terminal.d.ts.map +1 -1
  34. package/dist/terminal.js +83 -21
  35. package/dist/terminal.js.map +1 -1
  36. package/dist/tui.d.ts +31 -2
  37. package/dist/tui.d.ts.map +1 -1
  38. package/dist/tui.js +103 -66
  39. package/dist/tui.js.map +1 -1
  40. package/dist/utils.d.ts.map +1 -1
  41. package/dist/utils.js +16 -2
  42. package/dist/utils.js.map +1 -1
  43. package/package.json +2 -2
package/README.md CHANGED
@@ -16,7 +16,7 @@ Minimal terminal UI framework with differential rendering and synchronized outpu
16
16
  ## Quick Start
17
17
 
18
18
  ```typescript
19
- import { TUI, Text, Editor, ProcessTerminal, matchesKey } from "@ashx-j/lunr-tui";
19
+ import { TUI, Text, Editor, ProcessTerminal, matchesKey, type EditorTheme } from "@ashx-j/lunr-tui";
20
20
 
21
21
  // Create terminal
22
22
  const terminal = new ProcessTerminal();
@@ -27,7 +27,18 @@ const tui = new TUI(terminal);
27
27
  // Add components
28
28
  tui.addChild(new Text("Welcome to my app!"));
29
29
 
30
- import { defaultEditorTheme as editorTheme } from './test/test-themes.ts';
30
+ // Minimal editor theme using plain ANSI codes
31
+ const dim = (s: string) => `\x1b[2m${s}\x1b[22m`;
32
+ const editorTheme: EditorTheme = {
33
+ borderColor: dim,
34
+ selectList: {
35
+ selectedPrefix: (s) => `\x1b[34m${s}\x1b[39m`,
36
+ selectedText: (s) => `\x1b[1m${s}\x1b[22m`,
37
+ description: dim,
38
+ scrollInfo: dim,
39
+ noMatch: dim,
40
+ },
41
+ };
31
42
  const editor = new Editor(tui, editorTheme);
32
43
  editor.onSubmit = (text) => {
33
44
  console.log("Submitted:", text);
@@ -155,16 +166,16 @@ interface Component {
155
166
  render(width: number): string[];
156
167
  handleInput?(data: string): void;
157
168
  handleClick?(localY: number, width: number, localX?: number): boolean;
158
- invalidate?(): void;
169
+ invalidate(): void;
159
170
  }
160
171
  ```
161
172
 
162
173
  | Method | Description |
163
174
  |--------|-------------|
164
- | `render(width)` | Returns an array of strings, one per line. Each line **must not exceed `width`** or the TUI will error. Use `truncateToWidth()` or manual wrapping to ensure this. |
175
+ | `render(width)` | Returns an array of strings, one per line. Each line **must not exceed `width`**. The TUI truncates lines that are too wide and writes a diagnostic log (`pi-crash.log` in `~/.lunr/agent`, or `$PI_CODING_AGENT_DIR` if set) on the first overflow. Use `truncateToWidth()` or manual wrapping to avoid this. |
165
176
  | `handleInput?(data)` | Called when the component has focus and receives keyboard input. The `data` string contains raw terminal input (may include ANSI escape sequences). |
166
177
  | `handleClick?(localY, width, localX?)` | Called for a click with zero-based coordinates inside the component. `localX` is optional for compatibility with row-only handlers. Return `true` when handled. |
167
- | `invalidate?()` | Called to clear any cached render state. Components should re-render from scratch on the next `render()` call. |
178
+ | `invalidate()` | Called to clear any cached render state. Components should re-render from scratch on the next `render()` call. |
168
179
 
169
180
  The TUI appends a full SGR reset and OSC 8 reset at the end of each rendered line. Styles do not carry across lines. If you emit multi-line text with styling, reapply styles per line or use `wrapTextWithAnsi()` so styles are preserved for each wrapped line.
170
181
 
@@ -475,12 +486,21 @@ interface SettingItem {
475
486
  currentValue: string;
476
487
  values?: string[]; // If provided, Enter/Space cycles through these
477
488
  submenu?: (currentValue: string, done: (selectedValue?: string) => void) => Component;
489
+ disabled?: () => boolean; // If it returns true, the row is dimmed and cannot be activated
490
+ searchTerms?: string[]; // Extra names that search matches besides the label
491
+ }
492
+
493
+ // Non-selectable heading that groups the rows after it. Mix sections into the rows array.
494
+ interface SettingSection {
495
+ kind: "section";
496
+ label?: string;
478
497
  }
479
498
 
480
499
  interface SettingsListTheme {
481
500
  label: (text: string, selected: boolean) => string;
482
501
  value: (text: string, selected: boolean) => string;
483
502
  description: (text: string) => string;
503
+ disabled: (text: string) => string;
484
504
  cursor: string;
485
505
  hint: (text: string) => string;
486
506
  }
@@ -493,7 +513,8 @@ const settings = new SettingsList(
493
513
  10, // maxVisible
494
514
  theme, // SettingsListTheme
495
515
  (id, newValue) => console.log(`${id} changed to ${newValue}`),
496
- () => console.log("Cancelled")
516
+ () => console.log("Cancelled"),
517
+ { enableSearch: true } // optional: fuzzy search by label
497
518
  );
498
519
  settings.updateValue("theme", "light");
499
520
  ```
@@ -513,7 +534,7 @@ const spacer = new Spacer(2); // 2 empty lines (default: 1)
513
534
 
514
535
  ### Image
515
536
 
516
- Renders images inline for terminals that support the Kitty graphics protocol (Kitty, Ghostty, WezTerm) or iTerm2 inline images. Falls back to a text placeholder on unsupported terminals.
537
+ Renders images inline for terminals that support the Kitty graphics protocol (Kitty, Ghostty, WezTerm, Warp) or iTerm2 inline images. Falls back to a text placeholder on unsupported terminals.
517
538
 
518
539
  ```typescript
519
540
  interface ImageTheme {
@@ -595,7 +616,7 @@ if (matchesKey(data, Key.enter)) {
595
616
  The TUI uses three rendering strategies:
596
617
 
597
618
  1. **First Render**: Output all lines without clearing scrollback
598
- 2. **Width Changed or Change Above Viewport**: Clear screen and full re-render
619
+ 2. **Width or Height Changed, or Change Above Viewport**: Clear screen and full re-render
599
620
  3. **Normal Update**: Move cursor to first changed line, clear to end, render changed lines
600
621
 
601
622
  All updates are wrapped in **synchronized output** (`\x1b[?2026h` ... `\x1b[?2026l`) for atomic, flicker-free rendering.
@@ -608,21 +629,24 @@ The TUI works with any object implementing the `Terminal` interface:
608
629
  interface Terminal {
609
630
  start(onInput: (data: string) => void, onResize: () => void): void;
610
631
  stop(): void;
632
+ drainInput(maxMs?: number, idleMs?: number): Promise<void>;
611
633
  write(data: string): void;
612
634
  get columns(): number;
613
635
  get rows(): number;
636
+ get kittyProtocolActive(): boolean;
614
637
  moveBy(lines: number): void;
615
638
  hideCursor(): void;
616
639
  showCursor(): void;
617
640
  clearLine(): void;
618
641
  clearFromCursor(): void;
619
642
  clearScreen(): void;
643
+ setTitle(title: string): void;
644
+ setProgress(active: boolean): void;
620
645
  }
621
646
  ```
622
647
 
623
- **Built-in implementations:**
648
+ **Built-in implementation:**
624
649
  - `ProcessTerminal` - Uses `process.stdin/stdout`
625
- - `VirtualTerminal` - For testing (uses `@xterm/headless`)
626
650
 
627
651
  ## Utilities
628
652
 
@@ -645,7 +669,7 @@ const lines = wrapTextWithAnsi("This is a long line that needs wrapping", 20);
645
669
 
646
670
  ## Creating Custom Components
647
671
 
648
- When creating custom components, **each line returned by `render()` must not exceed the `width` parameter**. The TUI will error if any line is wider than the terminal.
672
+ When creating custom components, **each line returned by `render()` must not exceed the `width` parameter**. The TUI truncates any line that is wider than the terminal and logs the first overflow.
649
673
 
650
674
  ### Handling Input
651
675
 
@@ -760,33 +784,35 @@ class CachedComponent implements Component {
760
784
 
761
785
  ## Example
762
786
 
763
- See `test/chat-simple.ts` for a complete chat interface example with:
787
+ From a repo checkout, see `packages/tui/test/chat-simple.ts` for a complete chat interface example with:
764
788
  - Markdown messages with custom background colors
765
789
  - Loading spinner during responses
766
790
  - Editor with autocomplete and slash commands
767
791
  - Spacers between messages
768
792
 
769
- Run it:
793
+ Run it from `packages/tui`:
770
794
  ```bash
771
795
  npx tsx test/chat-simple.ts
772
796
  ```
773
797
 
774
798
  ## Development
775
799
 
800
+ These commands need a repo checkout.
801
+
776
802
  ```bash
777
- # Install dependencies (from monorepo root)
803
+ # Install dependencies (from the monorepo root)
778
804
  npm install
779
805
 
780
- # Run type checking
806
+ # Run lint and repo checks (from the monorepo root)
781
807
  npm run check
782
808
 
783
- # Run the demo
809
+ # Run the demo (from packages/tui)
784
810
  npx tsx test/chat-simple.ts
785
811
  ```
786
812
 
787
813
  ### Debug logging
788
814
 
789
- Set `PI_TUI_WRITE_LOG` to capture the raw ANSI stream written to stdout.
815
+ Set `PI_TUI_WRITE_LOG` to capture the raw ANSI stream written to stdout. The example below needs a repo checkout, but the variable works with any app built on this package.
790
816
 
791
817
  ```bash
792
818
  PI_TUI_WRITE_LOG=/tmp/tui-ansi.log npx tsx test/chat-simple.ts
@@ -54,3 +54,36 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
54
54
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
55
55
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
56
56
  SOFTWARE.
57
+
58
+ Tree-sitter grammars
59
+ ====================
60
+
61
+ lunR ships compiled tree-sitter grammars in the npm package and beside the standalone binary.
62
+ Six of them are unchanged files from these npm packages (see
63
+ packages/coding-agent/src/builtin-extensions/pi-lsp-extension/src/tree-sitter/vendored-grammars):
64
+ tree-sitter-typescript 0.23.2 (typescript, tsx; Copyright (c) 2017 Max Brunsfeld),
65
+ tree-sitter-javascript 0.23.1 (Copyright (c) 2014 Max Brunsfeld), tree-sitter-bash 0.23.3
66
+ (Copyright (c) 2017 Max Brunsfeld), tree-sitter-cpp 0.23.4 (Copyright (c) 2014 Max Brunsfeld)
67
+ and @tree-sitter-grammars/tree-sitter-lua 0.2.0 (Copyright (c) 2021 Munif Tanjim). All five are
68
+ MIT licensed. The other grammars come from the tree-sitter-wasms package
69
+ (https://github.com/Gregoor/tree-sitter-wasms).
70
+
71
+ MIT License
72
+
73
+ Permission is hereby granted, free of charge, to any person obtaining a copy
74
+ of this software and associated documentation files (the "Software"), to deal
75
+ in the Software without restriction, including without limitation the rights
76
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
77
+ copies of the Software, and to permit persons to whom the Software is
78
+ furnished to do so, subject to the following conditions:
79
+
80
+ The above copyright notice and this permission notice shall be included in all
81
+ copies or substantial portions of the Software.
82
+
83
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
84
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
85
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
86
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
87
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
88
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
89
+ SOFTWARE.
@@ -79,7 +79,8 @@ export declare class Editor implements Component, Focusable {
79
79
  private preferredVisualCol;
80
80
  private snappedFromCursorCol;
81
81
  private undoStack;
82
- onSubmit?: (text: string) => void;
82
+ /** Receives the trimmed text and the untrimmed text, so callers can see a leading space. */
83
+ onSubmit?: (text: string, rawText?: string) => void;
83
84
  onChange?: (text: string) => void;
84
85
  disableSubmit: boolean;
85
86
  constructor(tui: TUI, theme: EditorTheme, options?: EditorOptions);