@dxos/react-ui-terminal 0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264 → 0.14.0
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/lib/chunk-cli.mjs +46 -5
- package/dist/lib/chunk-cli.mjs.map +1 -1
- package/dist/lib/index.mjs +26 -15
- package/dist/lib/index.mjs.map +1 -1
- package/dist/lib/testing.mjs +7 -2
- package/dist/lib/testing.mjs.map +1 -1
- package/dist/types/src/cli/bridge.d.ts +3 -0
- package/dist/types/src/cli/bridge.d.ts.map +1 -1
- package/dist/types/src/cli/console.d.ts +1 -1
- package/dist/types/src/cli/console.d.ts.map +1 -1
- package/dist/types/src/cli/context.d.ts +3 -3
- package/dist/types/src/cli/context.d.ts.map +1 -1
- package/dist/types/src/cli/index.d.ts +9 -9
- package/dist/types/src/cli/index.d.ts.map +1 -1
- package/dist/types/src/cli/json.d.ts +8 -0
- package/dist/types/src/cli/json.d.ts.map +1 -0
- package/dist/types/src/cli/json.test.d.ts +2 -0
- package/dist/types/src/cli/json.test.d.ts.map +1 -0
- package/dist/types/src/cli/line-editor.d.ts +1 -1
- package/dist/types/src/cli/line-editor.d.ts.map +1 -1
- package/dist/types/src/cli/shell.d.ts +2 -2
- package/dist/types/src/cli/shell.d.ts.map +1 -1
- package/dist/types/src/cli/shell.test.d.ts +2 -0
- package/dist/types/src/cli/shell.test.d.ts.map +1 -0
- package/dist/types/src/cli/stdio.d.ts +1 -1
- package/dist/types/src/cli/stdio.d.ts.map +1 -1
- package/dist/types/src/cli/terminal.d.ts +1 -1
- package/dist/types/src/cli/terminal.d.ts.map +1 -1
- package/dist/types/src/cli/testing.d.ts +2 -1
- package/dist/types/src/cli/testing.d.ts.map +1 -1
- package/dist/types/src/components/Terminal/Terminal.d.ts +22 -6
- package/dist/types/src/components/Terminal/Terminal.d.ts.map +1 -1
- package/dist/types/src/components/Terminal/Terminal.stories.d.ts.map +1 -1
- package/dist/types/src/components/Terminal/index.d.ts +1 -1
- package/dist/types/src/components/Terminal/index.d.ts.map +1 -1
- package/dist/types/src/components/Terminal/theme.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +33 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -9
- package/src/cli/bridge.ts +9 -1
- package/src/cli/console.test.ts +23 -5
- package/src/cli/console.ts +11 -3
- package/src/cli/context.ts +7 -7
- package/src/cli/index.ts +9 -9
- package/src/cli/input.test.ts +1 -1
- package/src/cli/json.test.ts +51 -0
- package/src/cli/json.ts +47 -0
- package/src/cli/line-editor.test.ts +3 -3
- package/src/cli/line-editor.ts +1 -1
- package/src/cli/shell.test.ts +48 -0
- package/src/cli/shell.ts +13 -5
- package/src/cli/stdio.ts +1 -1
- package/src/cli/terminal.ts +3 -3
- package/src/cli/testing.ts +6 -2
- package/src/cli/tokenize.test.ts +1 -1
- package/src/components/Terminal/Terminal.stories.tsx +37 -17
- package/src/components/Terminal/Terminal.tsx +54 -12
- package/src/components/Terminal/index.ts +1 -1
- package/src/components/Terminal/theme.ts +14 -6
- package/src/components/index.ts +1 -1
- package/src/errors.ts +8 -0
- package/src/index.ts +1 -1
- package/src/testing.ts +8 -2
package/dist/lib/chunk-cli.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import * as Console from "effect/Console";
|
|
|
3
3
|
import * as Layer from "effect/Layer";
|
|
4
4
|
import * as FileSystem from "effect/FileSystem";
|
|
5
5
|
import * as Path from "effect/Path";
|
|
6
|
-
import * as ChildProcessSpawner from "effect/
|
|
6
|
+
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
|
|
7
7
|
import * as Sink from "effect/Sink";
|
|
8
8
|
import * as Stdio from "effect/Stdio";
|
|
9
9
|
import * as Stream from "effect/Stream";
|
|
@@ -11,8 +11,8 @@ import * as Queue from "effect/Queue";
|
|
|
11
11
|
import * as Terminal from "effect/Terminal";
|
|
12
12
|
import * as Option from "effect/Option";
|
|
13
13
|
import * as Cause from "effect/Cause";
|
|
14
|
-
import * as CliError from "effect/
|
|
15
|
-
import * as Command from "effect/
|
|
14
|
+
import * as CliError from "effect/cli/CliError";
|
|
15
|
+
import * as Command from "effect/cli/Command";
|
|
16
16
|
//#region \0rolldown/runtime.js
|
|
17
17
|
var __defProp = Object.defineProperty;
|
|
18
18
|
var __exportAll = (all, no_symbols) => {
|
|
@@ -25,16 +25,50 @@ var __exportAll = (all, no_symbols) => {
|
|
|
25
25
|
return target;
|
|
26
26
|
};
|
|
27
27
|
//#endregion
|
|
28
|
+
//#region src/cli/json.ts
|
|
29
|
+
var RESET = "\x1B[0m";
|
|
30
|
+
var KEY = "\x1B[36m";
|
|
31
|
+
var STRING = "\x1B[32m";
|
|
32
|
+
var NUMBER = "\x1B[33m";
|
|
33
|
+
var BOOLEAN = "\x1B[35m";
|
|
34
|
+
var NULL = "\x1B[2m";
|
|
35
|
+
var TOKEN = /("(?:[^"\\]|\\.)*")(\s*:)?|\b(?:true|false)\b|\bnull\b|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g;
|
|
36
|
+
/**
|
|
37
|
+
* The value `text` holds when it is a JSON object or array, else undefined. A bare scalar is valid
|
|
38
|
+
* JSON too, but reads as ordinary output, so only structured data is treated as JSON.
|
|
39
|
+
*/
|
|
40
|
+
var parseJson = (text) => {
|
|
41
|
+
const trimmed = text.trim();
|
|
42
|
+
if (!/^[[{]/.test(trimmed)) return;
|
|
43
|
+
try {
|
|
44
|
+
return JSON.parse(trimmed);
|
|
45
|
+
} catch {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
/** Indented JSON with ANSI colors per token kind; stripped of its escapes it is `JSON.stringify(value, null, 2)`. */
|
|
50
|
+
var highlightJson = (value) => (JSON.stringify(value, null, 2) ?? String(value)).replace(TOKEN, (match, string, colon) => {
|
|
51
|
+
if (string !== void 0) return colon !== void 0 ? `${KEY}${string}${RESET}${colon}` : `${STRING}${string}${RESET}`;
|
|
52
|
+
if (match === "true" || match === "false") return `${BOOLEAN}${match}${RESET}`;
|
|
53
|
+
if (match === "null") return `${NULL}${match}${RESET}`;
|
|
54
|
+
return `${NUMBER}${match}${RESET}`;
|
|
55
|
+
});
|
|
56
|
+
//#endregion
|
|
28
57
|
//#region src/cli/console.ts
|
|
29
58
|
var console_exports = /* @__PURE__ */ __exportAll({
|
|
30
59
|
layer: () => layer$3,
|
|
31
60
|
make: () => make$2
|
|
32
61
|
});
|
|
62
|
+
/** A value as terminal text: an object, or a string holding a JSON object or array, is highlighted; a scalar stays plain. */
|
|
33
63
|
var stringify = (value) => {
|
|
34
|
-
if (typeof value === "string")
|
|
64
|
+
if (typeof value === "string") {
|
|
65
|
+
const json = parseJson(value);
|
|
66
|
+
return json === void 0 ? value : highlightJson(json);
|
|
67
|
+
}
|
|
35
68
|
if (value instanceof Error) return value.stack ?? value.message;
|
|
69
|
+
if (typeof value !== "object" || value === null) return String(value);
|
|
36
70
|
try {
|
|
37
|
-
return
|
|
71
|
+
return highlightJson(value);
|
|
38
72
|
} catch {
|
|
39
73
|
return String(value);
|
|
40
74
|
}
|
|
@@ -403,6 +437,7 @@ var XtermBridge = class {
|
|
|
403
437
|
#subscribers = [];
|
|
404
438
|
#subscription;
|
|
405
439
|
#atLineStart = true;
|
|
440
|
+
#written = 0;
|
|
406
441
|
constructor(terminal) {
|
|
407
442
|
this.#terminal = terminal;
|
|
408
443
|
this.#subscription = terminal.onData((data) => this.#handleData(data));
|
|
@@ -420,6 +455,9 @@ var XtermBridge = class {
|
|
|
420
455
|
get atLineStart() {
|
|
421
456
|
return this.#atLineStart;
|
|
422
457
|
}
|
|
458
|
+
get written() {
|
|
459
|
+
return this.#written;
|
|
460
|
+
}
|
|
423
461
|
/**
|
|
424
462
|
* Writes text, translating bare newlines to CRLF since xterm does not reset the column on `\n`.
|
|
425
463
|
*/
|
|
@@ -427,6 +465,7 @@ var XtermBridge = class {
|
|
|
427
465
|
if (text.length === 0) return;
|
|
428
466
|
this.#terminal.write(text.replace(/\r?\n/g, "\r\n"));
|
|
429
467
|
this.#atLineStart = text.endsWith("\n");
|
|
468
|
+
this.#written++;
|
|
430
469
|
}
|
|
431
470
|
clear() {
|
|
432
471
|
this.#terminal.write("\x1B[2J\x1B[H");
|
|
@@ -505,12 +544,14 @@ var runShell = (bridge, options) => Effect.gen(function* () {
|
|
|
505
544
|
history.push(line);
|
|
506
545
|
const tokens = rewriteHelpAliases(tokenize(line));
|
|
507
546
|
if (tokens.length === 0) continue;
|
|
547
|
+
const writtenBefore = bridge.written;
|
|
508
548
|
yield* run(tokens).pipe(Effect.catchCause((cause) => {
|
|
509
549
|
if (Cause.hasInterruptsOnly(cause)) return Effect.void;
|
|
510
550
|
const error = Cause.findErrorOption(cause);
|
|
511
551
|
if (Option.isSome(error) && CliError.isCliError(error.value)) return Effect.void;
|
|
512
552
|
return Console.error(Cause.pretty(cause));
|
|
513
553
|
}));
|
|
554
|
+
if (bridge.written > writtenBefore) bridge.write(bridge.atLineStart ? "\n" : "\n\n");
|
|
514
555
|
}
|
|
515
556
|
bridge.write("\n");
|
|
516
557
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-cli.mjs","names":[],"sources":["../../src/cli/console.ts","../../src/cli/stdio.ts","../../src/cli/input.ts","../../src/cli/line-editor.ts","../../src/cli/terminal.ts","../../src/cli/context.ts","../../src/cli/bridge.ts","../../src/cli/tokenize.ts","../../src/cli/shell.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Console from 'effect/Console';\nimport * as Layer from 'effect/Layer';\n\nimport type { TerminalBridge } from './bridge';\n\nconst stringify = (value: unknown): string => {\n if (typeof value === 'string') {\n return value;\n }\n if (value instanceof Error) {\n return value.stack ?? value.message;\n }\n\n try {\n return JSON.stringify(value, null, 2) ?? String(value);\n } catch {\n return String(value);\n }\n};\n\nconst format = (args: ReadonlyArray<unknown>): string => args.map(stringify).join(' ');\n\n/**\n * Routes Effect's `Console` to the terminal.\n *\n * The CLI renders help, usage errors, and wizard output as ANSI text through this service, which\n * xterm interprets natively — so the browser gets the same styled output as a shell.\n */\nexport const make = (bridge: TerminalBridge): Console.Console => {\n const write = (args: ReadonlyArray<unknown>) => bridge.write(format(args) + '\\n');\n const noop = () => {};\n\n return {\n assert: (condition, ...args) => {\n if (!condition) {\n write(['Assertion failed:', ...args]);\n }\n },\n clear: () => bridge.clear(),\n count: noop,\n countReset: noop,\n debug: (...args) => write(args),\n dir: (item) => write([item]),\n dirxml: (...args) => write(args),\n error: (...args) => write(args),\n group: (...args) => write(args),\n groupCollapsed: (...args) => write(args),\n groupEnd: noop,\n info: (...args) => write(args),\n log: (...args) => write(args),\n table: (tabularData) => write([tabularData]),\n time: noop,\n timeEnd: noop,\n timeLog: (_label, ...args) => write(args),\n trace: (...args) => write(args),\n warn: (...args) => write(args),\n };\n};\n\n/** Overrides the console for everything running under the layer. */\nexport const layer = (bridge: TerminalBridge): Layer.Layer<never> =>\n Layer.succeedContext(Console.Console.context(make(bridge)));\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport * as Sink from 'effect/Sink';\nimport * as Stdio from 'effect/Stdio';\nimport * as Stream from 'effect/Stream';\n\nimport type { TerminalBridge } from './bridge';\n\nconst decoder = new TextDecoder();\n\n/**\n * Routes process stdout/stderr to the terminal.\n *\n * The CLI writes help and usage errors through `Stdio` rather than `Console`, so a draining stub\n * would swallow exactly the output a shell exists to show. Both streams land in the same terminal,\n * which is what a real one does too.\n */\nexport const make = (bridge: TerminalBridge): Stdio.Stdio => {\n const sink = Sink.forEach((chunk: string | Uint8Array) =>\n Effect.sync(() => bridge.write(typeof chunk === 'string' ? chunk : decoder.decode(chunk))),\n );\n\n return Stdio.make({\n args: Effect.succeed([]),\n stdout: () => sink,\n stderr: () => sink,\n stdin: Stream.empty,\n stdoutIsTerminal: Effect.succeed(true),\n });\n};\n\nexport const layer = (bridge: TerminalBridge): Layer.Layer<Stdio.Stdio> => Layer.succeed(Stdio.Stdio, make(bridge));\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Option from 'effect/Option';\nimport type * as Terminal from 'effect/Terminal';\n\ntype KeyOptions = {\n input?: string;\n ctrl?: boolean;\n meta?: boolean;\n shift?: boolean;\n};\n\nconst makeInput = (\n name: string,\n { input, ctrl = false, meta = false, shift = false }: KeyOptions = {},\n): Terminal.UserInput => ({\n input: Option.fromNullishOr(input),\n key: { name, ctrl, meta, shift },\n});\n\n/**\n * Control characters that name a key directly rather than resolving to a ctrl-modified letter.\n */\nconst CONTROL_KEYS: Record<string, string> = {\n '\\r': 'return',\n '\\n': 'return',\n '\\t': 'tab',\n '\\b': 'backspace',\n '\\x7f': 'backspace',\n};\n\n/**\n * CSI/SS3 sequences (minus the leading escape) emitted by xterm for navigation keys.\n * Ordered longest-first so `[3~` is matched before a shorter entry sharing its prefix.\n */\nconst ESCAPE_SEQUENCES: ReadonlyArray<readonly [string, string]> = [\n ['[1~', 'home'],\n ['[3~', 'delete'],\n ['[4~', 'end'],\n ['[5~', 'pageup'],\n ['[6~', 'pagedown'],\n ['[A', 'up'],\n ['[B', 'down'],\n ['[C', 'right'],\n ['[D', 'left'],\n ['[F', 'end'],\n ['[H', 'home'],\n ['OA', 'up'],\n ['OB', 'down'],\n ['OC', 'right'],\n ['OD', 'left'],\n];\n\nconst matchEscapeSequence = (data: string, index: number): { name: string; length: number } | undefined => {\n for (const [sequence, name] of ESCAPE_SEQUENCES) {\n if (data.startsWith(sequence, index)) {\n return { name, length: sequence.length };\n }\n }\n\n return undefined;\n};\n\n/**\n * Length of the unrecognized escape sequence at `index`, or zero if what follows is not one.\n *\n * The table above covers only unmodified navigation keys, so a chord like ctrl-right arrives as\n * the parameterized `\\x1b[1;5C` and matches nothing. Measuring the whole sequence lets the caller\n * discard it; decoding it byte by byte would type `1;5C` into the line instead.\n */\nconst unrecognizedEscapeLength = (data: string, index: number): number => {\n const introducer = data[index];\n if (introducer === '[') {\n // CSI: parameter and intermediate bytes up to a final byte in `@`–`~`.\n let end = index + 1;\n while (end < data.length && !(data[end] >= '@' && data[end] <= '~')) {\n end += 1;\n }\n\n return end < data.length ? end - index + 1 : data.length - index;\n }\n\n // SS3: a single final byte follows the introducer.\n if (introducer === 'O' && index + 1 < data.length) {\n return 2;\n }\n\n return 0;\n};\n\n/**\n * Decodes a chunk of xterm `onData` output into the keypress events that Effect's `Terminal`\n * consumers (notably `@effect/cli` prompts) expect, using the same key names as Node's readline.\n *\n * Decoding the raw data stream rather than `onKey` DOM events is what makes paste work: a pasted\n * string arrives as one chunk and expands to one event per character.\n */\nexport const decodeInput = (data: string): Terminal.UserInput[] => {\n const inputs: Terminal.UserInput[] = [];\n let index = 0;\n\n while (index < data.length) {\n const char = data[index];\n\n if (char === '\\x1b') {\n const escape = matchEscapeSequence(data, index + 1);\n if (escape) {\n inputs.push(makeInput(escape.name));\n index += escape.length + 1;\n continue;\n }\n\n const unrecognized = unrecognizedEscapeLength(data, index + 1);\n if (unrecognized > 0) {\n index += unrecognized + 1;\n continue;\n }\n\n // A lone escape followed by a printable character is how alt-modified keys arrive.\n const next = data[index + 1];\n if (next !== undefined && next >= ' ' && next !== '\\x7f') {\n inputs.push(makeInput(next.toLowerCase(), { input: next, meta: true }));\n index += 2;\n continue;\n }\n\n inputs.push(makeInput('escape'));\n index += 1;\n continue;\n }\n\n const control = CONTROL_KEYS[char];\n if (control) {\n inputs.push(makeInput(control));\n index += 1;\n continue;\n }\n\n const code = char.charCodeAt(0);\n if (code < 0x20) {\n inputs.push(makeInput(String.fromCharCode(code + 0x60), { ctrl: true }));\n index += 1;\n continue;\n }\n\n const lower = char.toLowerCase();\n inputs.push(\n makeInput(char === ' ' ? 'space' : lower, {\n input: char,\n shift: char !== lower,\n }),\n );\n index += 1;\n }\n\n return inputs;\n};\n\n/**\n * Ctrl-C and Ctrl-D end an input stream, matching the platform-node default.\n */\nexport const isQuitInput = (input: Terminal.UserInput): boolean =>\n input.key.ctrl && (input.key.name === 'c' || input.key.name === 'd');\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Option from 'effect/Option';\nimport * as Terminal from 'effect/Terminal';\n\nimport type { TerminalBridge } from './bridge';\n\nexport type LineResult =\n | { readonly type: 'line'; readonly value: string }\n | { readonly type: 'cancelled' }\n | { readonly type: 'eof' };\n\nexport type ReadLineOptions = {\n /**\n * Rendered before the editable buffer and redrawn on every keystroke.\n */\n prompt?: string;\n /**\n * Previously entered lines, oldest first. Mutated by the caller between reads; the editor only\n * reads it.\n */\n history?: ReadonlyArray<string>;\n};\n\n/**\n * Reads a single line, echoing keystrokes and supporting inline editing, history recall, and the\n * common readline control chords.\n *\n * Distinguishes cancellation (Ctrl-C) from end-of-input (Ctrl-D on an empty buffer) so a shell can\n * abandon the current line without exiting.\n */\nexport const readLineResult = (bridge: TerminalBridge, options: ReadLineOptions = {}): Effect.Effect<LineResult> =>\n Effect.callback<LineResult>((resume) => {\n const { prompt = '', history = [] } = options;\n\n let buffer = '';\n let cursor = 0;\n let historyIndex = history.length;\n let draft = '';\n\n // Redraws the whole row; a buffer long enough to wrap will not repaint correctly.\n const render = () => {\n const trailing = buffer.length - cursor;\n bridge.write(`\\r\\x1b[K${prompt}${buffer}${trailing > 0 ? `\\x1b[${trailing}D` : ''}`);\n };\n\n const finish = (result: LineResult) => {\n unsubscribe();\n resume(Effect.succeed(result));\n };\n\n const recall = (index: number) => {\n if (historyIndex === history.length) {\n draft = buffer;\n }\n\n historyIndex = index;\n buffer = index === history.length ? draft : history[index];\n cursor = buffer.length;\n render();\n };\n\n const unsubscribe = bridge.subscribe((input) => {\n const { key } = input;\n\n if (key.ctrl) {\n switch (key.name) {\n case 'c': {\n bridge.write('^C\\n');\n finish({ type: 'cancelled' });\n return;\n }\n case 'd': {\n if (buffer.length === 0) {\n bridge.write('\\n');\n finish({ type: 'eof' });\n }\n return;\n }\n case 'a': {\n cursor = 0;\n render();\n return;\n }\n case 'e': {\n cursor = buffer.length;\n render();\n return;\n }\n case 'u': {\n buffer = buffer.slice(cursor);\n cursor = 0;\n render();\n return;\n }\n case 'k': {\n buffer = buffer.slice(0, cursor);\n render();\n return;\n }\n case 'l': {\n bridge.clear();\n render();\n return;\n }\n default:\n return;\n }\n }\n\n // Alt chords carry the bare character, so without this the editor types the `f` of alt-f\n // rather than ignoring a word motion it does not implement.\n if (key.meta) {\n return;\n }\n\n switch (key.name) {\n case 'return': {\n bridge.write('\\n');\n finish({ type: 'line', value: buffer });\n return;\n }\n case 'backspace': {\n if (cursor > 0) {\n buffer = buffer.slice(0, cursor - 1) + buffer.slice(cursor);\n cursor -= 1;\n render();\n }\n return;\n }\n case 'delete': {\n if (cursor < buffer.length) {\n buffer = buffer.slice(0, cursor) + buffer.slice(cursor + 1);\n render();\n }\n return;\n }\n case 'left': {\n if (cursor > 0) {\n cursor -= 1;\n render();\n }\n return;\n }\n case 'right': {\n if (cursor < buffer.length) {\n cursor += 1;\n render();\n }\n return;\n }\n case 'home': {\n cursor = 0;\n render();\n return;\n }\n case 'end': {\n cursor = buffer.length;\n render();\n return;\n }\n case 'up': {\n if (historyIndex > 0) {\n recall(historyIndex - 1);\n }\n return;\n }\n case 'down': {\n if (historyIndex < history.length) {\n recall(historyIndex + 1);\n }\n return;\n }\n case 'escape':\n case 'tab':\n return;\n }\n\n Option.match(input.input, {\n onNone: () => {},\n onSome: (char) => {\n buffer = buffer.slice(0, cursor) + char + buffer.slice(cursor);\n cursor += char.length;\n render();\n },\n });\n });\n\n render();\n\n return Effect.sync(unsubscribe);\n });\n\n/**\n * The `Terminal` service contract: a line, or a `QuitError` for either interrupt.\n */\nexport const readLine = (bridge: TerminalBridge, options: ReadLineOptions = {}) =>\n readLineResult(bridge, options).pipe(\n Effect.flatMap((result) =>\n result.type === 'line' ? Effect.succeed(result.value) : Effect.fail(new Terminal.QuitError()),\n ),\n );\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Cause from 'effect/Cause';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport * as Queue from 'effect/Queue';\nimport * as Terminal from 'effect/Terminal';\n\nimport type { TerminalBridge } from './bridge';\nimport { isQuitInput } from './input';\nimport { readLine } from './line-editor';\n\n/**\n * A Effect `Terminal` backed by xterm.\n *\n * This is the only service in `CliApp.Environment` without a browser implementation upstream;\n * `Path` is already pure JS and `FileSystem` can be stubbed.\n */\nexport const make = (bridge: TerminalBridge): Terminal.Terminal =>\n Terminal.make({\n columns: Effect.sync(() => bridge.columns),\n rows: Effect.sync(() => bridge.rows),\n readInput: Effect.gen(function* () {\n const queue = yield* Queue.unbounded<Terminal.UserInput, Cause.Done>();\n const unsubscribe = bridge.subscribe((input) => {\n Queue.offerUnsafe(queue, input);\n if (isQuitInput(input)) {\n Queue.endUnsafe(queue);\n }\n });\n\n yield* Effect.addFinalizer(() => Effect.sync(unsubscribe));\n return Queue.asDequeue(queue);\n }),\n readLine: readLine(bridge),\n display: (text) => Effect.sync(() => bridge.write(text)),\n });\n\nexport const layer = (bridge: TerminalBridge): Layer.Layer<Terminal.Terminal> =>\n Layer.succeed(Terminal.Terminal, make(bridge));\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as FileSystem from 'effect/FileSystem';\nimport * as Layer from 'effect/Layer';\nimport * as Path from 'effect/Path';\nimport type * as Command from 'effect/unstable/cli/Command';\nimport * as ChildProcessSpawner from 'effect/unstable/process/ChildProcessSpawner';\n\nimport type { XtermBridge } from './bridge';\nimport * as XtermConsole from './console';\nimport * as XtermStdio from './stdio';\nimport * as XtermTerminal from './terminal';\n\n/**\n * The browser counterpart to `BunServices.layer`.\n *\n * Of `Command.Environment`, `Path` is already pure JS upstream and the CLI's browser-safe commands\n * never touch the filesystem or spawn a process, leaving `Terminal` and `Stdio` to implement. The\n * console override is merged in too — contributing no services of its own — so command output and\n * the CLI's ANSI help text land in the terminal instead of the devtools console.\n */\nexport type Provided = Command.Environment;\n\nconst UNAVAILABLE = 'Not available in the browser terminal.';\n\nexport const layer = (bridge: XtermBridge): Layer.Layer<Provided> =>\n Layer.mergeAll(\n XtermTerminal.layer(bridge),\n XtermConsole.layer(bridge),\n FileSystem.layerNoop({}),\n Path.layer,\n XtermStdio.layer(bridge),\n Layer.succeed(ChildProcessSpawner.ChildProcessSpawner)(\n ChildProcessSpawner.make(() => Effect.die(new Error(UNAVAILABLE))),\n ),\n );\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport type { IDisposable, Terminal as XtermTerminal } from '@xterm/xterm';\nimport type * as Terminal from 'effect/Terminal';\n\nimport { decodeInput } from './input';\n\nexport type InputHandler = (input: Terminal.UserInput) => void;\n\n/**\n * The surface the shell and the Effect `Terminal` service need from a terminal: a write sink and a\n * stack of keypress subscribers. Depending on this rather than the xterm class keeps the rest of\n * this module free of any renderer.\n */\nexport interface TerminalBridge {\n readonly columns: number;\n readonly rows: number;\n readonly atLineStart: boolean;\n write(text: string): void;\n clear(): void;\n subscribe(handler: InputHandler): () => void;\n}\n\n/**\n * Adapts an xterm instance to {@link TerminalBridge}.\n */\nexport class XtermBridge implements TerminalBridge {\n #terminal: XtermTerminal;\n #subscribers: InputHandler[] = [];\n #subscription: IDisposable;\n #atLineStart = true;\n\n constructor(terminal: XtermTerminal) {\n this.#terminal = terminal;\n this.#subscription = terminal.onData((data) => this.#handleData(data));\n }\n\n get columns(): number {\n return this.#terminal.cols;\n }\n\n get rows(): number {\n return this.#terminal.rows;\n }\n\n /**\n * Whether the cursor sits at the start of a row, so callers can avoid a blank line when a command\n * has already terminated its output with a newline.\n */\n get atLineStart(): boolean {\n return this.#atLineStart;\n }\n\n /**\n * Writes text, translating bare newlines to CRLF since xterm does not reset the column on `\\n`.\n */\n write(text: string): void {\n if (text.length === 0) {\n return;\n }\n\n this.#terminal.write(text.replace(/\\r?\\n/g, '\\r\\n'));\n this.#atLineStart = text.endsWith('\\n');\n }\n\n clear(): void {\n this.#terminal.write('\\x1b[2J\\x1b[H');\n this.#atLineStart = true;\n }\n\n /**\n * Subscribes to keypresses. The most recent subscriber wins, so a prompt opened by a running\n * command takes over from the shell's line editor and hands back when its scope closes.\n */\n subscribe(handler: InputHandler): () => void {\n this.#subscribers.push(handler);\n return () => {\n const index = this.#subscribers.indexOf(handler);\n if (index !== -1) {\n this.#subscribers.splice(index, 1);\n }\n };\n }\n\n dispose(): void {\n this.#subscription.dispose();\n this.#subscribers.length = 0;\n }\n\n #handleData(data: string): void {\n const handler = this.#subscribers.at(-1);\n if (!handler) {\n return;\n }\n\n for (const input of decodeInput(data)) {\n handler(input);\n }\n }\n}\n","//\n// Copyright 2026 DXOS.org\n//\n\n/**\n * Splits a raw input line into argv tokens. Supports single/double-quoted segments so quoted\n * strings with spaces survive. Intentionally simple — anything needing real shell semantics belongs\n * in a real shell.\n */\nexport const tokenize = (input: string): string[] => {\n const tokens: string[] = [];\n const regex = /\"([^\"]*)\"|'([^']*)'|(\\S+)/g;\n let match: RegExpExecArray | null;\n while ((match = regex.exec(input)) !== null) {\n tokens.push(match[1] ?? match[2] ?? match[3]);\n }\n\n return tokens;\n};\n\n/**\n * Translates shell-friendly aliases to their Effect CLI equivalents. The Effect CLI uses `--help`\n * rather than a `help` subcommand, but `help` and `?` are the natural things to type.\n */\nexport const rewriteHelpAliases = (tokens: ReadonlyArray<string>): string[] => {\n if (tokens.length === 0) {\n return [...tokens];\n }\n\n if (tokens[0] !== 'help' && tokens[0] !== '?') {\n return [...tokens];\n }\n\n return tokens.length === 1 ? ['--help'] : [...tokens.slice(1), '--help'];\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Cause from 'effect/Cause';\nimport * as Console from 'effect/Console';\nimport * as Effect from 'effect/Effect';\nimport * as Option from 'effect/Option';\nimport * as CliError from 'effect/unstable/cli/CliError';\nimport * as Command from 'effect/unstable/cli/Command';\n\nimport type { TerminalBridge } from './bridge';\nimport { readLineResult } from './line-editor';\nimport { rewriteHelpAliases, tokenize } from './tokenize';\n\nconst EXIT_COMMANDS = ['exit', 'quit'];\n\n/** The services CLI parsing and execution need. */\nexport type CliEnvironment = Command.Environment;\n\nexport type ShellOptions<Name extends string, Input, ContextInput, E, R> = {\n command: Command.Command<Name, Input, ContextInput, E, R>;\n /** Executable name, used in the prompt. */\n name?: string;\n version?: string;\n prompt?: string;\n banner?: string;\n};\n\n/**\n * Runs a read-eval-print loop against an Effect CLI command tree.\n *\n * Each line is tokenized and dispatched through the same `Command.runWith` the binary uses. The\n * command tree and its layer are built once, so every command reuses the already-activated\n * services.\n */\nexport const runShell = <Name extends string, Input, ContextInput, E, R>(\n bridge: TerminalBridge,\n options: ShellOptions<Name, Input, ContextInput, E, R>,\n): Effect.Effect<void, never, R | CliEnvironment> =>\n Effect.gen(function* () {\n const { command, name = 'dx', version = '0.0.0', prompt = `${name}> `, banner } = options;\n const run = Command.runWith(command, { version });\n const history: string[] = [];\n\n if (banner) {\n bridge.write(`${banner}\\n`);\n }\n\n while (true) {\n if (!bridge.atLineStart) {\n bridge.write('\\n');\n }\n\n const result = yield* readLineResult(bridge, { prompt, history });\n if (result.type === 'eof') {\n break;\n }\n if (result.type === 'cancelled') {\n continue;\n }\n\n const line = result.value.trim();\n if (line.length === 0) {\n continue;\n }\n if (EXIT_COMMANDS.includes(line)) {\n break;\n }\n\n history.push(line);\n const tokens = rewriteHelpAliases(tokenize(line));\n if (tokens.length === 0) {\n continue;\n }\n\n // Failures are reported rather than propagated so the shell survives to the next prompt.\n // CLI errors are skipped because the parser has already rendered them.\n yield* run(tokens).pipe(\n Effect.catchCause((cause) => {\n if (Cause.hasInterruptsOnly(cause)) {\n return Effect.void;\n }\n\n // A CLI error has already been rendered to stdout by the runner (help, usage), so\n // repeating it as a stack would only be noise.\n const error = Cause.findErrorOption(cause);\n if (Option.isSome(error) && CliError.isCliError(error.value)) {\n return Effect.void;\n }\n\n return Console.error(Cause.pretty(cause));\n }),\n );\n }\n\n bridge.write('\\n');\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,IAAM,aAAa,UAA2B;CAC5C,IAAI,OAAO,UAAU,UACnB,OAAO;CAET,IAAI,iBAAiB,OACnB,OAAO,MAAM,SAAS,MAAM;CAG9B,IAAI;EACF,OAAO,KAAK,UAAU,OAAO,MAAM,CAAC,KAAK,OAAO,KAAK;CACvD,QAAQ;EACN,OAAO,OAAO,KAAK;CACrB;AACF;AAEA,IAAM,UAAU,SAAyC,KAAK,IAAI,SAAS,CAAC,CAAC,KAAK,GAAG;;;;;;;AAQrF,IAAa,UAAQ,WAA4C;CAC/D,MAAM,SAAS,SAAiC,OAAO,MAAM,OAAO,IAAI,IAAI,IAAI;CAChF,MAAM,aAAa,CAAC;CAEpB,OAAO;EACL,SAAS,WAAW,GAAG,SAAS;GAC9B,IAAI,CAAC,WACH,MAAM,CAAC,qBAAqB,GAAG,IAAI,CAAC;EAExC;EACA,aAAa,OAAO,MAAM;EAC1B,OAAO;EACP,YAAY;EACZ,QAAQ,GAAG,SAAS,MAAM,IAAI;EAC9B,MAAM,SAAS,MAAM,CAAC,IAAI,CAAC;EAC3B,SAAS,GAAG,SAAS,MAAM,IAAI;EAC/B,QAAQ,GAAG,SAAS,MAAM,IAAI;EAC9B,QAAQ,GAAG,SAAS,MAAM,IAAI;EAC9B,iBAAiB,GAAG,SAAS,MAAM,IAAI;EACvC,UAAU;EACV,OAAO,GAAG,SAAS,MAAM,IAAI;EAC7B,MAAM,GAAG,SAAS,MAAM,IAAI;EAC5B,QAAQ,gBAAgB,MAAM,CAAC,WAAW,CAAC;EAC3C,MAAM;EACN,SAAS;EACT,UAAU,QAAQ,GAAG,SAAS,MAAM,IAAI;EACx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["../../src/cli/json.ts","../../src/cli/console.ts","../../src/cli/stdio.ts","../../src/cli/input.ts","../../src/cli/line-editor.ts","../../src/cli/terminal.ts","../../src/cli/context.ts","../../src/cli/bridge.ts","../../src/cli/tokenize.ts","../../src/cli/shell.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nconst RESET = '\\x1b[0m';\n\n// ANSI slots rather than colors: the terminal theme maps each slot onto a design system hue.\nconst KEY = '\\x1b[36m';\nconst STRING = '\\x1b[32m';\nconst NUMBER = '\\x1b[33m';\nconst BOOLEAN = '\\x1b[35m';\nconst NULL = '\\x1b[2m';\n\n// Strings first, so a colon, digit or keyword inside one is never read as its own token.\nconst TOKEN = /(\"(?:[^\"\\\\]|\\\\.)*\")(\\s*:)?|\\b(?:true|false)\\b|\\bnull\\b|-?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?/g;\n\n/**\n * The value `text` holds when it is a JSON object or array, else undefined. A bare scalar is valid\n * JSON too, but reads as ordinary output, so only structured data is treated as JSON.\n */\nexport const parseJson = (text: string): unknown => {\n const trimmed = text.trim();\n if (!/^[[{]/.test(trimmed)) {\n return undefined;\n }\n\n try {\n return JSON.parse(trimmed);\n } catch {\n return undefined;\n }\n};\n\n/** Indented JSON with ANSI colors per token kind; stripped of its escapes it is `JSON.stringify(value, null, 2)`. */\nexport const highlightJson = (value: unknown): string =>\n (JSON.stringify(value, null, 2) ?? String(value)).replace(TOKEN, (match, string?: string, colon?: string) => {\n if (string !== undefined) {\n return colon !== undefined ? `${KEY}${string}${RESET}${colon}` : `${STRING}${string}${RESET}`;\n }\n if (match === 'true' || match === 'false') {\n return `${BOOLEAN}${match}${RESET}`;\n }\n if (match === 'null') {\n return `${NULL}${match}${RESET}`;\n }\n return `${NUMBER}${match}${RESET}`;\n });\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Console from 'effect/Console';\nimport * as Layer from 'effect/Layer';\n\nimport type { TerminalBridge } from './bridge.ts';\nimport { highlightJson, parseJson } from './json.ts';\n\n/** A value as terminal text: an object, or a string holding a JSON object or array, is highlighted; a scalar stays plain. */\nconst stringify = (value: unknown): string => {\n if (typeof value === 'string') {\n const json = parseJson(value);\n return json === undefined ? value : highlightJson(json);\n }\n if (value instanceof Error) {\n return value.stack ?? value.message;\n }\n\n // Only structured values are highlighted: a logged number or boolean is output, not data to read.\n if (typeof value !== 'object' || value === null) {\n return String(value);\n }\n\n try {\n return highlightJson(value);\n } catch {\n return String(value);\n }\n};\n\nconst format = (args: ReadonlyArray<unknown>): string => args.map(stringify).join(' ');\n\n/**\n * Routes Effect's `Console` to the terminal.\n *\n * The CLI renders help, usage errors, and wizard output as ANSI text through this service, which\n * xterm interprets natively — so the browser gets the same styled output as a shell.\n */\nexport const make = (bridge: TerminalBridge): Console.Console => {\n const write = (args: ReadonlyArray<unknown>) => bridge.write(format(args) + '\\n');\n const noop = () => {};\n\n return {\n assert: (condition, ...args) => {\n if (!condition) {\n write(['Assertion failed:', ...args]);\n }\n },\n clear: () => bridge.clear(),\n count: noop,\n countReset: noop,\n debug: (...args) => write(args),\n dir: (item) => write([item]),\n dirxml: (...args) => write(args),\n error: (...args) => write(args),\n group: (...args) => write(args),\n groupCollapsed: (...args) => write(args),\n groupEnd: noop,\n info: (...args) => write(args),\n log: (...args) => write(args),\n table: (tabularData) => write([tabularData]),\n time: noop,\n timeEnd: noop,\n timeLog: (_label, ...args) => write(args),\n trace: (...args) => write(args),\n warn: (...args) => write(args),\n };\n};\n\n/** Overrides the console for everything running under the layer. */\nexport const layer = (bridge: TerminalBridge): Layer.Layer<never> =>\n Layer.succeedContext(Console.Console.context(make(bridge)));\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport * as Sink from 'effect/Sink';\nimport * as Stdio from 'effect/Stdio';\nimport * as Stream from 'effect/Stream';\n\nimport type { TerminalBridge } from './bridge.ts';\n\nconst decoder = new TextDecoder();\n\n/**\n * Routes process stdout/stderr to the terminal.\n *\n * The CLI writes help and usage errors through `Stdio` rather than `Console`, so a draining stub\n * would swallow exactly the output a shell exists to show. Both streams land in the same terminal,\n * which is what a real one does too.\n */\nexport const make = (bridge: TerminalBridge): Stdio.Stdio => {\n const sink = Sink.forEach((chunk: string | Uint8Array) =>\n Effect.sync(() => bridge.write(typeof chunk === 'string' ? chunk : decoder.decode(chunk))),\n );\n\n return Stdio.make({\n args: Effect.succeed([]),\n stdout: () => sink,\n stderr: () => sink,\n stdin: Stream.empty,\n stdoutIsTerminal: Effect.succeed(true),\n });\n};\n\nexport const layer = (bridge: TerminalBridge): Layer.Layer<Stdio.Stdio> => Layer.succeed(Stdio.Stdio, make(bridge));\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Option from 'effect/Option';\nimport type * as Terminal from 'effect/Terminal';\n\ntype KeyOptions = {\n input?: string;\n ctrl?: boolean;\n meta?: boolean;\n shift?: boolean;\n};\n\nconst makeInput = (\n name: string,\n { input, ctrl = false, meta = false, shift = false }: KeyOptions = {},\n): Terminal.UserInput => ({\n input: Option.fromNullishOr(input),\n key: { name, ctrl, meta, shift },\n});\n\n/**\n * Control characters that name a key directly rather than resolving to a ctrl-modified letter.\n */\nconst CONTROL_KEYS: Record<string, string> = {\n '\\r': 'return',\n '\\n': 'return',\n '\\t': 'tab',\n '\\b': 'backspace',\n '\\x7f': 'backspace',\n};\n\n/**\n * CSI/SS3 sequences (minus the leading escape) emitted by xterm for navigation keys.\n * Ordered longest-first so `[3~` is matched before a shorter entry sharing its prefix.\n */\nconst ESCAPE_SEQUENCES: ReadonlyArray<readonly [string, string]> = [\n ['[1~', 'home'],\n ['[3~', 'delete'],\n ['[4~', 'end'],\n ['[5~', 'pageup'],\n ['[6~', 'pagedown'],\n ['[A', 'up'],\n ['[B', 'down'],\n ['[C', 'right'],\n ['[D', 'left'],\n ['[F', 'end'],\n ['[H', 'home'],\n ['OA', 'up'],\n ['OB', 'down'],\n ['OC', 'right'],\n ['OD', 'left'],\n];\n\nconst matchEscapeSequence = (data: string, index: number): { name: string; length: number } | undefined => {\n for (const [sequence, name] of ESCAPE_SEQUENCES) {\n if (data.startsWith(sequence, index)) {\n return { name, length: sequence.length };\n }\n }\n\n return undefined;\n};\n\n/**\n * Length of the unrecognized escape sequence at `index`, or zero if what follows is not one.\n *\n * The table above covers only unmodified navigation keys, so a chord like ctrl-right arrives as\n * the parameterized `\\x1b[1;5C` and matches nothing. Measuring the whole sequence lets the caller\n * discard it; decoding it byte by byte would type `1;5C` into the line instead.\n */\nconst unrecognizedEscapeLength = (data: string, index: number): number => {\n const introducer = data[index];\n if (introducer === '[') {\n // CSI: parameter and intermediate bytes up to a final byte in `@`–`~`.\n let end = index + 1;\n while (end < data.length && !(data[end] >= '@' && data[end] <= '~')) {\n end += 1;\n }\n\n return end < data.length ? end - index + 1 : data.length - index;\n }\n\n // SS3: a single final byte follows the introducer.\n if (introducer === 'O' && index + 1 < data.length) {\n return 2;\n }\n\n return 0;\n};\n\n/**\n * Decodes a chunk of xterm `onData` output into the keypress events that Effect's `Terminal`\n * consumers (notably `@effect/cli` prompts) expect, using the same key names as Node's readline.\n *\n * Decoding the raw data stream rather than `onKey` DOM events is what makes paste work: a pasted\n * string arrives as one chunk and expands to one event per character.\n */\nexport const decodeInput = (data: string): Terminal.UserInput[] => {\n const inputs: Terminal.UserInput[] = [];\n let index = 0;\n\n while (index < data.length) {\n const char = data[index];\n\n if (char === '\\x1b') {\n const escape = matchEscapeSequence(data, index + 1);\n if (escape) {\n inputs.push(makeInput(escape.name));\n index += escape.length + 1;\n continue;\n }\n\n const unrecognized = unrecognizedEscapeLength(data, index + 1);\n if (unrecognized > 0) {\n index += unrecognized + 1;\n continue;\n }\n\n // A lone escape followed by a printable character is how alt-modified keys arrive.\n const next = data[index + 1];\n if (next !== undefined && next >= ' ' && next !== '\\x7f') {\n inputs.push(makeInput(next.toLowerCase(), { input: next, meta: true }));\n index += 2;\n continue;\n }\n\n inputs.push(makeInput('escape'));\n index += 1;\n continue;\n }\n\n const control = CONTROL_KEYS[char];\n if (control) {\n inputs.push(makeInput(control));\n index += 1;\n continue;\n }\n\n const code = char.charCodeAt(0);\n if (code < 0x20) {\n inputs.push(makeInput(String.fromCharCode(code + 0x60), { ctrl: true }));\n index += 1;\n continue;\n }\n\n const lower = char.toLowerCase();\n inputs.push(\n makeInput(char === ' ' ? 'space' : lower, {\n input: char,\n shift: char !== lower,\n }),\n );\n index += 1;\n }\n\n return inputs;\n};\n\n/**\n * Ctrl-C and Ctrl-D end an input stream, matching the platform-node default.\n */\nexport const isQuitInput = (input: Terminal.UserInput): boolean =>\n input.key.ctrl && (input.key.name === 'c' || input.key.name === 'd');\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Option from 'effect/Option';\nimport * as Terminal from 'effect/Terminal';\n\nimport type { TerminalBridge } from './bridge.ts';\n\nexport type LineResult =\n | { readonly type: 'line'; readonly value: string }\n | { readonly type: 'cancelled' }\n | { readonly type: 'eof' };\n\nexport type ReadLineOptions = {\n /**\n * Rendered before the editable buffer and redrawn on every keystroke.\n */\n prompt?: string;\n /**\n * Previously entered lines, oldest first. Mutated by the caller between reads; the editor only\n * reads it.\n */\n history?: ReadonlyArray<string>;\n};\n\n/**\n * Reads a single line, echoing keystrokes and supporting inline editing, history recall, and the\n * common readline control chords.\n *\n * Distinguishes cancellation (Ctrl-C) from end-of-input (Ctrl-D on an empty buffer) so a shell can\n * abandon the current line without exiting.\n */\nexport const readLineResult = (bridge: TerminalBridge, options: ReadLineOptions = {}): Effect.Effect<LineResult> =>\n Effect.callback<LineResult>((resume) => {\n const { prompt = '', history = [] } = options;\n\n let buffer = '';\n let cursor = 0;\n let historyIndex = history.length;\n let draft = '';\n\n // Redraws the whole row; a buffer long enough to wrap will not repaint correctly.\n const render = () => {\n const trailing = buffer.length - cursor;\n bridge.write(`\\r\\x1b[K${prompt}${buffer}${trailing > 0 ? `\\x1b[${trailing}D` : ''}`);\n };\n\n const finish = (result: LineResult) => {\n unsubscribe();\n resume(Effect.succeed(result));\n };\n\n const recall = (index: number) => {\n if (historyIndex === history.length) {\n draft = buffer;\n }\n\n historyIndex = index;\n buffer = index === history.length ? draft : history[index];\n cursor = buffer.length;\n render();\n };\n\n const unsubscribe = bridge.subscribe((input) => {\n const { key } = input;\n\n if (key.ctrl) {\n switch (key.name) {\n case 'c': {\n bridge.write('^C\\n');\n finish({ type: 'cancelled' });\n return;\n }\n case 'd': {\n if (buffer.length === 0) {\n bridge.write('\\n');\n finish({ type: 'eof' });\n }\n return;\n }\n case 'a': {\n cursor = 0;\n render();\n return;\n }\n case 'e': {\n cursor = buffer.length;\n render();\n return;\n }\n case 'u': {\n buffer = buffer.slice(cursor);\n cursor = 0;\n render();\n return;\n }\n case 'k': {\n buffer = buffer.slice(0, cursor);\n render();\n return;\n }\n case 'l': {\n bridge.clear();\n render();\n return;\n }\n default:\n return;\n }\n }\n\n // Alt chords carry the bare character, so without this the editor types the `f` of alt-f\n // rather than ignoring a word motion it does not implement.\n if (key.meta) {\n return;\n }\n\n switch (key.name) {\n case 'return': {\n bridge.write('\\n');\n finish({ type: 'line', value: buffer });\n return;\n }\n case 'backspace': {\n if (cursor > 0) {\n buffer = buffer.slice(0, cursor - 1) + buffer.slice(cursor);\n cursor -= 1;\n render();\n }\n return;\n }\n case 'delete': {\n if (cursor < buffer.length) {\n buffer = buffer.slice(0, cursor) + buffer.slice(cursor + 1);\n render();\n }\n return;\n }\n case 'left': {\n if (cursor > 0) {\n cursor -= 1;\n render();\n }\n return;\n }\n case 'right': {\n if (cursor < buffer.length) {\n cursor += 1;\n render();\n }\n return;\n }\n case 'home': {\n cursor = 0;\n render();\n return;\n }\n case 'end': {\n cursor = buffer.length;\n render();\n return;\n }\n case 'up': {\n if (historyIndex > 0) {\n recall(historyIndex - 1);\n }\n return;\n }\n case 'down': {\n if (historyIndex < history.length) {\n recall(historyIndex + 1);\n }\n return;\n }\n case 'escape':\n case 'tab':\n return;\n }\n\n Option.match(input.input, {\n onNone: () => {},\n onSome: (char) => {\n buffer = buffer.slice(0, cursor) + char + buffer.slice(cursor);\n cursor += char.length;\n render();\n },\n });\n });\n\n render();\n\n return Effect.sync(unsubscribe);\n });\n\n/**\n * The `Terminal` service contract: a line, or a `QuitError` for either interrupt.\n */\nexport const readLine = (bridge: TerminalBridge, options: ReadLineOptions = {}) =>\n readLineResult(bridge, options).pipe(\n Effect.flatMap((result) =>\n result.type === 'line' ? Effect.succeed(result.value) : Effect.fail(new Terminal.QuitError()),\n ),\n );\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Cause from 'effect/Cause';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport * as Queue from 'effect/Queue';\nimport * as Terminal from 'effect/Terminal';\n\nimport type { TerminalBridge } from './bridge.ts';\nimport { isQuitInput } from './input.ts';\nimport { readLine } from './line-editor.ts';\n\n/**\n * A Effect `Terminal` backed by xterm.\n *\n * This is the only service in `CliApp.Environment` without a browser implementation upstream;\n * `Path` is already pure JS and `FileSystem` can be stubbed.\n */\nexport const make = (bridge: TerminalBridge): Terminal.Terminal =>\n Terminal.make({\n columns: Effect.sync(() => bridge.columns),\n rows: Effect.sync(() => bridge.rows),\n readInput: Effect.gen(function* () {\n const queue = yield* Queue.unbounded<Terminal.UserInput, Cause.Done>();\n const unsubscribe = bridge.subscribe((input) => {\n Queue.offerUnsafe(queue, input);\n if (isQuitInput(input)) {\n Queue.endUnsafe(queue);\n }\n });\n\n yield* Effect.addFinalizer(() => Effect.sync(unsubscribe));\n return Queue.asDequeue(queue);\n }),\n readLine: readLine(bridge),\n display: (text) => Effect.sync(() => bridge.write(text)),\n });\n\nexport const layer = (bridge: TerminalBridge): Layer.Layer<Terminal.Terminal> =>\n Layer.succeed(Terminal.Terminal, make(bridge));\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport type * as Command from 'effect/cli/Command';\nimport * as Effect from 'effect/Effect';\nimport * as FileSystem from 'effect/FileSystem';\nimport * as Layer from 'effect/Layer';\nimport * as Path from 'effect/Path';\nimport * as ChildProcessSpawner from 'effect/process/ChildProcessSpawner';\n\nimport type { TerminalBridge } from './bridge.ts';\nimport * as XtermConsole from './console.ts';\nimport * as XtermStdio from './stdio.ts';\nimport * as XtermTerminal from './terminal.ts';\n\n/**\n * The browser counterpart to `BunServices.layer`.\n *\n * Of `Command.Environment`, `Path` is already pure JS upstream and the CLI's browser-safe commands\n * never touch the filesystem or spawn a process, leaving `Terminal` and `Stdio` to implement. The\n * console override is merged in too — contributing no services of its own — so command output and\n * the CLI's ANSI help text land in the terminal instead of the devtools console.\n */\nexport type Provided = Command.Environment;\n\nconst UNAVAILABLE = 'Not available in the browser terminal.';\n\nexport const layer = (bridge: TerminalBridge): Layer.Layer<Provided> =>\n Layer.mergeAll(\n XtermTerminal.layer(bridge),\n XtermConsole.layer(bridge),\n FileSystem.layerNoop({}),\n Path.layer,\n XtermStdio.layer(bridge),\n Layer.succeed(ChildProcessSpawner.ChildProcessSpawner)(\n ChildProcessSpawner.make(() => Effect.die(new Error(UNAVAILABLE))),\n ),\n );\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport type { IDisposable, Terminal as XtermTerminal } from '@xterm/xterm';\nimport type * as Terminal from 'effect/Terminal';\n\nimport { decodeInput } from './input.ts';\n\nexport type InputHandler = (input: Terminal.UserInput) => void;\n\n/**\n * The surface the shell and the Effect `Terminal` service need from a terminal: a write sink and a\n * stack of keypress subscribers. Depending on this rather than the xterm class keeps the rest of\n * this module free of any renderer.\n */\nexport interface TerminalBridge {\n readonly columns: number;\n readonly rows: number;\n readonly atLineStart: boolean;\n /** How many writes have reached the terminal, so a caller can tell whether something printed. */\n readonly written: number;\n write(text: string): void;\n clear(): void;\n subscribe(handler: InputHandler): () => void;\n}\n\n/**\n * Adapts an xterm instance to {@link TerminalBridge}.\n */\nexport class XtermBridge implements TerminalBridge {\n #terminal: XtermTerminal;\n #subscribers: InputHandler[] = [];\n #subscription: IDisposable;\n #atLineStart = true;\n #written = 0;\n\n constructor(terminal: XtermTerminal) {\n this.#terminal = terminal;\n this.#subscription = terminal.onData((data) => this.#handleData(data));\n }\n\n get columns(): number {\n return this.#terminal.cols;\n }\n\n get rows(): number {\n return this.#terminal.rows;\n }\n\n /**\n * Whether the cursor sits at the start of a row, so callers can avoid a blank line when a command\n * has already terminated its output with a newline.\n */\n get atLineStart(): boolean {\n return this.#atLineStart;\n }\n\n get written(): number {\n return this.#written;\n }\n\n /**\n * Writes text, translating bare newlines to CRLF since xterm does not reset the column on `\\n`.\n */\n write(text: string): void {\n if (text.length === 0) {\n return;\n }\n\n this.#terminal.write(text.replace(/\\r?\\n/g, '\\r\\n'));\n this.#atLineStart = text.endsWith('\\n');\n this.#written++;\n }\n\n clear(): void {\n this.#terminal.write('\\x1b[2J\\x1b[H');\n this.#atLineStart = true;\n }\n\n /**\n * Subscribes to keypresses. The most recent subscriber wins, so a prompt opened by a running\n * command takes over from the shell's line editor and hands back when its scope closes.\n */\n subscribe(handler: InputHandler): () => void {\n this.#subscribers.push(handler);\n return () => {\n const index = this.#subscribers.indexOf(handler);\n if (index !== -1) {\n this.#subscribers.splice(index, 1);\n }\n };\n }\n\n dispose(): void {\n this.#subscription.dispose();\n this.#subscribers.length = 0;\n }\n\n #handleData(data: string): void {\n const handler = this.#subscribers.at(-1);\n if (!handler) {\n return;\n }\n\n for (const input of decodeInput(data)) {\n handler(input);\n }\n }\n}\n","//\n// Copyright 2026 DXOS.org\n//\n\n/**\n * Splits a raw input line into argv tokens. Supports single/double-quoted segments so quoted\n * strings with spaces survive. Intentionally simple — anything needing real shell semantics belongs\n * in a real shell.\n */\nexport const tokenize = (input: string): string[] => {\n const tokens: string[] = [];\n const regex = /\"([^\"]*)\"|'([^']*)'|(\\S+)/g;\n let match: RegExpExecArray | null;\n while ((match = regex.exec(input)) !== null) {\n tokens.push(match[1] ?? match[2] ?? match[3]);\n }\n\n return tokens;\n};\n\n/**\n * Translates shell-friendly aliases to their Effect CLI equivalents. The Effect CLI uses `--help`\n * rather than a `help` subcommand, but `help` and `?` are the natural things to type.\n */\nexport const rewriteHelpAliases = (tokens: ReadonlyArray<string>): string[] => {\n if (tokens.length === 0) {\n return [...tokens];\n }\n\n if (tokens[0] !== 'help' && tokens[0] !== '?') {\n return [...tokens];\n }\n\n return tokens.length === 1 ? ['--help'] : [...tokens.slice(1), '--help'];\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Cause from 'effect/Cause';\nimport * as CliError from 'effect/cli/CliError';\nimport * as Command from 'effect/cli/Command';\nimport * as Console from 'effect/Console';\nimport * as Effect from 'effect/Effect';\nimport * as Option from 'effect/Option';\n\nimport type { TerminalBridge } from './bridge.ts';\nimport { readLineResult } from './line-editor.ts';\nimport { rewriteHelpAliases, tokenize } from './tokenize.ts';\n\nconst EXIT_COMMANDS = ['exit', 'quit'];\n\n/** The services CLI parsing and execution need. */\nexport type CliEnvironment = Command.Environment;\n\nexport type ShellOptions<Name extends string, Input, ContextInput, E, R> = {\n command: Command.Command<Name, Input, ContextInput, E, R>;\n /** Executable name, used in the prompt. */\n name?: string;\n version?: string;\n prompt?: string;\n banner?: string;\n};\n\n/**\n * Runs a read-eval-print loop against an Effect CLI command tree.\n *\n * Each line is tokenized and dispatched through the same `Command.runWith` the binary uses. The\n * command tree and its layer are built once, so every command reuses the already-activated\n * services.\n */\nexport const runShell = <Name extends string, Input, ContextInput, E, R>(\n bridge: TerminalBridge,\n options: ShellOptions<Name, Input, ContextInput, E, R>,\n): Effect.Effect<void, never, R | CliEnvironment> =>\n Effect.gen(function* () {\n const { command, name = 'dx', version = '0.0.0', prompt = `${name}> `, banner } = options;\n const run = Command.runWith(command, { version });\n const history: string[] = [];\n\n if (banner) {\n bridge.write(`${banner}\\n`);\n }\n\n while (true) {\n if (!bridge.atLineStart) {\n bridge.write('\\n');\n }\n\n const result = yield* readLineResult(bridge, { prompt, history });\n if (result.type === 'eof') {\n break;\n }\n if (result.type === 'cancelled') {\n continue;\n }\n\n const line = result.value.trim();\n if (line.length === 0) {\n continue;\n }\n if (EXIT_COMMANDS.includes(line)) {\n break;\n }\n\n history.push(line);\n const tokens = rewriteHelpAliases(tokenize(line));\n if (tokens.length === 0) {\n continue;\n }\n\n const writtenBefore = bridge.written;\n\n // Failures are reported rather than propagated so the shell survives to the next prompt.\n // CLI errors are skipped because the parser has already rendered them.\n yield* run(tokens).pipe(\n Effect.catchCause((cause) => {\n if (Cause.hasInterruptsOnly(cause)) {\n return Effect.void;\n }\n\n // A CLI error has already been rendered to stdout by the runner (help, usage), so\n // repeating it as a stack would only be noise.\n const error = Cause.findErrorOption(cause);\n if (Option.isSome(error) && CliError.isCliError(error.value)) {\n return Effect.void;\n }\n\n return Console.error(Cause.pretty(cause));\n }),\n );\n\n // A blank line after a response sets it apart from the next prompt; a command that printed\n // nothing gets none, or every silent command would leave a gap.\n if (bridge.written > writtenBefore) {\n bridge.write(bridge.atLineStart ? '\\n' : '\\n\\n');\n }\n }\n\n bridge.write('\\n');\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAM,QAAQ;AAGd,IAAM,MAAM;AACZ,IAAM,SAAS;AACf,IAAM,SAAS;AACf,IAAM,UAAU;AAChB,IAAM,OAAO;AAGb,IAAM,QAAQ;;;;;AAMd,IAAa,aAAa,SAA0B;CAClD,MAAM,UAAU,KAAK,KAAK;CAC1B,IAAI,CAAC,QAAQ,KAAK,OAAO,GACvB;CAGF,IAAI;EACF,OAAO,KAAK,MAAM,OAAO;CAC3B,QAAQ;EACN;CACF;AACF;;AAGA,IAAa,iBAAiB,WAC3B,KAAK,UAAU,OAAO,MAAM,CAAC,KAAK,OAAO,KAAK,EAAA,CAAG,QAAQ,QAAQ,OAAO,QAAiB,UAAmB;CAC3G,IAAI,WAAW,KAAA,GACb,OAAO,UAAU,KAAA,IAAY,GAAG,MAAM,SAAS,QAAQ,UAAU,GAAG,SAAS,SAAS;CAExF,IAAI,UAAU,UAAU,U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O,KAAK,CAAC;EAC1C,CAAC,CACH;EAIA,IAAI,OAAO,UAAU,eACnB,OAAO,MAAM,OAAO,cAAc,OAAO,MAAM;CAEnD;CAEA,OAAO,MAAM,IAAI;AACnB,CAAC"}
|
package/dist/lib/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { FitAddon } from "@xterm/addon-fit";
|
|
|
4
4
|
import { Terminal as Terminal$1 } from "@xterm/xterm";
|
|
5
5
|
import * as Effect from "effect/Effect";
|
|
6
6
|
import * as Fiber from "effect/Fiber";
|
|
7
|
-
import { useEffect, useRef } from "react";
|
|
7
|
+
import { useEffect, useImperativeHandle, useRef } from "react";
|
|
8
8
|
import { mx } from "@dxos/ui-theme";
|
|
9
9
|
import { jsx } from "react/jsx-runtime";
|
|
10
10
|
//#region src/components/Terminal/theme.ts
|
|
@@ -14,22 +14,22 @@ import { jsx } from "react/jsx-runtime";
|
|
|
14
14
|
* slots step through the greys so dim output stays legible against the surface.
|
|
15
15
|
*/
|
|
16
16
|
var ANSI_TOKENS = {
|
|
17
|
-
black: "--color-
|
|
17
|
+
black: "--color-fg-subtle",
|
|
18
18
|
red: "--color-red-text",
|
|
19
19
|
green: "--color-green-text",
|
|
20
20
|
yellow: "--color-yellow-text",
|
|
21
21
|
blue: "--color-blue-text",
|
|
22
22
|
magenta: "--color-fuchsia-text",
|
|
23
23
|
cyan: "--color-cyan-text",
|
|
24
|
-
white: "--color-
|
|
25
|
-
brightBlack: "--color-
|
|
24
|
+
white: "--color-fg-muted",
|
|
25
|
+
brightBlack: "--color-fg-muted",
|
|
26
26
|
brightRed: "--color-red-text",
|
|
27
27
|
brightGreen: "--color-green-text",
|
|
28
28
|
brightYellow: "--color-yellow-text",
|
|
29
29
|
brightBlue: "--color-blue-text",
|
|
30
30
|
brightMagenta: "--color-fuchsia-text",
|
|
31
31
|
brightCyan: "--color-cyan-text",
|
|
32
|
-
brightWhite: "--color-
|
|
32
|
+
brightWhite: "--color-fg"
|
|
33
33
|
};
|
|
34
34
|
/**
|
|
35
35
|
* Resolves design system color tokens to the hex form xterm's parser accepts.
|
|
@@ -44,6 +44,7 @@ var makeResolver = (scope) => {
|
|
|
44
44
|
scope.appendChild(probe);
|
|
45
45
|
const context = document.createElement("canvas").getContext("2d", { willReadFrequently: true });
|
|
46
46
|
const resolve = (token) => {
|
|
47
|
+
if (getComputedStyle(probe).getPropertyValue(token).trim().length === 0) return;
|
|
47
48
|
probe.style.color = `var(${token})`;
|
|
48
49
|
const computed = getComputedStyle(probe).color;
|
|
49
50
|
if (!context || computed.length === 0) return;
|
|
@@ -70,14 +71,14 @@ var createXtermTheme = (element) => {
|
|
|
70
71
|
const { resolve, dispose } = makeResolver(element);
|
|
71
72
|
try {
|
|
72
73
|
const surface = resolve("--color-base-surface");
|
|
73
|
-
const foreground = resolve("--color-
|
|
74
|
+
const foreground = resolve("--color-fg");
|
|
74
75
|
const ansi = Object.fromEntries(Object.entries(ANSI_TOKENS).map(([slot, token]) => [slot, resolve(token)]));
|
|
75
76
|
return {
|
|
76
77
|
background: surface,
|
|
77
78
|
foreground,
|
|
78
79
|
cursor: foreground,
|
|
79
80
|
cursorAccent: surface,
|
|
80
|
-
selectionBackground: resolve("--color-
|
|
81
|
+
selectionBackground: resolve("--color-cm-focused-selection"),
|
|
81
82
|
...ansi
|
|
82
83
|
};
|
|
83
84
|
} finally {
|
|
@@ -92,8 +93,13 @@ var createXtermTheme = (element) => {
|
|
|
92
93
|
* The command tree and its layer are built once per mount, so state held by the services (a DXOS
|
|
93
94
|
* client, for instance) persists across commands the way it does in a long-lived shell.
|
|
94
95
|
*/
|
|
95
|
-
var Terminal = ({ classNames, command, layer: layer$1, name, version, prompt, banner, fontSize = 13 }) => {
|
|
96
|
+
var Terminal = ({ ref, classNames, command, layer: layer$1, name, version, prompt, banner, fontSize = 13, dimensions }) => {
|
|
96
97
|
const containerRef = useRef(null);
|
|
98
|
+
const xtermRef = useRef(null);
|
|
99
|
+
useImperativeHandle(ref, () => ({
|
|
100
|
+
clear: () => xtermRef.current?.clear(),
|
|
101
|
+
focus: () => xtermRef.current?.focus()
|
|
102
|
+
}), []);
|
|
97
103
|
useEffect(() => {
|
|
98
104
|
const container = containerRef.current;
|
|
99
105
|
if (!container) return;
|
|
@@ -101,13 +107,14 @@ var Terminal = ({ classNames, command, layer: layer$1, name, version, prompt, ba
|
|
|
101
107
|
const xterm = new Terminal$1({
|
|
102
108
|
fontSize,
|
|
103
109
|
fontFamily: styles.getPropertyValue("--font-mono").trim() || "monospace",
|
|
104
|
-
cursorBlink: true
|
|
110
|
+
cursorBlink: true,
|
|
111
|
+
...dimensions
|
|
105
112
|
});
|
|
106
|
-
const fitAddon = new FitAddon();
|
|
107
|
-
xterm.loadAddon(fitAddon);
|
|
113
|
+
const fitAddon = dimensions ? void 0 : new FitAddon();
|
|
114
|
+
if (fitAddon) xterm.loadAddon(fitAddon);
|
|
108
115
|
xterm.open(container);
|
|
109
116
|
const fit = () => {
|
|
110
|
-
if (container.clientWidth > 0 && container.clientHeight > 0) fitAddon.fit();
|
|
117
|
+
if (fitAddon && container.clientWidth > 0 && container.clientHeight > 0) fitAddon.fit();
|
|
111
118
|
};
|
|
112
119
|
const applyTheme = () => {
|
|
113
120
|
xterm.options.theme = createXtermTheme(container);
|
|
@@ -119,6 +126,7 @@ var Terminal = ({ classNames, command, layer: layer$1, name, version, prompt, ba
|
|
|
119
126
|
attributeFilter: ["class", "style"]
|
|
120
127
|
});
|
|
121
128
|
xterm.focus();
|
|
129
|
+
xtermRef.current = xterm;
|
|
122
130
|
const bridge = new XtermBridge(xterm);
|
|
123
131
|
const shell = runShell(bridge, {
|
|
124
132
|
command,
|
|
@@ -131,6 +139,7 @@ var Terminal = ({ classNames, command, layer: layer$1, name, version, prompt, ba
|
|
|
131
139
|
const observer = new ResizeObserver(fit);
|
|
132
140
|
observer.observe(container);
|
|
133
141
|
return () => {
|
|
142
|
+
xtermRef.current = null;
|
|
134
143
|
cancelAnimationFrame(frame);
|
|
135
144
|
themeObserver.disconnect();
|
|
136
145
|
observer.disconnect();
|
|
@@ -146,11 +155,13 @@ var Terminal = ({ classNames, command, layer: layer$1, name, version, prompt, ba
|
|
|
146
155
|
version,
|
|
147
156
|
prompt,
|
|
148
157
|
banner,
|
|
149
|
-
fontSize
|
|
158
|
+
fontSize,
|
|
159
|
+
dimensions?.cols,
|
|
160
|
+
dimensions?.rows
|
|
150
161
|
]);
|
|
151
162
|
return /* @__PURE__ */ jsx("div", {
|
|
152
|
-
|
|
153
|
-
|
|
163
|
+
className: mx("p-1 overflow-hidden", dimensions ? "w-max h-max" : "grow dx-fill", classNames),
|
|
164
|
+
ref: containerRef
|
|
154
165
|
});
|
|
155
166
|
};
|
|
156
167
|
//#endregion
|
package/dist/lib/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/components/Terminal/theme.ts","../../src/components/Terminal/Terminal.tsx"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport type { ITheme } from '@xterm/xterm';\n\n/**\n * ANSI slots mapped onto the design system's semantic hues. The theme carries one text weight per\n * hue, so a bright slot reuses its base token rather than inventing a second shade; the neutral\n * slots step through the greys so dim output stays legible against the surface.\n */\nconst ANSI_TOKENS = {\n black: '--color-subdued',\n red: '--color-red-text',\n green: '--color-green-text',\n yellow: '--color-yellow-text',\n blue: '--color-blue-text',\n magenta: '--color-fuchsia-text',\n cyan: '--color-cyan-text',\n white: '--color-description',\n brightBlack: '--color-description',\n brightRed: '--color-red-text',\n brightGreen: '--color-green-text',\n brightYellow: '--color-yellow-text',\n brightBlue: '--color-blue-text',\n brightMagenta: '--color-fuchsia-text',\n brightCyan: '--color-cyan-text',\n brightWhite: '--color-base-fg',\n} as const;\n\n/**\n * Resolves design system color tokens to the hex form xterm's parser accepts.\n *\n * Two steps, because neither alone suffices: a probe element inside the token scope turns\n * `light-dark(var(…))` into an absolute computed color, then a canvas rasterizes that color — which\n * the theme states in `oklch()` — down to sRGB channels.\n */\nconst makeResolver = (scope: Element) => {\n const probe = document.createElement('span');\n probe.style.display = 'none';\n scope.appendChild(probe);\n\n const context = document.createElement('canvas').getContext('2d', { willReadFrequently: true });\n\n const resolve = (token: string): string | undefined => {\n probe.style.color = `var(${token})`;\n const computed = getComputedStyle(probe).color;\n if (!context || computed.length === 0) {\n return undefined;\n }\n\n context.clearRect(0, 0, 1, 1);\n context.fillStyle = computed;\n context.fillRect(0, 0, 1, 1);\n const [red, green, blue] = context.getImageData(0, 0, 1, 1).data;\n return `#${[red, green, blue].map((channel) => channel.toString(16).padStart(2, '0')).join('')}`;\n };\n\n return { resolve, dispose: () => probe.remove() };\n};\n\n/**\n * Builds an xterm theme from the design system tokens in scope at `element`, so the terminal\n * follows light/dark and any theme override rather than carrying its own palette.\n */\nexport const createXtermTheme = (element: Element): ITheme => {\n const { resolve, dispose } = makeResolver(element);\n try {\n const surface = resolve('--color-base-surface');\n const foreground = resolve('--color-base-fg');\n const ansi = Object.fromEntries(Object.entries(ANSI_TOKENS).map(([slot, token]) => [slot, resolve(token)])) as Pick<\n ITheme,\n keyof typeof ANSI_TOKENS\n >;\n\n return {\n background: surface,\n foreground,\n cursor: foreground,\n cursorAccent: surface,\n selectionBackground: resolve('--color-accent-surface'),\n ...ansi,\n };\n } finally {\n dispose();\n }\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport '@xterm/xterm/css/xterm.css';\n\nimport { FitAddon } from '@xterm/addon-fit';\nimport { Terminal as Xterm } from '@xterm/xterm';\nimport * as Effect from 'effect/Effect';\nimport * as Fiber from 'effect/Fiber';\nimport type * as Layer from 'effect/Layer';\nimport type * as Command from 'effect/unstable/cli/Command';\nimport React, { useEffect, useRef } from 'react';\n\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport { mx } from '@dxos/ui-theme';\n\nimport { XtermBridge, XtermContext, runShell } from '../../cli';\nimport { createXtermTheme } from './theme';\n\nexport type TerminalProps<Name extends string, Input, ContextInput, E, R> = ThemedClassName<{\n /**\n * Root of an Effect CLI command tree; typically built with `Command.withSubcommands`.\n */\n command: Command.Command<Name, Input, ContextInput, E, R>;\n /**\n * Services the command handlers need beyond the platform services provided internally, which is\n * why the terminal's own environment is excluded from what this must supply.\n *\n * Construction must not fail: the shell runs on a forked fiber with no surface to report a layer\n * error on, so a host that can fail to build its services has to resolve that before mounting.\n */\n layer: Layer.Layer<Exclude<R, XtermContext.Provided>, never, never>;\n name?: string;\n version?: string;\n prompt?: string;\n banner?: string;\n fontSize?: number;\n}>;\n\n/**\n * Terminal emulator hosting an Effect CLI command tree entirely in the browser.\n *\n * The command tree and its layer are built once per mount, so state held by the services (a DXOS\n * client, for instance) persists across commands the way it does in a long-lived shell.\n */\nexport const Terminal = <Name extends string, Input, ContextInput, E, R>({\n classNames,\n command,\n layer,\n name,\n version,\n prompt,\n banner,\n fontSize = 13,\n}: TerminalProps<Name, Input, ContextInput, E, R>) => {\n const containerRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const container = containerRef.current;\n if (!container) {\n return;\n }\n\n // The face must come from the mono token rather than the container, whose inherited UI face is\n // proportional and would leave xterm's fixed cells ragged.\n const styles = getComputedStyle(container);\n const xterm = new Xterm({\n fontSize,\n fontFamily: styles.getPropertyValue('--font-mono').trim() || 'monospace',\n cursorBlink: true,\n });\n\n const fitAddon = new FitAddon();\n xterm.loadAddon(fitAddon);\n xterm.open(container);\n\n // Fitting a zero-sized container pins the terminal to its one-column minimum, and fitting\n // before xterm's render service exists throws, so the observer's initial callback — which\n // lands once the element is measurable and the renderer is up — drives the first fit too.\n const fit = () => {\n if (container.clientWidth > 0 && container.clientHeight > 0) {\n fitAddon.fit();\n }\n };\n\n // Drive the palette from the design system tokens so the terminal tracks light/dark without a\n // scheme of its own. The theme class lands on the document from a provider whose effect runs\n // after this one, so the palette is applied on the next frame and refreshed on every change.\n const applyTheme = () => {\n xterm.options.theme = createXtermTheme(container);\n };\n\n const frame = requestAnimationFrame(applyTheme);\n const themeObserver = new MutationObserver(applyTheme);\n themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['class', 'style'] });\n\n xterm.focus();\n\n const bridge = new XtermBridge(xterm);\n const shell = runShell(bridge, { command, name, version, prompt, banner }).pipe(\n Effect.provide(XtermContext.layer(bridge)),\n Effect.provide(layer),\n );\n const fiber = Effect.runFork(Effect.scoped(shell));\n\n const observer = new ResizeObserver(fit);\n observer.observe(container);\n\n return () => {\n cancelAnimationFrame(frame);\n themeObserver.disconnect();\n observer.disconnect();\n // Disposal is chained onto the interrupt rather than run beside it: the shell's finalizers\n // still write their last output through the bridge, which throws once xterm is gone.\n Effect.runFork(\n Fiber.interrupt(fiber).pipe(\n Effect.andThen(\n Effect.sync(() => {\n bridge.dispose();\n xterm.dispose();\n }),\n ),\n ),\n );\n };\n }, [command, layer, name, version, prompt, banner, fontSize]);\n\n return <div ref={containerRef} className={mx('grow w-full h-full overflow-hidden bg-base-surface', classNames)} />;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAWA,IAAM,cAAc;CAClB,OAAO;CACP,KAAK;CACL,OAAO;CACP,QAAQ;CACR,MAAM;CACN,SAAS;CACT,MAAM;CACN,OAAO;CACP,aAAa;CACb,WAAW;CACX,aAAa;CACb,cAAc;CACd,YAAY;CACZ,eAAe;CACf,YAAY;CACZ,aAAa;AACf;;;;;;;;AASA,IAAM,gBAAgB,UAAmB;CACvC,MAAM,QAAQ,SAAS,cAAc,MAAM;CAC3C,MAAM,MAAM,UAAU;CACtB,MAAM,YAAY,KAAK;CAEvB,MAAM,UAAU,SAAS,cAAc,QAAQ,CAAC,CAAC,WAAW,MAAM,EAAE,oBAAoB,KAAK,CAAC;CAE9F,MAAM,WAAW,UAAsC;EACrD,MAAM,MAAM,QAAQ,OAAO,MAAM;EACjC,MAAM,WAAW,iBAAiB,KAAK,CAAC,CAAC;EACzC,IAAI,CAAC,WAAW,SAAS,WAAW,GAClC;EAGF,QAAQ,UAAU,GAAG,GAAG,GAAG,CAAC;EAC5B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AU,eAAe,GACxD,SAAS,IAAI;EAEjB;EAKA,MAAM,mBAAmB;GACvB,MAAM,QAAQ,QAAQ,iBAAiB,SAAS;EAClD;EAEA,MAAM,QAAQ,sBAAsB,UAAU;EAC9C,MAAM,gBAAgB,IAAI,iBAAiB,UAAU;EACrD,cAAc,QAAQ,SAAS,iBAAiB;GAAE,YAAY;GAAM,iBAAiB,CAAC,SAAS,OAAO;EAAE,CAAC;EAEzG,MAAM,MAAM;EAEZ,MAAM,SAAS,IAAI,YAAY,KAAK;EACpC,MAAM,QAAQ,SAAS,QAAQ;GAAE;GAAS;GAAM;GAAS;GAAQ;EAAO,CAAC,CAAC,CAAC,KACzE,OAAO,QAAQ,MAAmB,MAAM,CAAC,GACzC,OAAO,QAAQ,OAAK,CACtB;EACA,MAAM,QAAQ,OAAO,QAAQ,OAAO,OAAO,KAAK,CAAC;EAEjD,MAAM,WAAW,IAAI,eAAe,GAAG;EACvC,SAAS,QAAQ,SAAS;EAE1B,aAAa;GACX,qBAAqB,KAAK;GAC1B,cAAc,WAAW;GACzB,SAAS,WAAW;GAGpB,OAAO,QACL,MAAM,UAAU,KAAK,CAAC,CAAC,KACrB,OAAO,QACL,OAAO,WAAW;IAChB,OAAO,QAAQ;IACf,MAAM,QAAQ;GAChB,CAAC,CACH,CACF,CACF;EACF;CACF,GAAG;EAAC;EAAS;EAAO;EAAM;EAAS;EAAQ;EAAQ;CAAQ,CAAC;CAE5D,OAAO,oBAAC,OAAD;EAAK,KAAK;EAAc,WAAW,GAAG,sDAAsD,UAAU;CAAI,CAAA;AACnH"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/components/Terminal/theme.ts","../../src/components/Terminal/Terminal.tsx"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport type { ITheme } from '@xterm/xterm';\n\n/**\n * ANSI slots mapped onto the design system's semantic hues. The theme carries one text weight per\n * hue, so a bright slot reuses its base token rather than inventing a second shade; the neutral\n * slots step through the greys so dim output stays legible against the surface.\n */\nconst ANSI_TOKENS = {\n black: '--color-fg-subtle',\n red: '--color-red-text',\n green: '--color-green-text',\n yellow: '--color-yellow-text',\n blue: '--color-blue-text',\n magenta: '--color-fuchsia-text',\n cyan: '--color-cyan-text',\n white: '--color-fg-muted',\n brightBlack: '--color-fg-muted',\n brightRed: '--color-red-text',\n brightGreen: '--color-green-text',\n brightYellow: '--color-yellow-text',\n brightBlue: '--color-blue-text',\n brightMagenta: '--color-fuchsia-text',\n brightCyan: '--color-cyan-text',\n brightWhite: '--color-fg',\n} as const;\n\n/**\n * Resolves design system color tokens to the hex form xterm's parser accepts.\n *\n * Two steps, because neither alone suffices: a probe element inside the token scope turns\n * `light-dark(var(…))` into an absolute computed color, then a canvas rasterizes that color — which\n * the theme states in `oklch()` — down to sRGB channels.\n */\nconst makeResolver = (scope: Element) => {\n const probe = document.createElement('span');\n probe.style.display = 'none';\n scope.appendChild(probe);\n\n const context = document.createElement('canvas').getContext('2d', { willReadFrequently: true });\n\n const resolve = (token: string): string | undefined => {\n // An undefined token makes `color` fall back to the inherited text color, which would pass as a\n // real value — the selection then matched the text and hid it — so it resolves to nothing instead.\n if (getComputedStyle(probe).getPropertyValue(token).trim().length === 0) {\n return undefined;\n }\n\n probe.style.color = `var(${token})`;\n const computed = getComputedStyle(probe).color;\n if (!context || computed.length === 0) {\n return undefined;\n }\n\n context.clearRect(0, 0, 1, 1);\n context.fillStyle = computed;\n context.fillRect(0, 0, 1, 1);\n const [red, green, blue] = context.getImageData(0, 0, 1, 1).data;\n return `#${[red, green, blue].map((channel) => channel.toString(16).padStart(2, '0')).join('')}`;\n };\n\n return { resolve, dispose: () => probe.remove() };\n};\n\n/**\n * Builds an xterm theme from the design system tokens in scope at `element`, so the terminal\n * follows light/dark and any theme override rather than carrying its own palette.\n */\nexport const createXtermTheme = (element: Element): ITheme => {\n const { resolve, dispose } = makeResolver(element);\n try {\n const surface = resolve('--color-base-surface');\n const foreground = resolve('--color-fg');\n const ansi = Object.fromEntries(Object.entries(ANSI_TOKENS).map(([slot, token]) => [slot, resolve(token)])) as Pick<\n ITheme,\n keyof typeof ANSI_TOKENS\n >;\n\n return {\n background: surface,\n foreground,\n cursor: foreground,\n cursorAccent: surface,\n // The editor's selection, so selected terminal text looks like selected text elsewhere; opaque,\n // since the resolver drops alpha and a translucent token would come out solid.\n selectionBackground: resolve('--color-cm-focused-selection'),\n ...ansi,\n };\n } finally {\n dispose();\n }\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport '@xterm/xterm/css/xterm.css';\n\nimport { FitAddon } from '@xterm/addon-fit';\nimport { Terminal as Xterm } from '@xterm/xterm';\nimport type * as Command from 'effect/cli/Command';\nimport * as Effect from 'effect/Effect';\nimport * as Fiber from 'effect/Fiber';\nimport type * as Layer from 'effect/Layer';\nimport React, { type Ref, useEffect, useImperativeHandle, useRef } from 'react';\n\nimport type * as Util from '@dxos/react-ui/Util';\nimport { mx } from '@dxos/ui-theme';\n\nimport { XtermBridge, XtermContext, runShell } from '../../cli/index.ts';\nimport { createXtermTheme } from './theme.ts';\n\n/** Imperative surface for hosts that render controls beside the terminal (a clear button, e.g.). */\nexport type TerminalApi = {\n clear: () => void;\n focus: () => void;\n};\n\nexport type TerminalProps<Name extends string, Input, ContextInput, E, R> = Util.ThemedClassName<{\n /** Publishes the {@link TerminalApi} while mounted. */\n ref?: Ref<TerminalApi>;\n /**\n * Root of an Effect CLI command tree; typically built with `Command.withSubcommands`.\n */\n command: Command.Command<Name, Input, ContextInput, E, R>;\n /**\n * Services the command handlers need beyond the platform services provided internally, which is\n * why the terminal's own environment is excluded from what this must supply.\n *\n * Construction must not fail: the shell runs on a forked fiber with no surface to report a layer\n * error on, so a host that can fail to build its services has to resolve that before mounting.\n */\n layer: Layer.Layer<Exclude<R, XtermContext.Provided>, never, never>;\n name?: string;\n version?: string;\n prompt?: string;\n banner?: string;\n fontSize?: number;\n /**\n * Fixed cell grid. With this the terminal renders exactly `cols × rows` and the element hugs the\n * grid, so a host sized by its content (a popover) shows no rounding slack; without it the\n * terminal fits itself to the container, whose trailing partial cells read as a gap.\n */\n dimensions?: { cols: number; rows: number };\n}>;\n\n/**\n * Terminal emulator hosting an Effect CLI command tree entirely in the browser.\n *\n * The command tree and its layer are built once per mount, so state held by the services (a DXOS\n * client, for instance) persists across commands the way it does in a long-lived shell.\n */\nexport const Terminal = <Name extends string, Input, ContextInput, E, R>({\n ref,\n classNames,\n command,\n layer,\n name,\n version,\n prompt,\n banner,\n fontSize = 13,\n dimensions,\n}: TerminalProps<Name, Input, ContextInput, E, R>) => {\n const containerRef = useRef<HTMLDivElement>(null);\n\n // The instance is reached through a ref rather than published from the effect, so a host taking a\n // new ref object on re-render re-reads it without the terminal being torn down and rebuilt.\n const xtermRef = useRef<Xterm | null>(null);\n useImperativeHandle(\n ref,\n () => ({\n clear: () => xtermRef.current?.clear(),\n focus: () => xtermRef.current?.focus(),\n }),\n [],\n );\n\n useEffect(() => {\n const container = containerRef.current;\n if (!container) {\n return;\n }\n\n // The face must come from the mono token rather than the container, whose inherited UI face is\n // proportional and would leave xterm's fixed cells ragged.\n const styles = getComputedStyle(container);\n const xterm = new Xterm({\n fontSize,\n fontFamily: styles.getPropertyValue('--font-mono').trim() || 'monospace',\n cursorBlink: true,\n ...dimensions,\n });\n\n // Fixed-grid mode needs no fitting: the terminal is its own size and the host hugs it.\n const fitAddon = dimensions ? undefined : new FitAddon();\n if (fitAddon) {\n xterm.loadAddon(fitAddon);\n }\n xterm.open(container);\n\n // Fitting a zero-sized container pins the terminal to its one-column minimum, and fitting\n // before xterm's render service exists throws, so the observer's initial callback — which\n // lands once the element is measurable and the renderer is up — drives the first fit too.\n const fit = () => {\n if (fitAddon && container.clientWidth > 0 && container.clientHeight > 0) {\n fitAddon.fit();\n }\n };\n\n // Drive the palette from the design system tokens so the terminal tracks light/dark without a\n // scheme of its own. The theme class lands on the document from a provider whose effect runs\n // after this one, so the palette is applied on the next frame and refreshed on every change.\n const applyTheme = () => {\n xterm.options.theme = createXtermTheme(container);\n };\n\n const frame = requestAnimationFrame(applyTheme);\n const themeObserver = new MutationObserver(applyTheme);\n themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['class', 'style'] });\n\n xterm.focus();\n xtermRef.current = xterm;\n\n const bridge = new XtermBridge(xterm);\n const shell = runShell(bridge, { command, name, version, prompt, banner }).pipe(\n // `R` is generic here, so the checker can discharge `Exclude<R, XtermContext.Provided>` only\n // one provide at a time; any combined form leaves the requirement unsolved.\n // @effect-diagnostics-next-line multipleEffectProvide:off\n Effect.provide(XtermContext.layer(bridge)),\n Effect.provide(layer),\n );\n const fiber = Effect.runFork(Effect.scoped(shell));\n\n const observer = new ResizeObserver(fit);\n observer.observe(container);\n\n return () => {\n xtermRef.current = null;\n cancelAnimationFrame(frame);\n themeObserver.disconnect();\n observer.disconnect();\n // Disposal is chained onto the interrupt rather than run beside it: the shell's finalizers\n // still write their last output through the bridge, which throws once xterm is gone.\n Effect.runFork(\n Fiber.interrupt(fiber).pipe(\n Effect.andThen(\n Effect.sync(() => {\n bridge.dispose();\n xterm.dispose();\n }),\n ),\n ),\n );\n };\n }, [command, layer, name, version, prompt, banner, fontSize, dimensions?.cols, dimensions?.rows]);\n\n return (\n <div\n className={mx('p-1 overflow-hidden', dimensions ? 'w-max h-max' : 'grow dx-fill', classNames)}\n ref={containerRef}\n />\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;AAWA,IAAM,cAAc;CAClB,OAAO;CACP,KAAK;CACL,OAAO;CACP,QAAQ;CACR,MAAM;CACN,SAAS;CACT,MAAM;CACN,OAAO;CACP,aAAa;CACb,WAAW;CACX,aAAa;CACb,cAAc;CACd,YAAY;CACZ,eAAe;CACf,YAAY;CACZ,aAAa;AACf;;;;;;;;AASA,IAAM,gBAAgB,UAAmB;CACvC,MAAM,QAAQ,SAAS,cAAc,MAAM;CAC3C,MAAM,MAAM,UAAU;CACtB,MAAM,YAAY,KAAK;CAEvB,MAAM,UAAU,SAAS,cAAc,Q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,SAAS,WAAW;GAGpB,OAAO,QACL,MAAM,UAAU,KAAK,CAAC,CAAC,KACrB,OAAO,QACL,OAAO,WAAW;IAChB,OAAO,QAAQ;IACf,MAAM,QAAQ;GAChB,CAAC,CACH,CACF,CACF;EACF;CACF,GAAG;EAAC;EAAS;EAAO;EAAM;EAAS;EAAQ;EAAQ;EAAU,YAAY;EAAM,YAAY;CAAI,CAAC;CAEhG,OACE,oBAAC,OAAD;EACE,WAAW,GAAG,uBAAuB,aAAa,gBAAgB,gBAAgB,UAAU;EAC5F,KAAK;CACN,CAAA;AAEL"}
|
package/dist/lib/testing.mjs
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
2
|
import * as Duration from "effect/Duration";
|
|
3
|
-
import
|
|
3
|
+
import * as EffectEx from "@dxos/effect/EffectEx";
|
|
4
|
+
import { BaseError } from "@dxos/errors";
|
|
5
|
+
//#region src/errors.ts
|
|
6
|
+
/** Terminal harness failed. The underlying failure, where there is one, is the `cause`. */
|
|
7
|
+
var TerminalTestError = class extends BaseError.extend("TerminalTestError", "Terminal harness failed.") {};
|
|
8
|
+
//#endregion
|
|
4
9
|
//#region src/testing.ts
|
|
5
10
|
var POLL_INTERVAL = Duration.millis(50);
|
|
6
11
|
var DEFAULT_TIMEOUT = Duration.seconds(15);
|
|
@@ -24,7 +29,7 @@ var pollTerminal = (element, text) => Effect.suspend(() => readTerminal(element)
|
|
|
24
29
|
*/
|
|
25
30
|
var waitForTerminal = (element, text, timeout = DEFAULT_TIMEOUT) => EffectEx.runPromise(pollTerminal(element, text).pipe(Effect.timeoutOrElse({
|
|
26
31
|
duration: timeout,
|
|
27
|
-
orElse: () => Effect.fail(
|
|
32
|
+
orElse: () => Effect.fail(new TerminalTestError({ message: `Timed out waiting for "${text}". Terminal contents:\n${readTerminal(element)}` }))
|
|
28
33
|
})));
|
|
29
34
|
/**
|
|
30
35
|
* Types a command and submits it.
|
package/dist/lib/testing.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.mjs","names":[],"sources":["../../src/testing.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Duration from 'effect/Duration';\nimport * as Effect from 'effect/Effect';\n\nimport
|
|
1
|
+
{"version":3,"file":"testing.mjs","names":[],"sources":["../../src/errors.ts","../../src/testing.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport { BaseError } from '@dxos/errors';\n\n/** Terminal harness failed. The underlying failure, where there is one, is the `cause`. */\nexport class TerminalTestError extends BaseError.extend('TerminalTestError', 'Terminal harness failed.') {}\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Duration from 'effect/Duration';\nimport * as Effect from 'effect/Effect';\n\nimport * as EffectEx from '@dxos/effect/EffectEx';\n\nimport { TerminalTestError } from './errors.ts';\n\nconst POLL_INTERVAL = Duration.millis(50);\nconst DEFAULT_TIMEOUT = Duration.seconds(15);\n\n/**\n * Reads the terminal's visible contents as plain text.\n *\n * xterm splits a row into a span per style run and pads with non-breaking spaces, so a story cannot\n * assert against it with a plain text query — this flattens a row back to what the user sees.\n */\nexport const readTerminal = (element: HTMLElement): string =>\n Array.from(element.querySelectorAll('.xterm-rows > div'))\n .map((row) => (row.textContent ?? '').replace(/\\u00a0/g, ' ').trimEnd())\n .join('\\n');\n\n/**\n * The hidden textarea xterm reads keystrokes from.\n */\nexport const getTerminalInput = (element: HTMLElement): HTMLTextAreaElement | null =>\n element.querySelector('.xterm-helper-textarea');\n\nconst pollTerminal = (element: HTMLElement, text: string): Effect.Effect<void> =>\n Effect.suspend(() =>\n readTerminal(element).includes(text)\n ? Effect.void\n : Effect.sleep(POLL_INTERVAL).pipe(Effect.flatMap(() => pollTerminal(element, text))),\n );\n\n/**\n * Resolves once the terminal shows `text`, or throws with the current contents.\n *\n * The terminal is painted by a fiber writing into the DOM, so there is nothing to await — polling\n * is the only way to observe it. Returns a promise because a story's `play` is the boundary.\n */\nexport const waitForTerminal = (element: HTMLElement, text: string, timeout = DEFAULT_TIMEOUT): Promise<void> =>\n EffectEx.runPromise(\n pollTerminal(element, text).pipe(\n Effect.timeoutOrElse({\n duration: timeout,\n orElse: () =>\n Effect.fail(\n new TerminalTestError({\n message: `Timed out waiting for \"${text}\". Terminal contents:\\n${readTerminal(element)}`,\n }),\n ),\n }),\n ),\n );\n\n/**\n * Types a command and submits it.\n *\n * Waits for the input to echo before sending the return, because the shell drops keystrokes that\n * arrive before its line editor has subscribed — without this the command silently never runs.\n */\nexport const runCommand = async (\n element: HTMLElement,\n command: string,\n keyboard: (text: string) => Promise<unknown>,\n): Promise<void> => {\n getTerminalInput(element)?.focus();\n await keyboard(command);\n await waitForTerminal(element, command);\n await keyboard('{Enter}');\n};\n"],"mappings":";;;;;;AAOA,IAAa,oBAAb,cAAuC,UAAU,OAAO,qBAAqB,0BAA0B,CAAC,CAAC,CAAC;;;ACI1G,IAAM,gBAAgB,SAAS,OAAO,EAAE;AACxC,IAAM,kBAAkB,SAAS,QAAQ,EAAE;;;;;;;AAQ3C,IAAa,gBAAgB,YAC3B,MAAM,KAAK,QAAQ,iBAAiB,mBAAmB,CAAC,CAAA,CACrD,KAAK,SAAS,IAAI,eAAe,GAAA,CAAI,QAAQ,WAAW,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAA,CACtE,KAAK,IAAI;;;;AAKd,IAAa,oBAAoB,YAC/B,QAAQ,cAAc,wBAAwB;AAEhD,IAAM,gBAAgB,SAAsB,SAC1C,OAAO,cACL,aAAa,OAAO,CAAC,CAAC,SAAS,IAAI,IAC/B,OAAO,OACP,OAAO,MAAM,aAAa,CAAC,CAAC,KAAK,OAAO,cAAc,aAAa,SAAS,IAAI,CAAC,CAAC,CACxF;;;;;;;AAQF,IAAa,mBAAmB,SAAsB,MAAc,UAAU,oBAC5E,SAAS,WACP,aAAa,SAAS,IAAI,CAAC,CAAC,KAC1B,OAAO,cAAc;CACnB,UAAU;CACV,cACE,OAAO,KACL,IAAI,kBAAkB,EACpB,SAAS,0BAA0B,KAAK,yBAAyB,aAAa,OAAO,IACvF,CAAC,CACH;AACJ,CAAC,CACH,CACF;;;;;;;AAQF,IAAa,aAAa,OACxB,SACA,SACA,aACkB;CAClB,iBAAiB,OAAO,CAAC,EAAE,MAAM;CACjC,MAAM,SAAS,OAAO;CACtB,MAAM,gBAAgB,SAAS,OAAO;CACtC,MAAM,SAAS,SAAS;AAC1B"}
|
|
@@ -10,6 +10,8 @@ export interface TerminalBridge {
|
|
|
10
10
|
readonly columns: number;
|
|
11
11
|
readonly rows: number;
|
|
12
12
|
readonly atLineStart: boolean;
|
|
13
|
+
/** How many writes have reached the terminal, so a caller can tell whether something printed. */
|
|
14
|
+
readonly written: number;
|
|
13
15
|
write(text: string): void;
|
|
14
16
|
clear(): void;
|
|
15
17
|
subscribe(handler: InputHandler): () => void;
|
|
@@ -27,6 +29,7 @@ export declare class XtermBridge implements TerminalBridge {
|
|
|
27
29
|
* has already terminated its output with a newline.
|
|
28
30
|
*/
|
|
29
31
|
get atLineStart(): boolean;
|
|
32
|
+
get written(): number;
|
|
30
33
|
/**
|
|
31
34
|
* Writes text, translating bare newlines to CRLF since xterm does not reset the column on `\n`.
|
|
32
35
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../../../src/cli/bridge.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAe,QAAQ,IAAI,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAIjD,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,SAAS,KAAK,IAAI,CAAC;AAE/D;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC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IAED;;;OAGG;IACH,SAAS,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,IAAI,CAQ3C;IAED,OAAO,IAAI,IAAI,CAGd;CAYF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../../../src/cli/console.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../../../src/cli/console.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AA2BlD;;;;;GAKG;AACH,eAAO,MAAM,IAAI,WAAY,cAAc,KAAG,OAAO,CAAC,OA6BrD,CAAC;AAEF,oEAAoE;AACpE,eAAO,MAAM,KAAK,WAAY,cAAc,KAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CACH,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type * as Command from 'effect/cli/Command';
|
|
1
2
|
import * as Layer from 'effect/Layer';
|
|
2
|
-
import type
|
|
3
|
-
import type { XtermBridge } from './bridge';
|
|
3
|
+
import type { TerminalBridge } from './bridge.ts';
|
|
4
4
|
/**
|
|
5
5
|
* The browser counterpart to `BunServices.layer`.
|
|
6
6
|
*
|
|
@@ -10,5 +10,5 @@ import type { XtermBridge } from './bridge';
|
|
|
10
10
|
* the CLI's ANSI help text land in the terminal instead of the devtools console.
|
|
11
11
|
*/
|
|
12
12
|
export type Provided = Command.Environment;
|
|
13
|
-
export declare const layer: (bridge:
|
|
13
|
+
export declare const layer: (bridge: TerminalBridge) => Layer.Layer<Provided>;
|
|
14
14
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/cli/context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/cli/context.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,OAAO,MAAM,oBAAoB,CAAC;AAGnD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAItC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAKlD;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;AAI3C,eAAO,MAAM,KAAK,WAAY,cAAc,KAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,CAUhE,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * as XtermConsole from './console';
|
|
2
|
-
export * as XtermContext from './context';
|
|
3
|
-
export * as XtermStdio from './stdio';
|
|
4
|
-
export * as XtermTerminal from './terminal';
|
|
5
|
-
export * from './bridge';
|
|
6
|
-
export * from './input';
|
|
7
|
-
export * from './line-editor';
|
|
8
|
-
export * from './shell';
|
|
9
|
-
export * from './tokenize';
|
|
1
|
+
export * as XtermConsole from './console.ts';
|
|
2
|
+
export * as XtermContext from './context.ts';
|
|
3
|
+
export * as XtermStdio from './stdio.ts';
|
|
4
|
+
export * as XtermTerminal from './terminal.ts';
|
|
5
|
+
export * from './bridge.ts';
|
|
6
|
+
export * from './input.ts';
|
|
7
|
+
export * from './line-editor.ts';
|
|
8
|
+
export * from './shell.ts';
|
|
9
|
+
export * from './tokenize.ts';
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,YAAY,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,YAAY,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,YAAY,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,UAAU,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,aAAa,MAAM,eAAe,CAAC;AAE/C,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The value `text` holds when it is a JSON object or array, else undefined. A bare scalar is valid
|
|
3
|
+
* JSON too, but reads as ordinary output, so only structured data is treated as JSON.
|
|
4
|
+
*/
|
|
5
|
+
export declare const parseJson: (text: string) => unknown;
|
|
6
|
+
/** Indented JSON with ANSI colors per token kind; stripped of its escapes it is `JSON.stringify(value, null, 2)`. */
|
|
7
|
+
export declare const highlightJson: (value: unknown) => string;
|
|
8
|
+
//# sourceMappingURL=json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../../src/cli/json.ts"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,eAAO,MAAM,SAAS,SAAU,MAAM,KAAG,OAWxC,CAAC;AAEF,qHAAqH;AACrH,eAAO,MAAM,aAAa,UAAW,OAAO,KAAG,MAY3C,CAAC"}
|