@dxos/react-ui-terminal 0.0.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 +500 -0
- package/dist/lib/chunk-cli.mjs.map +1 -0
- package/dist/lib/cli.mjs +2 -0
- package/dist/lib/index.mjs +157 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/lib/testing.mjs +41 -0
- package/dist/lib/testing.mjs.map +1 -0
- package/dist/types/src/cli/bridge.d.ts +42 -0
- package/dist/types/src/cli/bridge.d.ts.map +1 -0
- package/dist/types/src/cli/console.d.ts +16 -0
- package/dist/types/src/cli/console.d.ts.map +1 -0
- package/dist/types/src/cli/console.test.d.ts +2 -0
- package/dist/types/src/cli/console.test.d.ts.map +1 -0
- package/dist/types/src/cli/context.d.ts +17 -0
- package/dist/types/src/cli/context.d.ts.map +1 -0
- package/dist/types/src/cli/index.d.ts +9 -0
- package/dist/types/src/cli/index.d.ts.map +1 -0
- package/dist/types/src/cli/input.d.ts +14 -0
- package/dist/types/src/cli/input.d.ts.map +1 -0
- package/dist/types/src/cli/input.test.d.ts +2 -0
- package/dist/types/src/cli/input.test.d.ts.map +1 -0
- package/dist/types/src/cli/line-editor.d.ts +35 -0
- package/dist/types/src/cli/line-editor.d.ts.map +1 -0
- package/dist/types/src/cli/line-editor.test.d.ts +2 -0
- package/dist/types/src/cli/line-editor.test.d.ts.map +1 -0
- package/dist/types/src/cli/shell.d.ts +30 -0
- package/dist/types/src/cli/shell.d.ts.map +1 -0
- package/dist/types/src/cli/terminal.d.ts +12 -0
- package/dist/types/src/cli/terminal.d.ts.map +1 -0
- package/dist/types/src/cli/testing.d.ts +20 -0
- package/dist/types/src/cli/testing.d.ts.map +1 -0
- package/dist/types/src/cli/tokenize.d.ts +12 -0
- package/dist/types/src/cli/tokenize.d.ts.map +1 -0
- package/dist/types/src/components/Terminal/Terminal.d.ts +30 -0
- package/dist/types/src/components/Terminal/Terminal.d.ts.map +1 -0
- package/dist/types/src/components/Terminal/Terminal.stories.d.ts +18 -0
- package/dist/types/src/components/Terminal/Terminal.stories.d.ts.map +1 -0
- package/dist/types/src/components/Terminal/index.d.ts +2 -0
- package/dist/types/src/components/Terminal/index.d.ts.map +1 -0
- package/dist/types/src/components/Terminal/theme.d.ts +7 -0
- package/dist/types/src/components/Terminal/theme.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +2 -0
- package/dist/types/src/components/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/testing.d.ts +23 -0
- package/dist/types/src/testing.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +65 -0
- package/src/cli/bridge.ts +102 -0
- package/src/cli/console.test.ts +73 -0
- package/src/cli/console.ts +91 -0
- package/src/cli/context.ts +26 -0
- package/src/cli/index.ts +13 -0
- package/src/cli/input.test.ts +109 -0
- package/src/cli/input.ts +132 -0
- package/src/cli/line-editor.test.ts +141 -0
- package/src/cli/line-editor.ts +199 -0
- package/src/cli/shell.ts +103 -0
- package/src/cli/terminal.ts +43 -0
- package/src/cli/testing.ts +51 -0
- package/src/cli/tokenize.ts +35 -0
- package/src/components/Terminal/Terminal.stories.tsx +114 -0
- package/src/components/Terminal/Terminal.tsx +118 -0
- package/src/components/Terminal/index.ts +5 -0
- package/src/components/Terminal/theme.ts +87 -0
- package/src/components/index.ts +5 -0
- package/src/index.ts +5 -0
- package/src/testing.ts +56 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { i as XtermBridge, o as layer, t as runShell } from "./chunk-cli.mjs";
|
|
2
|
+
import "@xterm/xterm/css/xterm.css";
|
|
3
|
+
import { FitAddon } from "@xterm/addon-fit";
|
|
4
|
+
import { Terminal as Terminal$1 } from "@xterm/xterm";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Fiber from "effect/Fiber";
|
|
7
|
+
import { useEffect, useRef } from "react";
|
|
8
|
+
import { mx } from "@dxos/ui-theme";
|
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
//#region src/components/Terminal/theme.ts
|
|
11
|
+
/**
|
|
12
|
+
* ANSI slots mapped onto the design system's semantic hues. The theme carries one text weight per
|
|
13
|
+
* hue, so a bright slot reuses its base token rather than inventing a second shade; the neutral
|
|
14
|
+
* slots step through the greys so dim output stays legible against the surface.
|
|
15
|
+
*/
|
|
16
|
+
var ANSI_TOKENS = {
|
|
17
|
+
black: "--color-subdued",
|
|
18
|
+
red: "--color-red-text",
|
|
19
|
+
green: "--color-green-text",
|
|
20
|
+
yellow: "--color-yellow-text",
|
|
21
|
+
blue: "--color-blue-text",
|
|
22
|
+
magenta: "--color-fuchsia-text",
|
|
23
|
+
cyan: "--color-cyan-text",
|
|
24
|
+
white: "--color-description",
|
|
25
|
+
brightBlack: "--color-description",
|
|
26
|
+
brightRed: "--color-red-text",
|
|
27
|
+
brightGreen: "--color-green-text",
|
|
28
|
+
brightYellow: "--color-yellow-text",
|
|
29
|
+
brightBlue: "--color-blue-text",
|
|
30
|
+
brightMagenta: "--color-fuchsia-text",
|
|
31
|
+
brightCyan: "--color-cyan-text",
|
|
32
|
+
brightWhite: "--color-base-fg"
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Resolves design system color tokens to the hex form xterm's parser accepts.
|
|
36
|
+
*
|
|
37
|
+
* Two steps, because neither alone suffices: a probe element inside the token scope turns
|
|
38
|
+
* `light-dark(var(…))` into an absolute computed color, then a canvas rasterizes that color — which
|
|
39
|
+
* the theme states in `oklch()` — down to sRGB channels.
|
|
40
|
+
*/
|
|
41
|
+
var makeResolver = (scope) => {
|
|
42
|
+
const probe = document.createElement("span");
|
|
43
|
+
probe.style.display = "none";
|
|
44
|
+
scope.appendChild(probe);
|
|
45
|
+
const context = document.createElement("canvas").getContext("2d", { willReadFrequently: true });
|
|
46
|
+
const resolve = (token) => {
|
|
47
|
+
probe.style.color = `var(${token})`;
|
|
48
|
+
const computed = getComputedStyle(probe).color;
|
|
49
|
+
if (!context || computed.length === 0) return;
|
|
50
|
+
context.clearRect(0, 0, 1, 1);
|
|
51
|
+
context.fillStyle = computed;
|
|
52
|
+
context.fillRect(0, 0, 1, 1);
|
|
53
|
+
const [red, green, blue] = context.getImageData(0, 0, 1, 1).data;
|
|
54
|
+
return `#${[
|
|
55
|
+
red,
|
|
56
|
+
green,
|
|
57
|
+
blue
|
|
58
|
+
].map((channel) => channel.toString(16).padStart(2, "0")).join("")}`;
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
resolve,
|
|
62
|
+
dispose: () => probe.remove()
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Builds an xterm theme from the design system tokens in scope at `element`, so the terminal
|
|
67
|
+
* follows light/dark and any theme override rather than carrying its own palette.
|
|
68
|
+
*/
|
|
69
|
+
var createXtermTheme = (element) => {
|
|
70
|
+
const { resolve, dispose } = makeResolver(element);
|
|
71
|
+
try {
|
|
72
|
+
const surface = resolve("--color-base-surface");
|
|
73
|
+
const foreground = resolve("--color-base-fg");
|
|
74
|
+
const ansi = Object.fromEntries(Object.entries(ANSI_TOKENS).map(([slot, token]) => [slot, resolve(token)]));
|
|
75
|
+
return {
|
|
76
|
+
background: surface,
|
|
77
|
+
foreground,
|
|
78
|
+
cursor: foreground,
|
|
79
|
+
cursorAccent: surface,
|
|
80
|
+
selectionBackground: resolve("--color-accent-surface"),
|
|
81
|
+
...ansi
|
|
82
|
+
};
|
|
83
|
+
} finally {
|
|
84
|
+
dispose();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/components/Terminal/Terminal.tsx
|
|
89
|
+
/**
|
|
90
|
+
* Terminal emulator hosting an `@effect/cli` command tree entirely in the browser.
|
|
91
|
+
*
|
|
92
|
+
* The command tree and its layer are built once per mount, so state held by the services (a DXOS
|
|
93
|
+
* client, for instance) persists across commands the way it does in a long-lived shell.
|
|
94
|
+
*/
|
|
95
|
+
var Terminal = ({ classNames, command, layer: layer$1, name, version, prompt, banner, fontSize = 13 }) => {
|
|
96
|
+
const containerRef = useRef(null);
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
const container = containerRef.current;
|
|
99
|
+
if (!container) return;
|
|
100
|
+
const xterm = new Terminal$1({
|
|
101
|
+
fontSize,
|
|
102
|
+
fontFamily: getComputedStyle(container).getPropertyValue("--font-mono").trim() || "monospace",
|
|
103
|
+
cursorBlink: true
|
|
104
|
+
});
|
|
105
|
+
const fitAddon = new FitAddon();
|
|
106
|
+
xterm.loadAddon(fitAddon);
|
|
107
|
+
xterm.open(container);
|
|
108
|
+
const fit = () => {
|
|
109
|
+
if (container.clientWidth > 0 && container.clientHeight > 0) fitAddon.fit();
|
|
110
|
+
};
|
|
111
|
+
const applyTheme = () => {
|
|
112
|
+
xterm.options.theme = createXtermTheme(container);
|
|
113
|
+
};
|
|
114
|
+
const frame = requestAnimationFrame(applyTheme);
|
|
115
|
+
const themeObserver = new MutationObserver(applyTheme);
|
|
116
|
+
themeObserver.observe(document.documentElement, {
|
|
117
|
+
attributes: true,
|
|
118
|
+
attributeFilter: ["class", "style"]
|
|
119
|
+
});
|
|
120
|
+
xterm.focus();
|
|
121
|
+
const bridge = new XtermBridge(xterm);
|
|
122
|
+
const shell = runShell(bridge, {
|
|
123
|
+
command,
|
|
124
|
+
name,
|
|
125
|
+
version,
|
|
126
|
+
prompt,
|
|
127
|
+
banner
|
|
128
|
+
}).pipe(Effect.provide(layer(bridge)), Effect.provide(layer$1));
|
|
129
|
+
const fiber = Effect.runFork(Effect.scoped(shell));
|
|
130
|
+
const observer = new ResizeObserver(fit);
|
|
131
|
+
observer.observe(container);
|
|
132
|
+
return () => {
|
|
133
|
+
cancelAnimationFrame(frame);
|
|
134
|
+
themeObserver.disconnect();
|
|
135
|
+
observer.disconnect();
|
|
136
|
+
Effect.runFork(Fiber.interrupt(fiber));
|
|
137
|
+
bridge.dispose();
|
|
138
|
+
xterm.dispose();
|
|
139
|
+
};
|
|
140
|
+
}, [
|
|
141
|
+
command,
|
|
142
|
+
layer$1,
|
|
143
|
+
name,
|
|
144
|
+
version,
|
|
145
|
+
prompt,
|
|
146
|
+
banner,
|
|
147
|
+
fontSize
|
|
148
|
+
]);
|
|
149
|
+
return /* @__PURE__ */ jsx("div", {
|
|
150
|
+
ref: containerRef,
|
|
151
|
+
className: mx("grow w-full h-full overflow-hidden bg-base-surface", classNames)
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
//#endregion
|
|
155
|
+
export { Terminal };
|
|
156
|
+
|
|
157
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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 type * as Command from '@effect/cli/Command';\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 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, R, E, A> = ThemedClassName<{\n /**\n * Root of an `@effect/cli` command tree; typically built with `Command.withSubcommands`.\n */\n command: Command.Command<Name, R, E, A>;\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 layer: Layer.Layer<Exclude<R, XtermContext.Provided>, any, 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, R, E, A>({\n classNames,\n command,\n layer,\n name,\n version,\n prompt,\n banner,\n fontSize = 13,\n}: TerminalProps<Name, R, E, A>) => {\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 Effect.runFork(Fiber.interrupt(fiber));\n bridge.dispose();\n xterm.dispose();\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":"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"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/testing.ts
|
|
2
|
+
var POLL_INTERVAL = 50;
|
|
3
|
+
var DEFAULT_TIMEOUT = 15e3;
|
|
4
|
+
/**
|
|
5
|
+
* Reads the terminal's visible contents as plain text.
|
|
6
|
+
*
|
|
7
|
+
* xterm splits a row into a span per style run and pads with non-breaking spaces, so a story cannot
|
|
8
|
+
* assert against it with a plain text query — this flattens a row back to what the user sees.
|
|
9
|
+
*/
|
|
10
|
+
var readTerminal = (element) => Array.from(element.querySelectorAll(".xterm-rows > div")).map((row) => (row.textContent ?? "").replace(/ /g, " ").trimEnd()).join("\n");
|
|
11
|
+
/**
|
|
12
|
+
* The hidden textarea xterm reads keystrokes from.
|
|
13
|
+
*/
|
|
14
|
+
var getTerminalInput = (element) => element.querySelector(".xterm-helper-textarea");
|
|
15
|
+
/**
|
|
16
|
+
* Resolves once the terminal shows `text`, or throws with the current contents.
|
|
17
|
+
*/
|
|
18
|
+
var waitForTerminal = async (element, text, timeout = DEFAULT_TIMEOUT) => {
|
|
19
|
+
const deadline = Date.now() + timeout;
|
|
20
|
+
do {
|
|
21
|
+
if (readTerminal(element).includes(text)) return;
|
|
22
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
|
|
23
|
+
} while (Date.now() < deadline);
|
|
24
|
+
throw new Error(`Timed out waiting for "${text}". Terminal contents:\n${readTerminal(element)}`);
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Types a command and submits it.
|
|
28
|
+
*
|
|
29
|
+
* Waits for the input to echo before sending the return, because the shell drops keystrokes that
|
|
30
|
+
* arrive before its line editor has subscribed — without this the command silently never runs.
|
|
31
|
+
*/
|
|
32
|
+
var runCommand = async (element, command, keyboard) => {
|
|
33
|
+
getTerminalInput(element)?.focus();
|
|
34
|
+
await keyboard(command);
|
|
35
|
+
await waitForTerminal(element, command);
|
|
36
|
+
await keyboard("{Enter}");
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
export { getTerminalInput, readTerminal, runCommand, waitForTerminal };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=testing.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.mjs","names":[],"sources":["../../src/testing.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nconst POLL_INTERVAL = 50;\nconst DEFAULT_TIMEOUT = 15_000;\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(/ /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\n/**\n * Resolves once the terminal shows `text`, or throws with the current contents.\n */\nexport const waitForTerminal = async (element: HTMLElement, text: string, timeout = DEFAULT_TIMEOUT): Promise<void> => {\n const deadline = Date.now() + timeout;\n do {\n if (readTerminal(element).includes(text)) {\n return;\n }\n\n await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));\n } while (Date.now() < deadline);\n\n throw new Error(`Timed out waiting for \"${text}\". Terminal contents:\\n${readTerminal(element)}`);\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":";AAIA,IAAM,gBAAgB;AACtB,IAAM,kBAAkB;;;;;;;AAQxB,IAAa,gBAAgB,YAC3B,MAAM,KAAK,QAAQ,iBAAiB,mBAAmB,CAAC,CAAA,CACrD,KAAK,SAAS,IAAI,eAAe,GAAA,CAAI,QAAQ,MAAM,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAA,CACjE,KAAK,IAAI;;;;AAKd,IAAa,oBAAoB,YAC/B,QAAQ,cAAc,wBAAwB;;;;AAKhD,IAAa,kBAAkB,OAAO,SAAsB,MAAc,UAAU,oBAAmC;CACrH,MAAM,WAAW,KAAK,IAAI,IAAI;CAC9B,GAAG;EACD,IAAI,aAAa,OAAO,CAAC,CAAC,SAAS,IAAI,GACrC;EAGF,MAAM,IAAI,SAAS,YAAY,WAAW,SAAS,aAAa,CAAC;CACnE,SAAS,KAAK,IAAI,IAAI;CAEtB,MAAM,IAAI,MAAM,0BAA0B,KAAK,yBAAyB,aAAa,OAAO,GAAG;AACjG;;;;;;;AAQA,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"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type * as Terminal from '@effect/platform/Terminal';
|
|
2
|
+
import type { Terminal as XtermTerminal } from '@xterm/xterm';
|
|
3
|
+
export type InputHandler = (input: Terminal.UserInput) => void;
|
|
4
|
+
/**
|
|
5
|
+
* The surface the shell and the Effect `Terminal` service need from a terminal: a write sink and a
|
|
6
|
+
* stack of keypress subscribers. Depending on this rather than the xterm class keeps the rest of
|
|
7
|
+
* this module free of any renderer.
|
|
8
|
+
*/
|
|
9
|
+
export interface TerminalBridge {
|
|
10
|
+
readonly columns: number;
|
|
11
|
+
readonly rows: number;
|
|
12
|
+
readonly atLineStart: boolean;
|
|
13
|
+
write(text: string): void;
|
|
14
|
+
clear(): void;
|
|
15
|
+
subscribe(handler: InputHandler): () => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Adapts an xterm instance to {@link TerminalBridge}.
|
|
19
|
+
*/
|
|
20
|
+
export declare class XtermBridge implements TerminalBridge {
|
|
21
|
+
#private;
|
|
22
|
+
constructor(terminal: XtermTerminal);
|
|
23
|
+
get columns(): number;
|
|
24
|
+
get rows(): number;
|
|
25
|
+
/**
|
|
26
|
+
* Whether the cursor sits at the start of a row, so callers can avoid a blank line when a command
|
|
27
|
+
* has already terminated its output with a newline.
|
|
28
|
+
*/
|
|
29
|
+
get atLineStart(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Writes text, translating bare newlines to CRLF since xterm does not reset the column on `\n`.
|
|
32
|
+
*/
|
|
33
|
+
write(text: string): void;
|
|
34
|
+
clear(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Subscribes to keypresses. The most recent subscriber wins, so a prompt opened by a running
|
|
37
|
+
* command takes over from the shell's line editor and hands back when its scope closes.
|
|
38
|
+
*/
|
|
39
|
+
subscribe(handler: InputHandler): () => void;
|
|
40
|
+
dispose(): void;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../../../src/cli/bridge.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,QAAQ,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAe,QAAQ,IAAI,aAAa,EAAE,MAAM,cAAc,CAAC;AAI3E,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,WAAW,EAAE,OAAO,CAAC;IAC9B,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,KAAK,IAAI,IAAI,CAAC;IACd,SAAS,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,IAAI,CAAC;CAC9C;AAED;;GAEG;AACH,qBAAa,WAAY,YAAW,cAAc;;IAMhD,YAAY,QAAQ,EAAE,aAAa,EAGlC;IAED,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;OAGG;IACH,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAOxB;IAED,KAAK,IAAI,IAAI,CAGZ;IAED;;;OAGG;IACH,SAAS,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,IAAI,CAQ3C;IAED,OAAO,IAAI,IAAI,CAGd;CAYF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as Console from 'effect/Console';
|
|
2
|
+
import * as Layer from 'effect/Layer';
|
|
3
|
+
import type { TerminalBridge } from './bridge';
|
|
4
|
+
/**
|
|
5
|
+
* Routes Effect's `Console` to the terminal.
|
|
6
|
+
*
|
|
7
|
+
* `@effect/cli` renders help, usage errors, and wizard output as ANSI text through this service,
|
|
8
|
+
* which xterm interprets natively — so the browser gets the same styled output as a shell.
|
|
9
|
+
*/
|
|
10
|
+
export declare const make: (bridge: TerminalBridge) => Console.Console;
|
|
11
|
+
/**
|
|
12
|
+
* `Console.log` resolves against the `currentServices` fiber ref rather than the layer context, so
|
|
13
|
+
* this must go through `setConsole` — providing the tag with `Layer.succeed` is silently ignored.
|
|
14
|
+
*/
|
|
15
|
+
export declare const layer: (bridge: TerminalBridge) => Layer.Layer<never>;
|
|
16
|
+
//# sourceMappingURL=console.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../../../src/cli/console.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAE1C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAmB/C;;;;;GAKG;AACH,eAAO,MAAM,IAAI,WAAY,cAAc,KAAG,OAAO,CAAC,OAmDrD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,KAAK,WAAY,cAAc,KAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAqC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.test.d.ts","sourceRoot":"","sources":["../../../../src/cli/console.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as FileSystem from '@effect/platform/FileSystem';
|
|
2
|
+
import * as Path from '@effect/platform/Path';
|
|
3
|
+
import type * as Terminal from '@effect/platform/Terminal';
|
|
4
|
+
import * as Layer from 'effect/Layer';
|
|
5
|
+
import type { XtermBridge } from './bridge';
|
|
6
|
+
/**
|
|
7
|
+
* The browser counterpart to `BunContext.layer`.
|
|
8
|
+
*
|
|
9
|
+
* `CliApp.Environment` is only `FileSystem | Path | Terminal`: `Path` is already pure JS upstream
|
|
10
|
+
* and the CLI's browser-safe commands never touch the filesystem, leaving `Terminal` as the sole
|
|
11
|
+
* service needing a real implementation. The console override is merged in too — contributing no
|
|
12
|
+
* services of its own — so command output and the CLI's ANSI help text land in the terminal
|
|
13
|
+
* instead of the devtools console.
|
|
14
|
+
*/
|
|
15
|
+
export type Provided = Terminal.Terminal | FileSystem.FileSystem | Path.Path;
|
|
16
|
+
export declare const layer: (bridge: XtermBridge) => Layer.Layer<Provided>;
|
|
17
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/cli/context.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,UAAU,MAAM,6BAA6B,CAAC;AAC1D,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAC;AAC9C,OAAO,KAAK,KAAK,QAAQ,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAI5C;;;;;;;;GAQG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,GAAG,UAAU,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC;AAE7E,eAAO,MAAM,KAAK,WAAY,WAAW,KAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,CAC+C,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * as XtermConsole from './console';
|
|
2
|
+
export * as XtermContext from './context';
|
|
3
|
+
export * as XtermTerminal from './terminal';
|
|
4
|
+
export * from './bridge';
|
|
5
|
+
export * from './input';
|
|
6
|
+
export * from './line-editor';
|
|
7
|
+
export * from './shell';
|
|
8
|
+
export * from './tokenize';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,YAAY,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,YAAY,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,aAAa,MAAM,YAAY,CAAC;AAE5C,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type * as Terminal from '@effect/platform/Terminal';
|
|
2
|
+
/**
|
|
3
|
+
* Decodes a chunk of xterm `onData` output into the keypress events that `@effect/platform`
|
|
4
|
+
* consumers (notably `@effect/cli` prompts) expect, using the same key names as Node's readline.
|
|
5
|
+
*
|
|
6
|
+
* Decoding the raw data stream rather than `onKey` DOM events is what makes paste work: a pasted
|
|
7
|
+
* string arrives as one chunk and expands to one event per character.
|
|
8
|
+
*/
|
|
9
|
+
export declare const decodeInput: (data: string) => Terminal.UserInput[];
|
|
10
|
+
/**
|
|
11
|
+
* Ctrl-C and Ctrl-D end an input stream, matching the platform-node default.
|
|
12
|
+
*/
|
|
13
|
+
export declare const isQuitInput: (input: Terminal.UserInput) => boolean;
|
|
14
|
+
//# sourceMappingURL=input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../../../src/cli/input.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,QAAQ,MAAM,2BAA2B,CAAC;AA6D3D;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,SAAU,MAAM,KAAG,QAAQ,CAAC,SAAS,EAqD5D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,UAAW,QAAQ,CAAC,SAAS,KAAG,OACc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.test.d.ts","sourceRoot":"","sources":["../../../../src/cli/input.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as Terminal from '@effect/platform/Terminal';
|
|
2
|
+
import * as Effect from 'effect/Effect';
|
|
3
|
+
import type { TerminalBridge } from './bridge';
|
|
4
|
+
export type LineResult = {
|
|
5
|
+
readonly type: 'line';
|
|
6
|
+
readonly value: string;
|
|
7
|
+
} | {
|
|
8
|
+
readonly type: 'cancelled';
|
|
9
|
+
} | {
|
|
10
|
+
readonly type: 'eof';
|
|
11
|
+
};
|
|
12
|
+
export type ReadLineOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* Rendered before the editable buffer and redrawn on every keystroke.
|
|
15
|
+
*/
|
|
16
|
+
prompt?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Previously entered lines, oldest first. Mutated by the caller between reads; the editor only
|
|
19
|
+
* reads it.
|
|
20
|
+
*/
|
|
21
|
+
history?: ReadonlyArray<string>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Reads a single line, echoing keystrokes and supporting inline editing, history recall, and the
|
|
25
|
+
* common readline control chords.
|
|
26
|
+
*
|
|
27
|
+
* Distinguishes cancellation (Ctrl-C) from end-of-input (Ctrl-D on an empty buffer) so a shell can
|
|
28
|
+
* abandon the current line without exiting.
|
|
29
|
+
*/
|
|
30
|
+
export declare const readLineResult: (bridge: TerminalBridge, options?: ReadLineOptions) => Effect.Effect<LineResult>;
|
|
31
|
+
/**
|
|
32
|
+
* The `Terminal` service contract: a line, or a `QuitException` for either interrupt.
|
|
33
|
+
*/
|
|
34
|
+
export declare const readLine: (bridge: TerminalBridge, options?: ReadLineOptions) => Effect.Effect<string, Terminal.QuitException, never>;
|
|
35
|
+
//# sourceMappingURL=line-editor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line-editor.d.ts","sourceRoot":"","sources":["../../../../src/cli/line-editor.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAC;AACtD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjD;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GAC9B;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;CAAE,CAAC;AAE7B,MAAM,MAAM,eAAe,GAAG;IAC5B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACjC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,WAAY,cAAc,YAAW,eAAe,KAAQ,MAAM,CAAC,MAAM,CAAC,UAAU,CA0J3G,CAAC;AAEL;;GAEG;AACH,eAAO,MAAM,QAAQ,WAAY,cAAc,YAAW,eAAe,yDAKtE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line-editor.test.d.ts","sourceRoot":"","sources":["../../../../src/cli/line-editor.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as Command from '@effect/cli/Command';
|
|
2
|
+
import type * as FileSystem from '@effect/platform/FileSystem';
|
|
3
|
+
import type * as Path from '@effect/platform/Path';
|
|
4
|
+
import type * as Terminal from '@effect/platform/Terminal';
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import type { TerminalBridge } from './bridge';
|
|
7
|
+
/**
|
|
8
|
+
* The services `Command.run` itself needs, spelled out because `@effect/cli` only exposes the
|
|
9
|
+
* equivalent alias inside its `CliApp` namespace.
|
|
10
|
+
*/
|
|
11
|
+
export type CliEnvironment = FileSystem.FileSystem | Path.Path | Terminal.Terminal;
|
|
12
|
+
export type ShellOptions<Name extends string, R, E, A> = {
|
|
13
|
+
command: Command.Command<Name, R, E, A>;
|
|
14
|
+
/**
|
|
15
|
+
* Executable name, used in help output and as the argv[1] the Effect CLI parser skips.
|
|
16
|
+
*/
|
|
17
|
+
name?: string;
|
|
18
|
+
version?: string;
|
|
19
|
+
prompt?: string;
|
|
20
|
+
banner?: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Runs a read-eval-print loop against an `@effect/cli` command tree.
|
|
24
|
+
*
|
|
25
|
+
* Each line is tokenized and dispatched through the same `Command.run` the binary uses, with a
|
|
26
|
+
* synthetic argv prefix standing in for the two leading entries the parser discards. The command
|
|
27
|
+
* tree and its layer are built once, so every command reuses the already-activated services.
|
|
28
|
+
*/
|
|
29
|
+
export declare const runShell: <Name extends string, R, E, A>(bridge: TerminalBridge, options: ShellOptions<Name, R, E, A>) => Effect.Effect<void, never, R | CliEnvironment>;
|
|
30
|
+
//# sourceMappingURL=shell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../../../src/cli/shell.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,OAAO,MAAM,qBAAqB,CAAC;AAE/C,OAAO,KAAK,KAAK,UAAU,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,KAAK,IAAI,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,KAAK,QAAQ,MAAM,2BAA2B,CAAC;AAG3D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAM/C;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC;AAEnF,MAAM,MAAM,YAAY,CAAC,IAAI,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI;IACvD,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACxC;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,IAAI,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,UAC3C,cAAc,WACb,YAAY,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KACnC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,cAAc,CAwD5C,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as Terminal from '@effect/platform/Terminal';
|
|
2
|
+
import * as Layer from 'effect/Layer';
|
|
3
|
+
import type { TerminalBridge } from './bridge';
|
|
4
|
+
/**
|
|
5
|
+
* A `@effect/platform` `Terminal` backed by xterm.
|
|
6
|
+
*
|
|
7
|
+
* This is the only service in `CliApp.Environment` without a browser implementation upstream;
|
|
8
|
+
* `Path` is already pure JS and `FileSystem` can be stubbed.
|
|
9
|
+
*/
|
|
10
|
+
export declare const make: (bridge: TerminalBridge) => Terminal.Terminal;
|
|
11
|
+
export declare const layer: (bridge: TerminalBridge) => Layer.Layer<Terminal.Terminal>;
|
|
12
|
+
//# sourceMappingURL=terminal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../../../../src/cli/terminal.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAC;AAGtD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAGtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAI/C;;;;;GAKG;AACH,eAAO,MAAM,IAAI,WAAY,cAAc,KAAG,QAAQ,CAAC,QAmBnD,CAAC;AAEL,eAAO,MAAM,KAAK,WAAY,cAAc,KAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAC5B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type InputHandler, type TerminalBridge } from './bridge';
|
|
2
|
+
/**
|
|
3
|
+
* A bridge that records writes and lets a test push keystrokes, standing in for xterm.
|
|
4
|
+
*/
|
|
5
|
+
export declare class TestBridge implements TerminalBridge {
|
|
6
|
+
#private;
|
|
7
|
+
readonly columns = 80;
|
|
8
|
+
readonly rows = 24;
|
|
9
|
+
readonly writes: string[];
|
|
10
|
+
get atLineStart(): boolean;
|
|
11
|
+
get rendered(): string;
|
|
12
|
+
write(text: string): void;
|
|
13
|
+
clear(): void;
|
|
14
|
+
subscribe(handler: InputHandler): () => void;
|
|
15
|
+
/**
|
|
16
|
+
* Feeds raw terminal data through the real decoder, so tests exercise the same path as xterm.
|
|
17
|
+
*/
|
|
18
|
+
send(data: string): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../../src/cli/testing.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAGlE;;GAEG;AACH,qBAAa,UAAW,YAAW,cAAc;;IAC/C,QAAQ,CAAC,OAAO,MAAM;IACtB,QAAQ,CAAC,IAAI,MAAM;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAM;IAK/B,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAGxB;IAED,KAAK,IAAI,IAAI,CAEZ;IAED,SAAS,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,IAAI,CAK3C;IAED;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAIvB;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits a raw input line into argv tokens. Supports single/double-quoted segments so quoted
|
|
3
|
+
* strings with spaces survive. Intentionally simple — anything needing real shell semantics belongs
|
|
4
|
+
* in a real shell.
|
|
5
|
+
*/
|
|
6
|
+
export declare const tokenize: (input: string) => string[];
|
|
7
|
+
/**
|
|
8
|
+
* Translates shell-friendly aliases to their Effect CLI equivalents. The Effect CLI uses `--help`
|
|
9
|
+
* rather than a `help` subcommand, but `help` and `?` are the natural things to type.
|
|
10
|
+
*/
|
|
11
|
+
export declare const rewriteHelpAliases: (tokens: ReadonlyArray<string>) => string[];
|
|
12
|
+
//# sourceMappingURL=tokenize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenize.d.ts","sourceRoot":"","sources":["../../../../src/cli/tokenize.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,QAAQ,UAAW,MAAM,KAAG,MAAM,EAS9C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,WAAY,aAAa,CAAC,MAAM,CAAC,KAAG,MAAM,EAUxE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import '@xterm/xterm/css/xterm.css';
|
|
2
|
+
import type * as Command from '@effect/cli/Command';
|
|
3
|
+
import type * as Layer from 'effect/Layer';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { type ThemedClassName } from '@dxos/react-ui';
|
|
6
|
+
import { XtermContext } from '../../cli';
|
|
7
|
+
export type TerminalProps<Name extends string, R, E, A> = ThemedClassName<{
|
|
8
|
+
/**
|
|
9
|
+
* Root of an `@effect/cli` command tree; typically built with `Command.withSubcommands`.
|
|
10
|
+
*/
|
|
11
|
+
command: Command.Command<Name, R, E, A>;
|
|
12
|
+
/**
|
|
13
|
+
* Services the command handlers need beyond the platform services provided internally, which is
|
|
14
|
+
* why the terminal's own environment is excluded from what this must supply.
|
|
15
|
+
*/
|
|
16
|
+
layer: Layer.Layer<Exclude<R, XtermContext.Provided>, any, never>;
|
|
17
|
+
name?: string;
|
|
18
|
+
version?: string;
|
|
19
|
+
prompt?: string;
|
|
20
|
+
banner?: string;
|
|
21
|
+
fontSize?: number;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Terminal emulator hosting an `@effect/cli` command tree entirely in the browser.
|
|
25
|
+
*
|
|
26
|
+
* The command tree and its layer are built once per mount, so state held by the services (a DXOS
|
|
27
|
+
* client, for instance) persists across commands the way it does in a long-lived shell.
|
|
28
|
+
*/
|
|
29
|
+
export declare const Terminal: <Name extends string, R, E, A>({ classNames, command, layer, name, version, prompt, banner, fontSize, }: TerminalProps<Name, R, E, A>) => React.JSX.Element;
|
|
30
|
+
//# sourceMappingURL=Terminal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Terminal.d.ts","sourceRoot":"","sources":["../../../../../src/components/Terminal/Terminal.tsx"],"names":[],"mappings":"AAIA,OAAO,4BAA4B,CAAC;AAEpC,OAAO,KAAK,KAAK,OAAO,MAAM,qBAAqB,CAAC;AAKpD,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAC3C,OAAO,KAA4B,MAAM,OAAO,CAAC;AAEjD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtD,OAAO,EAAe,YAAY,EAAY,MAAM,WAAW,CAAC;AAGhE,MAAM,MAAM,aAAa,CAAC,IAAI,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,eAAe,CAAC;IACxE;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACxC;;;OAGG;IACH,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAClE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,IAAI,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,4EASlD,aAAa,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,sBAiE9B,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
declare const meta: {
|
|
4
|
+
title: string;
|
|
5
|
+
render: () => React.JSX.Element;
|
|
6
|
+
decorators: import("@storybook/react").Decorator[];
|
|
7
|
+
parameters: {
|
|
8
|
+
layout: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export default meta;
|
|
12
|
+
type Story = StoryObj<typeof meta>;
|
|
13
|
+
export declare const Default: Story;
|
|
14
|
+
/**
|
|
15
|
+
* Drives the shell end to end: a command is parsed, run, and its output rendered.
|
|
16
|
+
*/
|
|
17
|
+
export declare const Spec: Story;
|
|
18
|
+
//# sourceMappingURL=Terminal.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Terminal.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/Terminal/Terminal.stories.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAIjE,OAAO,KAAkB,MAAM,OAAO,CAAC;AAiEvC,QAAA,MAAM,IAAI;;;;;QAIM,MAAM;;CACe,CAAC;eAEvB,IAAI;AAEnB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAAU,CAAC;AAEjC;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,KAoBlB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/Terminal/index.ts"],"names":[],"mappings":"AAIA,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ITheme } from '@xterm/xterm';
|
|
2
|
+
/**
|
|
3
|
+
* Builds an xterm theme from the design system tokens in scope at `element`, so the terminal
|
|
4
|
+
* follows light/dark and any theme override rather than carrying its own palette.
|
|
5
|
+
*/
|
|
6
|
+
export declare const createXtermTheme: (element: Element) => ITheme;
|
|
7
|
+
//# sourceMappingURL=theme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../../../src/components/Terminal/theme.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAyD3C;;;GAGG;AACH,eAAO,MAAM,gBAAgB,YAAa,OAAO,KAAG,MAqBnD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/index.ts"],"names":[],"mappings":"AAIA,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC"}
|