@valyrianjs/terminal 0.2.0 → 0.2.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.
- package/dist/ansi.d.ts +2 -0
- package/dist/ansi.d.ts.map +1 -1
- package/dist/ansi.js +23 -13
- package/dist/ansi.js.map +1 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +10 -2
- package/dist/events.js.map +1 -1
- package/dist/frame-style.d.ts +7 -0
- package/dist/frame-style.d.ts.map +1 -0
- package/dist/frame-style.js +27 -0
- package/dist/frame-style.js.map +1 -0
- package/dist/keymap.d.ts.map +1 -1
- package/dist/keymap.js +4 -2
- package/dist/keymap.js.map +1 -1
- package/dist/layout.d.ts +5 -1
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +55 -24
- package/dist/layout.js.map +1 -1
- package/dist/mouse.d.ts +6 -0
- package/dist/mouse.d.ts.map +1 -1
- package/dist/mouse.js +38 -17
- package/dist/mouse.js.map +1 -1
- package/dist/primitives.d.ts.map +1 -1
- package/dist/primitives.js +8 -1
- package/dist/primitives.js.map +1 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +266 -70
- package/dist/render.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +13 -5
- package/dist/runtime.js.map +1 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +325 -83
- package/dist/session.js.map +1 -1
- package/dist/text.d.ts +7 -0
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +114 -0
- package/dist/text.js.map +1 -1
- package/dist/theme.d.ts.map +1 -1
- package/dist/theme.js +3 -0
- package/dist/theme.js.map +1 -1
- package/dist/tree.d.ts.map +1 -1
- package/dist/tree.js +18 -4
- package/dist/tree.js.map +1 -1
- package/dist/types.d.ts +41 -4
- package/dist/types.d.ts.map +1 -1
- package/docs/api-reference.md +18 -8
- package/docs/cookbook.md +1 -1
- package/docs/interaction-model.md +10 -8
- package/docs/primitive-gallery.md +9 -5
- package/examples/basic.tsx +22 -0
- package/examples/cli.tsx +55 -0
- package/examples/demo.tsx +98 -0
- package/examples/docs/background-fill.tsx +107 -0
- package/examples/docs/component-composition.tsx +140 -0
- package/examples/docs/cursor.tsx +121 -0
- package/examples/docs/employees-list.tsx +138 -0
- package/examples/docs/hello.tsx +98 -0
- package/examples/docs/interactive-note.tsx +111 -0
- package/examples/docs/module-api-dashboard.tsx +307 -0
- package/examples/docs/module-flux-store.tsx +181 -0
- package/examples/docs/module-form-workflow.tsx +339 -0
- package/examples/docs/module-forms.tsx +218 -0
- package/examples/docs/module-money.tsx +175 -0
- package/examples/docs/module-native-store.tsx +188 -0
- package/examples/docs/module-pulses.tsx +142 -0
- package/examples/docs/module-query.tsx +209 -0
- package/examples/docs/module-request.tsx +194 -0
- package/examples/docs/module-state-workbench.tsx +283 -0
- package/examples/docs/module-tasks.tsx +223 -0
- package/examples/docs/module-translate.tsx +194 -0
- package/examples/docs/module-utils.tsx +168 -0
- package/examples/docs/module-valyrian-core.tsx +159 -0
- package/examples/docs/pizza-builder.tsx +463 -0
- package/examples/docs/primitive-activity-console.tsx +113 -0
- package/examples/docs/primitive-command-panel.tsx +186 -0
- package/examples/docs/primitive-data-explorer.tsx +155 -0
- package/examples/docs/primitive-input-workbench.tsx +128 -0
- package/examples/docs/primitive-layout-shell.tsx +115 -0
- package/examples/docs/responsive-split.tsx +186 -0
- package/examples/docs/style-system.tsx +209 -0
- package/examples/docs/theme-colors.tsx +225 -0
- package/examples/docs/virtualized-list-workbench.tsx +232 -0
- package/examples/opencode-dogfood-app.tsx +215 -0
- package/examples/opencode-dogfood-lifecycle.tsx +194 -0
- package/examples/opencode-dogfood.tsx +11 -0
- package/llms-full.txt +38 -22
- package/package.json +3 -2
- package/src/ansi.ts +23 -13
- package/src/events.ts +6 -2
- package/src/frame-style.ts +36 -0
- package/src/keymap.ts +4 -2
- package/src/layout.ts +59 -25
- package/src/mouse.ts +41 -16
- package/src/primitives.ts +8 -1
- package/src/render.ts +286 -71
- package/src/runtime.ts +13 -5
- package/src/session.ts +343 -79
- package/src/text.ts +148 -0
- package/src/theme.ts +3 -0
- package/src/tree.ts +19 -4
- package/src/types.ts +48 -3
package/src/mouse.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { parseTerminalKey } from "./events.js";
|
|
|
2
2
|
|
|
3
3
|
import type { ParsedTerminalInput, TerminalHitbox } from "./types.js";
|
|
4
4
|
|
|
5
|
-
const nestedParentTags = new Set(["terminal-box", "terminal-view"]);
|
|
5
|
+
const nestedParentTags = new Set(["terminal-box", "terminal-view", "terminal-list"]);
|
|
6
6
|
|
|
7
7
|
function containsHitbox(parent: TerminalHitbox, child: TerminalHitbox) {
|
|
8
8
|
return child.x1 >= parent.x1 && child.x2 <= parent.x2 && child.y1 >= parent.y1 && child.y2 <= parent.y2;
|
|
@@ -12,24 +12,40 @@ function samePointerLayer(left: TerminalHitbox, right: TerminalHitbox) {
|
|
|
12
12
|
return (left.pointerLayer ?? 0) === (right.pointerLayer ?? 0);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
function parseMouseMatch(match: RegExpExecArray): Extract<ParsedTerminalInput, { type: "mouse" }> {
|
|
16
|
+
const code = Number(match[1]);
|
|
17
|
+
let action: "press" | "release" | "drag" | "wheel-up" | "wheel-down" = match[4] === "M" ? "press" : "release";
|
|
18
|
+
if (code >= 64) {
|
|
19
|
+
action = code === 64 ? "wheel-up" : "wheel-down";
|
|
20
|
+
} else if (code >= 32 && match[4] === "M") {
|
|
21
|
+
action = "drag";
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
type: "mouse",
|
|
25
|
+
button: code,
|
|
26
|
+
x: Number(match[2]),
|
|
27
|
+
y: Number(match[3]),
|
|
28
|
+
action
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function parseTerminalMousePrefix(chunk: string | Uint8Array): { input: Extract<ParsedTerminalInput, { type: "mouse" }>; rest: string } | null {
|
|
33
|
+
const value = typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
|
|
34
|
+
const match = /^\u001b\[<(\d+);(\d+);(\d+)([Mm])/.exec(value);
|
|
35
|
+
if (!match) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
input: parseMouseMatch(match),
|
|
40
|
+
rest: value.slice(match[0].length)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
15
44
|
export function parseTerminalInput(chunk: string | Uint8Array): ParsedTerminalInput {
|
|
16
45
|
const value = typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
|
|
17
46
|
const match = /^\u001b\[<(\d+);(\d+);(\d+)([Mm])$/.exec(value);
|
|
18
47
|
if (match) {
|
|
19
|
-
|
|
20
|
-
let action: "press" | "release" | "drag" | "wheel-up" | "wheel-down" = match[4] === "M" ? "press" : "release";
|
|
21
|
-
if (code >= 64) {
|
|
22
|
-
action = code === 64 ? "wheel-up" : "wheel-down";
|
|
23
|
-
} else if (code >= 32 && match[4] === "M") {
|
|
24
|
-
action = "drag";
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
type: "mouse",
|
|
28
|
-
button: code,
|
|
29
|
-
x: Number(match[2]),
|
|
30
|
-
y: Number(match[3]),
|
|
31
|
-
action
|
|
32
|
-
};
|
|
48
|
+
return parseMouseMatch(match);
|
|
33
49
|
}
|
|
34
50
|
return { type: "key", key: parseTerminalKey(value) };
|
|
35
51
|
}
|
|
@@ -63,6 +79,15 @@ export function cursorFromHitbox(hitbox: TerminalHitbox, x: number) {
|
|
|
63
79
|
if (typeof hitbox.textStartX !== "number") {
|
|
64
80
|
return 0;
|
|
65
81
|
}
|
|
82
|
+
|
|
66
83
|
const textLength = Number(hitbox.textLength || 0);
|
|
67
|
-
|
|
84
|
+
const cellOffset = Math.max(0, x - hitbox.textStartX);
|
|
85
|
+
if (Array.isArray(hitbox.textCellToStringIndex) && hitbox.textCellToStringIndex.length > 0) {
|
|
86
|
+
const index = hitbox.textCellToStringIndex[Math.min(cellOffset, hitbox.textCellToStringIndex.length - 1)];
|
|
87
|
+
if (typeof index === "number" && Number.isFinite(index)) {
|
|
88
|
+
return Math.max(0, Math.min(textLength, index));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return Math.max(0, Math.min(textLength, cellOffset));
|
|
68
93
|
}
|
package/src/primitives.ts
CHANGED
|
@@ -49,7 +49,14 @@ export const Editor = primitive<TerminalEditorProps>("terminal-editor");
|
|
|
49
49
|
export const Button = primitive<TerminalButtonProps>("terminal-button");
|
|
50
50
|
export const ScrollView = primitive<TerminalScrollViewProps>("terminal-scroll");
|
|
51
51
|
export const LogView = primitive<TerminalLogViewProps>("terminal-log-view");
|
|
52
|
-
export const List =
|
|
52
|
+
export const List = function TerminalList(props: TerminalPrimitiveComponentProps<TerminalListProps<any>> | null | undefined, children: any[]) {
|
|
53
|
+
const nextProps = { ...(props || {}) } as Record<string, any>;
|
|
54
|
+
if (children.length === 1 && typeof children[0] === "function") {
|
|
55
|
+
nextProps.__childrenRenderer = children[0];
|
|
56
|
+
return v("terminal-list", nextProps);
|
|
57
|
+
}
|
|
58
|
+
return v("terminal-list", nextProps, ...children);
|
|
59
|
+
} as TerminalListComponent;
|
|
53
60
|
export const Table = primitive<TerminalTableProps>("terminal-table");
|
|
54
61
|
export const Row = primitive<TerminalRowProps>("terminal-row");
|
|
55
62
|
export const Td = primitive<TerminalTdProps>("terminal-td");
|