@adea-ai/ui 0.149.4 → 0.149.6

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.
@@ -96,6 +96,11 @@ export declare function ansi256ToColor(index: number): AnsiColor | undefined;
96
96
  export declare function createAnsiParser(options?: AnsiParserOptions): AnsiParser;
97
97
  /** Parse a whole output at once: finished lines plus the open one, if any. */
98
98
  export declare function parseAnsi(text: string, options?: AnsiParserOptions): AnsiLine[];
99
+ /**
100
+ * The whole output as a reader sees it, for the clipboard: every line, none
101
+ * shortened, with escape sequences and overwritten text resolved away.
102
+ */
103
+ export declare function ansiPlainText(text: string): string;
99
104
  /** A line's text with styling removed, for tests and for accessible names. */
100
105
  export declare function ansiLineText(line: AnsiLine): string;
101
106
  //# sourceMappingURL=ansi.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ansi.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/terminal/ansi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,yEAAyE;AACzE,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAE9B,MAAM,MAAM,SAAS,GAAG,QAAQ,CAAC;IAC/B,EAAE,CAAC,EAAE,SAAS,CAAA;IACd,EAAE,CAAC,EAAE,SAAS,CAAA;IACd,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,GAAG,CAAC,EAAE,IAAI,CAAA;IACV,MAAM,CAAC,EAAE,IAAI,CAAA;IACb,SAAS,CAAC,EAAE,IAAI,CAAA;IAChB,MAAM,CAAC,EAAE,IAAI,CAAA;IACb,OAAO,CAAC,EAAE,IAAI,CAAA;CACf,CAAC,CAAA;AAEF,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC,CAAA;AAEtE,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC;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@@ function parseAnsi(text, options) {
534
534
  const open = parser.openLine();
535
535
  return open ? [...parser.lines, open] : [...parser.lines];
536
536
  }
537
+ /**
538
+ * The whole output as a reader sees it, for the clipboard: every line, none
539
+ * shortened, with escape sequences and overwritten text resolved away.
540
+ */
541
+ function ansiPlainText(text) {
542
+ const parser = createAnsiParser({
543
+ maxLineLength: Number.POSITIVE_INFINITY,
544
+ retainLines: Number.POSITIVE_INFINITY
545
+ });
546
+ parser.write(text);
547
+ const open = parser.openLine();
548
+ return [...parser.lines.map(ansiLineText), open ? ansiLineText(open) : ""].join("\n");
549
+ }
537
550
  /** A line's text with styling removed, for tests and for accessible names. */
538
551
  function ansiLineText(line) {
539
552
  return line.segments.map((segment) => segment.text).join("");
540
553
  }
541
- export { ANSI_MAX_LINE_LENGTH, ANSI_RETAIN_LINES, ansi256ToColor, ansiLineText, createAnsiParser, isPlainStyle, nearestAnsiColor, parseAnsi, resolveColors };
554
+ export { ANSI_MAX_LINE_LENGTH, ANSI_RETAIN_LINES, ansi256ToColor, ansiLineText, ansiPlainText, createAnsiParser, isPlainStyle, nearestAnsiColor, parseAnsi, resolveColors };
542
555
 
543
556
  //# sourceMappingURL=ansi.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ansi.js","names":[],"sources":["../../../../src/components/composites/terminal/ansi.ts"],"sourcesContent":["/**\n * A terminal's text, read safely.\n *\n * Command output is untrusted bytes, not text: it carries colour for the human\n * who ran the command, cursor control for a screen that is not here, and — from\n * a hostile program — sequences that ask a terminal emulator to rewrite its\n * title, write to the clipboard (OSC 52) or hide what it printed. This parser\n * accepts exactly the part a transcript can honour and drops the rest:\n *\n * - **Kept:** printable text, `\\n`, `\\r` (the cursor returns to column 0 and\n * later text overwrites, which is how a progress bar redraws itself), `\\b`\n * (the cursor steps back one column), tab, `ESC[…K` (erase in line, which\n * progress bars pair with `\\r`), and SGR `ESC[…m` for the sixteen theme\n * colours, bold, dim, italic, underline, strike-through and reverse video.\n * - **Mapped:** 256-colour and truecolour SGR become the nearest of the sixteen,\n * so the output keeps the theme's palette and its contrast guarantees instead\n * of a program's idea of \"dark blue\" on a light terminal.\n * - **Dropped, never echoed:** every other CSI (cursor movement, scrolling,\n * private modes), OSC, DCS/SOS/PM/APC strings, charset designations, the 8-bit\n * C1 forms of all of these, every other control character, and the Unicode\n * bidirectional overrides that make text read differently from how it is\n * stored. A malformed or truncated sequence is dropped with its payload, so a\n * half-received `ESC[3` never shows up as the text \"3\".\n *\n * Nothing here produces markup. The result is plain strings with a style object,\n * and the renderer decides what a style looks like.\n *\n * ## Why a stateful parser\n *\n * Output arrives in chunks that split anywhere — inside an escape sequence, in\n * the middle of a line. `createAnsiParser` keeps the half-read sequence, the\n * current style and the line being written between `write` calls, so a chunk\n * boundary changes nothing about the result. Finished lines are immutable and\n * never touched again, which is what lets a renderer keep their DOM while the\n * last line keeps growing. `parseAnsi` is the same thing run once.\n */\n\n/** An index into the sixteen-colour palette: 0–7 normal, 8–15 bright. */\nexport type AnsiColor = number\n\nexport type AnsiStyle = Readonly<{\n fg?: AnsiColor\n bg?: AnsiColor\n bold?: true\n dim?: true\n italic?: true\n underline?: true\n strike?: true\n inverse?: true\n}>\n\nexport type AnsiSegment = Readonly<{ text: string; style: AnsiStyle }>\n\nexport type AnsiLine = Readonly<{\n segments: readonly AnsiSegment[]\n /** Characters past `maxLineLength` that were not kept. Zero for most lines. */\n truncated: number\n}>\n\nexport type AnsiParserOptions = {\n /** Characters kept per line; the rest are counted in `truncated`. Default 10 000. */\n maxLineLength?: number\n /**\n * Finished lines kept. The oldest are discarded (and counted in `droppedLines`)\n * past this, so a command that prints for an hour cannot grow the parser\n * without bound. Default 200 000.\n */\n retainLines?: number\n}\n\nexport type AnsiParser = {\n /** Feed the next chunk. Chunks may split anywhere, including inside an escape. */\n write(chunk: string): void\n /** Finished lines, oldest first. The array is mutated in place as lines arrive. */\n readonly lines: readonly AnsiLine[]\n /** The line still being written, or `undefined` while it is empty. */\n openLine(): AnsiLine | undefined\n /** Finished lines discarded because of `retainLines`. */\n readonly droppedLines: number\n}\n\nexport const ANSI_MAX_LINE_LENGTH = 10_000\nexport const ANSI_RETAIN_LINES = 200_000\n\n/** Longest CSI parameter string worth reading; a real SGR is under 40 characters. */\nconst CSI_MAX = 256\n\nconst PLAIN: AnsiStyle = Object.freeze({})\nconst styleCache = new Map<string, AnsiStyle>()\nconst STYLE_CACHE_LIMIT = 4096\n\n/**\n * Styles are shared by value so a long run of identical style compares by\n * reference when cells are merged into segments, and so a million coloured\n * characters do not allocate a million style objects.\n */\nfunction intern(style: {\n fg?: AnsiColor\n bg?: AnsiColor\n bold?: boolean\n dim?: boolean\n italic?: boolean\n underline?: boolean\n strike?: boolean\n inverse?: boolean\n}): AnsiStyle {\n const key = [\n style.fg ?? '',\n style.bg ?? '',\n style.bold ? 'b' : '',\n style.dim ? 'd' : '',\n style.italic ? 'i' : '',\n style.underline ? 'u' : '',\n style.strike ? 's' : '',\n style.inverse ? 'r' : '',\n ].join('|')\n if (key === '|||||||') return PLAIN\n const cached = styleCache.get(key)\n if (cached) return cached\n const next: AnsiStyle = Object.freeze({\n ...(style.fg !== undefined && { fg: style.fg }),\n ...(style.bg !== undefined && { bg: style.bg }),\n ...(style.bold && { bold: true as const }),\n ...(style.dim && { dim: true as const }),\n ...(style.italic && { italic: true as const }),\n ...(style.underline && { underline: true as const }),\n ...(style.strike && { strike: true as const }),\n ...(style.inverse && { inverse: true as const }),\n })\n if (styleCache.size < STYLE_CACHE_LIMIT) styleCache.set(key, next)\n return next\n}\n\n/** Whether a style paints nothing, so the renderer can emit a bare text node. */\nexport function isPlainStyle(style: AnsiStyle): boolean {\n return (\n style.fg === undefined &&\n style.bg === undefined &&\n !style.bold &&\n !style.dim &&\n !style.italic &&\n !style.underline &&\n !style.strike &&\n !style.inverse\n )\n}\n\n/**\n * The colours a style actually paints. Reverse video swaps them; a swapped side\n * with no colour of its own resolves to the terminal's default foreground or\n * background (`'default-fg'`, `'default-bg'`), which are themselves theme tokens.\n */\nexport type ResolvedColors = Readonly<{\n fg: AnsiColor | 'default-bg' | undefined\n bg: AnsiColor | 'default-fg' | undefined\n}>\n\nexport function resolveColors(style: AnsiStyle): ResolvedColors {\n if (!style.inverse) return { fg: style.fg, bg: style.bg }\n return { fg: style.bg ?? 'default-bg', bg: style.fg ?? 'default-fg' }\n}\n\n// The xterm default palette, used only to decide which of the sixteen theme\n// colours an extended colour is closest to.\nconst XTERM_16: readonly (readonly [number, number, number])[] = [\n [0, 0, 0],\n [205, 0, 0],\n [0, 205, 0],\n [205, 205, 0],\n [0, 0, 238],\n [205, 0, 205],\n [0, 205, 205],\n [229, 229, 229],\n [127, 127, 127],\n [255, 0, 0],\n [0, 255, 0],\n [255, 255, 0],\n [92, 92, 255],\n [255, 0, 255],\n [0, 255, 255],\n [255, 255, 255],\n]\nconst CUBE_LEVELS = [0, 95, 135, 175, 215, 255] as const\n\nconst clamp = (value: number) => Math.min(255, Math.max(0, Math.round(value) || 0))\n\n/** The palette index (0–15) nearest to an RGB colour. Channels are clamped to 0–255. */\nexport function nearestAnsiColor(r: number, g: number, b: number): AnsiColor {\n const red = clamp(r)\n const green = clamp(g)\n const blue = clamp(b)\n let best = 0\n let bestDistance = Infinity\n for (let index = 0; index < XTERM_16.length; index += 1) {\n const [pr, pg, pb] = XTERM_16[index]!\n // The weights are the \"redmean\" approximation: cheap, and much closer to how\n // the eye separates two colours than plain Euclidean distance.\n const meanRed = (red + pr) / 2\n const dr = red - pr\n const dg = green - pg\n const db = blue - pb\n const distance =\n (2 + meanRed / 256) * dr * dr + 4 * dg * dg + (2 + (255 - meanRed) / 256) * db * db\n if (distance < bestDistance) {\n bestDistance = distance\n best = index\n }\n }\n return best\n}\n\n/** Map a 256-colour index to the sixteen. Out-of-range indices give `undefined`. */\nexport function ansi256ToColor(index: number): AnsiColor | undefined {\n if (!Number.isInteger(index) || index < 0 || index > 255) return undefined\n if (index < 16) return index\n if (index >= 232) {\n const grey = 8 + (index - 232) * 10\n return nearestAnsiColor(grey, grey, grey)\n }\n const cube = index - 16\n return nearestAnsiColor(\n CUBE_LEVELS[Math.floor(cube / 36)]!,\n CUBE_LEVELS[Math.floor(cube / 6) % 6]!,\n CUBE_LEVELS[cube % 6]!\n )\n}\n\ntype MutableStyle = {\n fg?: AnsiColor\n bg?: AnsiColor\n bold?: boolean\n dim?: boolean\n italic?: boolean\n underline?: boolean\n strike?: boolean\n inverse?: boolean\n}\n\n/** A parameter is a short run of digits; anything else is not a number we trust. */\nfunction toNumber(token: string | undefined): number | undefined {\n if (token === undefined) return undefined\n if (token === '') return 0\n if (token.length > 5 || !/^\\d+$/.test(token)) return undefined\n return Number(token)\n}\n\n/**\n * Apply one SGR parameter list to a style. Unknown parameters are skipped one\n * at a time, so a program using a code we ignore still gets the colours around\n * it. Extended colours (38/48) consume their operands whether or not they are\n * valid, so a malformed one cannot be re-read as unrelated codes.\n */\nfunction applySgr(current: AnsiStyle, params: string): AnsiStyle {\n const style: MutableStyle = { ...current }\n const tokens = params === '' ? ['0'] : params.split(';')\n\n for (let i = 0; i < tokens.length; i += 1) {\n const token = tokens[i]!\n // The colon form `38:2::r:g:b` carries its operands in one token.\n if (token.includes(':')) {\n const parts = token.split(':')\n const head = toNumber(parts[0])\n if (head === 38 || head === 48) {\n const color = extendedColor(parts[1] === undefined ? [] : parts.slice(1), true)\n if (color !== null) assign(style, head, color)\n } else if (head === 4) {\n if (parts[1] === '0') style.underline = false\n else style.underline = true\n }\n continue\n }\n\n const code = toNumber(token)\n if (code === undefined) continue\n\n if (code === 38 || code === 48) {\n const mode = toNumber(tokens[i + 1])\n const count = mode === 5 ? 1 : mode === 2 ? 3 : 0\n const operands = tokens.slice(i + 2, i + 2 + count)\n i += 1 + count\n const color = extendedColor([String(mode ?? ''), ...operands], false)\n if (color !== null) assign(style, code, color)\n continue\n }\n if (code === 58) {\n // Underline colour: consumed so its operands are not read as codes, then ignored.\n const mode = toNumber(tokens[i + 1])\n i += 1 + (mode === 5 ? 1 : mode === 2 ? 3 : 0)\n continue\n }\n\n if (code === 0) {\n delete style.fg\n delete style.bg\n style.bold = style.dim = style.italic = style.underline = false\n style.strike = style.inverse = false\n } else if (code === 1) style.bold = true\n else if (code === 2) style.dim = true\n else if (code === 3) style.italic = true\n else if (code === 4 || code === 21) style.underline = true\n else if (code === 7) style.inverse = true\n else if (code === 9) style.strike = true\n else if (code === 22) style.bold = style.dim = false\n else if (code === 23) style.italic = false\n else if (code === 24) style.underline = false\n else if (code === 27) style.inverse = false\n else if (code === 29) style.strike = false\n else if (code >= 30 && code <= 37) style.fg = code - 30\n else if (code === 39) delete style.fg\n else if (code >= 40 && code <= 47) style.bg = code - 40\n else if (code === 49) delete style.bg\n else if (code >= 90 && code <= 97) style.fg = code - 90 + 8\n else if (code >= 100 && code <= 107) style.bg = code - 100 + 8\n // Blink (5, 6), conceal (8), overline (53) and the rest are ignored. Conceal\n // in particular is not honoured: output must not be able to hide itself.\n }\n return intern(style)\n}\n\n/** The colour an extended-colour operand list names, or `null` when it is invalid. */\nfunction extendedColor(parts: readonly string[], colon: boolean): AnsiColor | null {\n const mode = toNumber(parts[0])\n if (mode === 5) {\n const index = toNumber(parts[1])\n const color = index === undefined ? undefined : ansi256ToColor(index)\n return color ?? null\n }\n if (mode === 2) {\n // In the colon form a colour-space id may precede the channels, empty or not.\n const channels = colon && parts.length > 4 ? parts.slice(2) : parts.slice(1)\n const [r, g, b] = channels.slice(0, 3).map(toNumber)\n if (r === undefined || g === undefined || b === undefined) return null\n if (r > 255 || g > 255 || b > 255) return null\n return nearestAnsiColor(r, g, b)\n }\n return null\n}\n\nfunction assign(style: MutableStyle, code: number, color: AnsiColor): void {\n if (code === 38) style.fg = color\n else style.bg = color\n}\n\n/** Characters that are never rendered: C0 except tab, DEL, C1, and bidi controls. */\nfunction isDroppedControl(code: number): boolean {\n return (\n (code < 0x20 && code !== 0x09) ||\n code === 0x7f ||\n (code >= 0x80 && code <= 0x9f) ||\n (code >= 0x202a && code <= 0x202e) ||\n (code >= 0x2066 && code <= 0x2069) ||\n code === 0x2028 ||\n code === 0x2029\n )\n}\n\ntype Run = { text: string; style: AnsiStyle }\n\n/**\n * The line being written. While the cursor only ever moves right it is a list of\n * styled runs, which is cheap; the first time something moves it left (`\\r`,\n * `\\b`) it becomes one cell per UTF-16 unit so later text can overwrite.\n */\nclass LineBuffer {\n private runs: Run[] = []\n private cells: string[] | undefined\n private cellStyles: AnsiStyle[] | undefined\n private cursor = 0\n private length = 0\n private dropped = 0\n /** A `\\r` seen but not yet applied: `\\r\\n` is by far the common case. */\n private pendingReturn = false\n\n constructor(private readonly max: number) {}\n\n isEmpty(): boolean {\n return this.length === 0 && this.dropped === 0\n }\n\n put(text: string, style: AnsiStyle): void {\n if (text === '') return\n this.applyReturn()\n if (this.cells === undefined) {\n const room = this.max - this.length\n if (room <= 0) {\n this.dropped += text.length\n return\n }\n const kept = text.length > room ? text.slice(0, room) : text\n this.dropped += text.length - kept.length\n const last = this.runs[this.runs.length - 1]\n if (last && last.style === style) last.text += kept\n else this.runs.push({ text: kept, style })\n this.length += kept.length\n this.cursor = this.length\n return\n }\n for (let i = 0; i < text.length; i += 1) this.putCell(text[i]!, style)\n }\n\n private putCell(char: string, style: AnsiStyle): void {\n const cells = this.cells!\n const styles = this.cellStyles!\n if (this.cursor >= this.max) {\n this.dropped += 1\n return\n }\n while (cells.length < this.cursor) {\n cells.push(' ')\n styles.push(PLAIN)\n }\n cells[this.cursor] = char\n styles[this.cursor] = style\n this.cursor += 1\n this.length = cells.length\n }\n\n carriageReturn(): void {\n this.pendingReturn = true\n }\n\n backspace(): void {\n this.applyReturn()\n if (this.cursor === 0) return\n this.toCells()\n this.cursor -= 1\n }\n\n /** `ESC[nK`: 0 from the cursor to the end, 1 start to cursor, 2 the whole line. */\n eraseInLine(mode: number): void {\n this.applyReturn()\n if (mode === 0 && this.cursor >= this.length) return\n this.toCells()\n const cells = this.cells!\n const styles = this.cellStyles!\n if (mode === 0) {\n cells.length = this.cursor\n styles.length = this.cursor\n } else if (mode === 1) {\n for (let i = 0; i <= this.cursor && i < cells.length; i += 1) {\n cells[i] = ' '\n styles[i] = PLAIN\n }\n } else if (mode === 2) {\n cells.length = 0\n styles.length = 0\n }\n this.length = cells.length\n }\n\n private applyReturn(): void {\n if (!this.pendingReturn) return\n this.pendingReturn = false\n if (this.length === 0) {\n this.cursor = 0\n return\n }\n this.toCells()\n this.cursor = 0\n }\n\n private toCells(): void {\n if (this.cells !== undefined) return\n const cells: string[] = []\n const styles: AnsiStyle[] = []\n for (const run of this.runs) {\n for (let i = 0; i < run.text.length; i += 1) {\n cells.push(run.text[i]!)\n styles.push(run.style)\n }\n }\n this.cells = cells\n this.cellStyles = styles\n this.runs = []\n this.cursor = Math.min(this.cursor, cells.length)\n }\n\n snapshot(): AnsiLine {\n const segments: AnsiSegment[] = []\n if (this.cells === undefined) {\n for (const run of this.runs) segments.push({ text: run.text, style: run.style })\n } else {\n const cells = this.cells\n const styles = this.cellStyles!\n let start = 0\n for (let i = 1; i <= cells.length; i += 1) {\n if (i === cells.length || styles[i] !== styles[start]) {\n segments.push({ text: cells.slice(start, i).join(''), style: styles[start]! })\n start = i\n }\n }\n }\n return { segments, truncated: this.dropped }\n }\n\n reset(): void {\n this.runs = []\n this.cells = undefined\n this.cellStyles = undefined\n this.cursor = 0\n this.length = 0\n this.dropped = 0\n this.pendingReturn = false\n }\n}\n\ntype State = 'text' | 'esc' | 'esc-intermediate' | 'csi' | 'string' | 'string-esc'\n\nexport function createAnsiParser(options: AnsiParserOptions = {}): AnsiParser {\n const maxLine = Math.max(1, Math.floor(options.maxLineLength ?? ANSI_MAX_LINE_LENGTH))\n const retain = Math.max(1, Math.floor(options.retainLines ?? ANSI_RETAIN_LINES))\n const lines: AnsiLine[] = []\n let droppedLines = 0\n const line = new LineBuffer(maxLine)\n let style: AnsiStyle = PLAIN\n let state: State = 'text'\n let csi = ''\n let csiOverflow = false\n // Only the 7-bit `ESC [` introducer is honoured. The 8-bit form is consumed so\n // its parameters are not echoed, but it never changes the style: it is a rarity\n // in real output and a favourite of filter-evasion payloads.\n let csiHonoured = true\n\n const finishLine = () => {\n lines.push(line.snapshot())\n line.reset()\n // Trim in blocks so the common append stays O(1) amortised.\n if (lines.length > retain + Math.max(64, retain >> 3)) {\n const excess = lines.length - retain\n lines.splice(0, excess)\n droppedLines += excess\n }\n }\n\n const runCsi = (final: string) => {\n if (csiOverflow || !csiHonoured) return\n // Only plain numeric parameters are honoured; a private marker (`?`, `>`,\n // `<`, `=`) or an intermediate byte makes this some other command entirely.\n if (!/^[\\d;:]*$/.test(csi)) return\n if (final === 'm') style = applySgr(style, csi)\n else if (final === 'K') {\n const mode = toNumber(csi.split(';')[0])\n if (mode !== undefined && mode <= 2) line.eraseInLine(mode)\n }\n }\n\n function write(chunk: string): void {\n for (let i = 0; i < chunk.length; i += 1) {\n const code = chunk.charCodeAt(i)\n\n switch (state) {\n case 'text': {\n if (!isDroppedControl(code)) {\n // Take the whole run of ordinary characters at once.\n let end = i + 1\n while (end < chunk.length && !isDroppedControl(chunk.charCodeAt(end))) end += 1\n line.put(chunk.slice(i, end), style)\n i = end - 1\n break\n }\n if (code === 0x1b) state = 'esc'\n else if (code === 0x0a) finishLine()\n else if (code === 0x0d) line.carriageReturn()\n else if (code === 0x08) line.backspace()\n else if (code === 0x9b) {\n state = 'csi'\n csi = ''\n csiOverflow = false\n csiHonoured = false\n } else if (\n code === 0x9d ||\n code === 0x90 ||\n code === 0x98 ||\n code === 0x9e ||\n code === 0x9f\n ) {\n state = 'string'\n }\n // Every other control character is dropped.\n break\n }\n case 'esc': {\n if (code === 0x5b) {\n state = 'csi'\n csi = ''\n csiOverflow = false\n csiHonoured = true\n } else if (\n code === 0x5d ||\n code === 0x50 ||\n code === 0x58 ||\n code === 0x5e ||\n code === 0x5f\n ) {\n state = 'string'\n } else if (code >= 0x20 && code <= 0x2f) state = 'esc-intermediate'\n else if (code >= 0x30 && code <= 0x7e) state = 'text'\n else if (code === 0x1b) state = 'esc'\n else {\n state = 'text'\n i -= 1\n }\n break\n }\n case 'esc-intermediate': {\n if (code >= 0x20 && code <= 0x2f) break\n if (code >= 0x30 && code <= 0x7e) state = 'text'\n else {\n state = 'text'\n i -= 1\n }\n break\n }\n case 'csi': {\n if (code >= 0x20 && code <= 0x3f) {\n if (csi.length < CSI_MAX) csi += chunk[i]\n else csiOverflow = true\n } else if (code >= 0x40 && code <= 0x7e) {\n runCsi(chunk[i]!)\n state = 'text'\n } else if (code === 0x1b) state = 'esc'\n else {\n // A control character or non-ASCII byte cannot be part of a CSI: the\n // sequence was malformed. Drop it and read this character normally.\n state = 'text'\n i -= 1\n }\n break\n }\n case 'string': {\n if (code === 0x07 || code === 0x9c) state = 'text'\n else if (code === 0x1b) state = 'string-esc'\n else if (code === 0x0a || code === 0x0d) {\n // No real title or clipboard payload spans a line. Ending here bounds\n // what an unterminated string can swallow to the rest of its line.\n state = 'text'\n i -= 1\n }\n break\n }\n case 'string-esc': {\n if (code === 0x5c) state = 'text'\n else {\n state = 'esc'\n i -= 1\n }\n break\n }\n }\n }\n }\n\n return {\n write,\n lines,\n openLine: () => (line.isEmpty() ? undefined : line.snapshot()),\n get droppedLines() {\n return droppedLines\n },\n }\n}\n\n/** Parse a whole output at once: finished lines plus the open one, if any. */\nexport function parseAnsi(text: string, options?: AnsiParserOptions): AnsiLine[] {\n const parser = createAnsiParser(options)\n parser.write(text)\n const open = parser.openLine()\n return open ? [...parser.lines, open] : [...parser.lines]\n}\n\n/** A line's text with styling removed, for tests and for accessible names. */\nexport function ansiLineText(line: AnsiLine): string {\n return line.segments.map((segment) => segment.text).join('')\n}\n"],"mappings":";AAiFA,IAAa,uBAAuB;AACpC,IAAa,oBAAoB;;AAGjC,IAAM,UAAU;AAEhB,IAAM,QAAmB,OAAO,OAAO,CAAC,CAAC;AACzC,IAAM,6BAAa,IAAI,IAAuB;AAC9C,IAAM,oBAAoB;;;;;;AAO1B,SAAS,OAAO,OASF;CACZ,MAAM,MAAM;EACV,M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,QAAQ,MAAQ,QAAQ,KAAM;MACvC,OAAO,MAAM,EAAG;MAChB,QAAQ;KACV,OAAO,IAAI,SAAS,IAAM,QAAQ;UAC7B;MAGH,QAAQ;MACR,KAAK;KACP;KACA;IAEF,KAAK;KACH,IAAI,SAAS,KAAQ,SAAS,KAAM,QAAQ;UACvC,IAAI,SAAS,IAAM,QAAQ;UAC3B,IAAI,SAAS,MAAQ,SAAS,IAAM;MAGvC,QAAQ;MACR,KAAK;KACP;KACA;IAEF,KAAK,cACH,IAAI,SAAS,IAAM,QAAQ;SACtB;KACH,QAAQ;KACR,KAAK;IACP;GAGJ;EACF;CACF;CAEA,OAAO;EACL;EACA;EACA,gBAAiB,KAAK,QAAQ,IAAI,KAAA,IAAY,KAAK,SAAS;EAC5D,IAAI,eAAe;GACjB,OAAO;EACT;CACF;AACF;;AAGA,SAAgB,UAAU,MAAc,SAAyC;CAC/E,MAAM,SAAS,iBAAiB,OAAO;CACvC,OAAO,MAAM,IAAI;CACjB,MAAM,OAAO,OAAO,SAAS;CAC7B,OAAO,OAAO,CAAC,GAAG,OAAO,OAAO,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK;AAC1D;;AAGA,SAAgB,aAAa,MAAwB;CACnD,OAAO,KAAK,SAAS,KAAK,YAAY,QAAQ,IAAI,CAAC,CAAC,KAAK,EAAE;AAC7D"}
1
+ {"version":3,"file":"ansi.js","names":[],"sources":["../../../../src/components/composites/terminal/ansi.ts"],"sourcesContent":["/**\n * A terminal's text, read safely.\n *\n * Command output is untrusted bytes, not text: it carries colour for the human\n * who ran the command, cursor control for a screen that is not here, and — from\n * a hostile program — sequences that ask a terminal emulator to rewrite its\n * title, write to the clipboard (OSC 52) or hide what it printed. This parser\n * accepts exactly the part a transcript can honour and drops the rest:\n *\n * - **Kept:** printable text, `\\n`, `\\r` (the cursor returns to column 0 and\n * later text overwrites, which is how a progress bar redraws itself), `\\b`\n * (the cursor steps back one column), tab, `ESC[…K` (erase in line, which\n * progress bars pair with `\\r`), and SGR `ESC[…m` for the sixteen theme\n * colours, bold, dim, italic, underline, strike-through and reverse video.\n * - **Mapped:** 256-colour and truecolour SGR become the nearest of the sixteen,\n * so the output keeps the theme's palette and its contrast guarantees instead\n * of a program's idea of \"dark blue\" on a light terminal.\n * - **Dropped, never echoed:** every other CSI (cursor movement, scrolling,\n * private modes), OSC, DCS/SOS/PM/APC strings, charset designations, the 8-bit\n * C1 forms of all of these, every other control character, and the Unicode\n * bidirectional overrides that make text read differently from how it is\n * stored. A malformed or truncated sequence is dropped with its payload, so a\n * half-received `ESC[3` never shows up as the text \"3\".\n *\n * Nothing here produces markup. The result is plain strings with a style object,\n * and the renderer decides what a style looks like.\n *\n * ## Why a stateful parser\n *\n * Output arrives in chunks that split anywhere — inside an escape sequence, in\n * the middle of a line. `createAnsiParser` keeps the half-read sequence, the\n * current style and the line being written between `write` calls, so a chunk\n * boundary changes nothing about the result. Finished lines are immutable and\n * never touched again, which is what lets a renderer keep their DOM while the\n * last line keeps growing. `parseAnsi` is the same thing run once.\n */\n\n/** An index into the sixteen-colour palette: 0–7 normal, 8–15 bright. */\nexport type AnsiColor = number\n\nexport type AnsiStyle = Readonly<{\n fg?: AnsiColor\n bg?: AnsiColor\n bold?: true\n dim?: true\n italic?: true\n underline?: true\n strike?: true\n inverse?: true\n}>\n\nexport type AnsiSegment = Readonly<{ text: string; style: AnsiStyle }>\n\nexport type AnsiLine = Readonly<{\n segments: readonly AnsiSegment[]\n /** Characters past `maxLineLength` that were not kept. Zero for most lines. */\n truncated: number\n}>\n\nexport type AnsiParserOptions = {\n /** Characters kept per line; the rest are counted in `truncated`. Default 10 000. */\n maxLineLength?: number\n /**\n * Finished lines kept. The oldest are discarded (and counted in `droppedLines`)\n * past this, so a command that prints for an hour cannot grow the parser\n * without bound. Default 200 000.\n */\n retainLines?: number\n}\n\nexport type AnsiParser = {\n /** Feed the next chunk. Chunks may split anywhere, including inside an escape. */\n write(chunk: string): void\n /** Finished lines, oldest first. The array is mutated in place as lines arrive. */\n readonly lines: readonly AnsiLine[]\n /** The line still being written, or `undefined` while it is empty. */\n openLine(): AnsiLine | undefined\n /** Finished lines discarded because of `retainLines`. */\n readonly droppedLines: number\n}\n\nexport const ANSI_MAX_LINE_LENGTH = 10_000\nexport const ANSI_RETAIN_LINES = 200_000\n\n/** Longest CSI parameter string worth reading; a real SGR is under 40 characters. */\nconst CSI_MAX = 256\n\nconst PLAIN: AnsiStyle = Object.freeze({})\nconst styleCache = new Map<string, AnsiStyle>()\nconst STYLE_CACHE_LIMIT = 4096\n\n/**\n * Styles are shared by value so a long run of identical style compares by\n * reference when cells are merged into segments, and so a million coloured\n * characters do not allocate a million style objects.\n */\nfunction intern(style: {\n fg?: AnsiColor\n bg?: AnsiColor\n bold?: boolean\n dim?: boolean\n italic?: boolean\n underline?: boolean\n strike?: boolean\n inverse?: boolean\n}): AnsiStyle {\n const key = [\n style.fg ?? '',\n style.bg ?? '',\n style.bold ? 'b' : '',\n style.dim ? 'd' : '',\n style.italic ? 'i' : '',\n style.underline ? 'u' : '',\n style.strike ? 's' : '',\n style.inverse ? 'r' : '',\n ].join('|')\n if (key === '|||||||') return PLAIN\n const cached = styleCache.get(key)\n if (cached) return cached\n const next: AnsiStyle = Object.freeze({\n ...(style.fg !== undefined && { fg: style.fg }),\n ...(style.bg !== undefined && { bg: style.bg }),\n ...(style.bold && { bold: true as const }),\n ...(style.dim && { dim: true as const }),\n ...(style.italic && { italic: true as const }),\n ...(style.underline && { underline: true as const }),\n ...(style.strike && { strike: true as const }),\n ...(style.inverse && { inverse: true as const }),\n })\n if (styleCache.size < STYLE_CACHE_LIMIT) styleCache.set(key, next)\n return next\n}\n\n/** Whether a style paints nothing, so the renderer can emit a bare text node. */\nexport function isPlainStyle(style: AnsiStyle): boolean {\n return (\n style.fg === undefined &&\n style.bg === undefined &&\n !style.bold &&\n !style.dim &&\n !style.italic &&\n !style.underline &&\n !style.strike &&\n !style.inverse\n )\n}\n\n/**\n * The colours a style actually paints. Reverse video swaps them; a swapped side\n * with no colour of its own resolves to the terminal's default foreground or\n * background (`'default-fg'`, `'default-bg'`), which are themselves theme tokens.\n */\nexport type ResolvedColors = Readonly<{\n fg: AnsiColor | 'default-bg' | undefined\n bg: AnsiColor | 'default-fg' | undefined\n}>\n\nexport function resolveColors(style: AnsiStyle): ResolvedColors {\n if (!style.inverse) return { fg: style.fg, bg: style.bg }\n return { fg: style.bg ?? 'default-bg', bg: style.fg ?? 'default-fg' }\n}\n\n// The xterm default palette, used only to decide which of the sixteen theme\n// colours an extended colour is closest to.\nconst XTERM_16: readonly (readonly [number, number, number])[] = [\n [0, 0, 0],\n [205, 0, 0],\n [0, 205, 0],\n [205, 205, 0],\n [0, 0, 238],\n [205, 0, 205],\n [0, 205, 205],\n [229, 229, 229],\n [127, 127, 127],\n [255, 0, 0],\n [0, 255, 0],\n [255, 255, 0],\n [92, 92, 255],\n [255, 0, 255],\n [0, 255, 255],\n [255, 255, 255],\n]\nconst CUBE_LEVELS = [0, 95, 135, 175, 215, 255] as const\n\nconst clamp = (value: number) => Math.min(255, Math.max(0, Math.round(value) || 0))\n\n/** The palette index (0–15) nearest to an RGB colour. Channels are clamped to 0–255. */\nexport function nearestAnsiColor(r: number, g: number, b: number): AnsiColor {\n const red = clamp(r)\n const green = clamp(g)\n const blue = clamp(b)\n let best = 0\n let bestDistance = Infinity\n for (let index = 0; index < XTERM_16.length; index += 1) {\n const [pr, pg, pb] = XTERM_16[index]!\n // The weights are the \"redmean\" approximation: cheap, and much closer to how\n // the eye separates two colours than plain Euclidean distance.\n const meanRed = (red + pr) / 2\n const dr = red - pr\n const dg = green - pg\n const db = blue - pb\n const distance =\n (2 + meanRed / 256) * dr * dr + 4 * dg * dg + (2 + (255 - meanRed) / 256) * db * db\n if (distance < bestDistance) {\n bestDistance = distance\n best = index\n }\n }\n return best\n}\n\n/** Map a 256-colour index to the sixteen. Out-of-range indices give `undefined`. */\nexport function ansi256ToColor(index: number): AnsiColor | undefined {\n if (!Number.isInteger(index) || index < 0 || index > 255) return undefined\n if (index < 16) return index\n if (index >= 232) {\n const grey = 8 + (index - 232) * 10\n return nearestAnsiColor(grey, grey, grey)\n }\n const cube = index - 16\n return nearestAnsiColor(\n CUBE_LEVELS[Math.floor(cube / 36)]!,\n CUBE_LEVELS[Math.floor(cube / 6) % 6]!,\n CUBE_LEVELS[cube % 6]!\n )\n}\n\ntype MutableStyle = {\n fg?: AnsiColor\n bg?: AnsiColor\n bold?: boolean\n dim?: boolean\n italic?: boolean\n underline?: boolean\n strike?: boolean\n inverse?: boolean\n}\n\n/** A parameter is a short run of digits; anything else is not a number we trust. */\nfunction toNumber(token: string | undefined): number | undefined {\n if (token === undefined) return undefined\n if (token === '') return 0\n if (token.length > 5 || !/^\\d+$/.test(token)) return undefined\n return Number(token)\n}\n\n/**\n * Apply one SGR parameter list to a style. Unknown parameters are skipped one\n * at a time, so a program using a code we ignore still gets the colours around\n * it. Extended colours (38/48) consume their operands whether or not they are\n * valid, so a malformed one cannot be re-read as unrelated codes.\n */\nfunction applySgr(current: AnsiStyle, params: string): AnsiStyle {\n const style: MutableStyle = { ...current }\n const tokens = params === '' ? ['0'] : params.split(';')\n\n for (let i = 0; i < tokens.length; i += 1) {\n const token = tokens[i]!\n // The colon form `38:2::r:g:b` carries its operands in one token.\n if (token.includes(':')) {\n const parts = token.split(':')\n const head = toNumber(parts[0])\n if (head === 38 || head === 48) {\n const color = extendedColor(parts[1] === undefined ? [] : parts.slice(1), true)\n if (color !== null) assign(style, head, color)\n } else if (head === 4) {\n if (parts[1] === '0') style.underline = false\n else style.underline = true\n }\n continue\n }\n\n const code = toNumber(token)\n if (code === undefined) continue\n\n if (code === 38 || code === 48) {\n const mode = toNumber(tokens[i + 1])\n const count = mode === 5 ? 1 : mode === 2 ? 3 : 0\n const operands = tokens.slice(i + 2, i + 2 + count)\n i += 1 + count\n const color = extendedColor([String(mode ?? ''), ...operands], false)\n if (color !== null) assign(style, code, color)\n continue\n }\n if (code === 58) {\n // Underline colour: consumed so its operands are not read as codes, then ignored.\n const mode = toNumber(tokens[i + 1])\n i += 1 + (mode === 5 ? 1 : mode === 2 ? 3 : 0)\n continue\n }\n\n if (code === 0) {\n delete style.fg\n delete style.bg\n style.bold = style.dim = style.italic = style.underline = false\n style.strike = style.inverse = false\n } else if (code === 1) style.bold = true\n else if (code === 2) style.dim = true\n else if (code === 3) style.italic = true\n else if (code === 4 || code === 21) style.underline = true\n else if (code === 7) style.inverse = true\n else if (code === 9) style.strike = true\n else if (code === 22) style.bold = style.dim = false\n else if (code === 23) style.italic = false\n else if (code === 24) style.underline = false\n else if (code === 27) style.inverse = false\n else if (code === 29) style.strike = false\n else if (code >= 30 && code <= 37) style.fg = code - 30\n else if (code === 39) delete style.fg\n else if (code >= 40 && code <= 47) style.bg = code - 40\n else if (code === 49) delete style.bg\n else if (code >= 90 && code <= 97) style.fg = code - 90 + 8\n else if (code >= 100 && code <= 107) style.bg = code - 100 + 8\n // Blink (5, 6), conceal (8), overline (53) and the rest are ignored. Conceal\n // in particular is not honoured: output must not be able to hide itself.\n }\n return intern(style)\n}\n\n/** The colour an extended-colour operand list names, or `null` when it is invalid. */\nfunction extendedColor(parts: readonly string[], colon: boolean): AnsiColor | null {\n const mode = toNumber(parts[0])\n if (mode === 5) {\n const index = toNumber(parts[1])\n const color = index === undefined ? undefined : ansi256ToColor(index)\n return color ?? null\n }\n if (mode === 2) {\n // In the colon form a colour-space id may precede the channels, empty or not.\n const channels = colon && parts.length > 4 ? parts.slice(2) : parts.slice(1)\n const [r, g, b] = channels.slice(0, 3).map(toNumber)\n if (r === undefined || g === undefined || b === undefined) return null\n if (r > 255 || g > 255 || b > 255) return null\n return nearestAnsiColor(r, g, b)\n }\n return null\n}\n\nfunction assign(style: MutableStyle, code: number, color: AnsiColor): void {\n if (code === 38) style.fg = color\n else style.bg = color\n}\n\n/** Characters that are never rendered: C0 except tab, DEL, C1, and bidi controls. */\nfunction isDroppedControl(code: number): boolean {\n return (\n (code < 0x20 && code !== 0x09) ||\n code === 0x7f ||\n (code >= 0x80 && code <= 0x9f) ||\n (code >= 0x202a && code <= 0x202e) ||\n (code >= 0x2066 && code <= 0x2069) ||\n code === 0x2028 ||\n code === 0x2029\n )\n}\n\ntype Run = { text: string; style: AnsiStyle }\n\n/**\n * The line being written. While the cursor only ever moves right it is a list of\n * styled runs, which is cheap; the first time something moves it left (`\\r`,\n * `\\b`) it becomes one cell per UTF-16 unit so later text can overwrite.\n */\nclass LineBuffer {\n private runs: Run[] = []\n private cells: string[] | undefined\n private cellStyles: AnsiStyle[] | undefined\n private cursor = 0\n private length = 0\n private dropped = 0\n /** A `\\r` seen but not yet applied: `\\r\\n` is by far the common case. */\n private pendingReturn = false\n\n constructor(private readonly max: number) {}\n\n isEmpty(): boolean {\n return this.length === 0 && this.dropped === 0\n }\n\n put(text: string, style: AnsiStyle): void {\n if (text === '') return\n this.applyReturn()\n if (this.cells === undefined) {\n const room = this.max - this.length\n if (room <= 0) {\n this.dropped += text.length\n return\n }\n const kept = text.length > room ? text.slice(0, room) : text\n this.dropped += text.length - kept.length\n const last = this.runs[this.runs.length - 1]\n if (last && last.style === style) last.text += kept\n else this.runs.push({ text: kept, style })\n this.length += kept.length\n this.cursor = this.length\n return\n }\n for (let i = 0; i < text.length; i += 1) this.putCell(text[i]!, style)\n }\n\n private putCell(char: string, style: AnsiStyle): void {\n const cells = this.cells!\n const styles = this.cellStyles!\n if (this.cursor >= this.max) {\n this.dropped += 1\n return\n }\n while (cells.length < this.cursor) {\n cells.push(' ')\n styles.push(PLAIN)\n }\n cells[this.cursor] = char\n styles[this.cursor] = style\n this.cursor += 1\n this.length = cells.length\n }\n\n carriageReturn(): void {\n this.pendingReturn = true\n }\n\n backspace(): void {\n this.applyReturn()\n if (this.cursor === 0) return\n this.toCells()\n this.cursor -= 1\n }\n\n /** `ESC[nK`: 0 from the cursor to the end, 1 start to cursor, 2 the whole line. */\n eraseInLine(mode: number): void {\n this.applyReturn()\n if (mode === 0 && this.cursor >= this.length) return\n this.toCells()\n const cells = this.cells!\n const styles = this.cellStyles!\n if (mode === 0) {\n cells.length = this.cursor\n styles.length = this.cursor\n } else if (mode === 1) {\n for (let i = 0; i <= this.cursor && i < cells.length; i += 1) {\n cells[i] = ' '\n styles[i] = PLAIN\n }\n } else if (mode === 2) {\n cells.length = 0\n styles.length = 0\n }\n this.length = cells.length\n }\n\n private applyReturn(): void {\n if (!this.pendingReturn) return\n this.pendingReturn = false\n if (this.length === 0) {\n this.cursor = 0\n return\n }\n this.toCells()\n this.cursor = 0\n }\n\n private toCells(): void {\n if (this.cells !== undefined) return\n const cells: string[] = []\n const styles: AnsiStyle[] = []\n for (const run of this.runs) {\n for (let i = 0; i < run.text.length; i += 1) {\n cells.push(run.text[i]!)\n styles.push(run.style)\n }\n }\n this.cells = cells\n this.cellStyles = styles\n this.runs = []\n this.cursor = Math.min(this.cursor, cells.length)\n }\n\n snapshot(): AnsiLine {\n const segments: AnsiSegment[] = []\n if (this.cells === undefined) {\n for (const run of this.runs) segments.push({ text: run.text, style: run.style })\n } else {\n const cells = this.cells\n const styles = this.cellStyles!\n let start = 0\n for (let i = 1; i <= cells.length; i += 1) {\n if (i === cells.length || styles[i] !== styles[start]) {\n segments.push({ text: cells.slice(start, i).join(''), style: styles[start]! })\n start = i\n }\n }\n }\n return { segments, truncated: this.dropped }\n }\n\n reset(): void {\n this.runs = []\n this.cells = undefined\n this.cellStyles = undefined\n this.cursor = 0\n this.length = 0\n this.dropped = 0\n this.pendingReturn = false\n }\n}\n\ntype State = 'text' | 'esc' | 'esc-intermediate' | 'csi' | 'string' | 'string-esc'\n\nexport function createAnsiParser(options: AnsiParserOptions = {}): AnsiParser {\n const maxLine = Math.max(1, Math.floor(options.maxLineLength ?? ANSI_MAX_LINE_LENGTH))\n const retain = Math.max(1, Math.floor(options.retainLines ?? ANSI_RETAIN_LINES))\n const lines: AnsiLine[] = []\n let droppedLines = 0\n const line = new LineBuffer(maxLine)\n let style: AnsiStyle = PLAIN\n let state: State = 'text'\n let csi = ''\n let csiOverflow = false\n // Only the 7-bit `ESC [` introducer is honoured. The 8-bit form is consumed so\n // its parameters are not echoed, but it never changes the style: it is a rarity\n // in real output and a favourite of filter-evasion payloads.\n let csiHonoured = true\n\n const finishLine = () => {\n lines.push(line.snapshot())\n line.reset()\n // Trim in blocks so the common append stays O(1) amortised.\n if (lines.length > retain + Math.max(64, retain >> 3)) {\n const excess = lines.length - retain\n lines.splice(0, excess)\n droppedLines += excess\n }\n }\n\n const runCsi = (final: string) => {\n if (csiOverflow || !csiHonoured) return\n // Only plain numeric parameters are honoured; a private marker (`?`, `>`,\n // `<`, `=`) or an intermediate byte makes this some other command entirely.\n if (!/^[\\d;:]*$/.test(csi)) return\n if (final === 'm') style = applySgr(style, csi)\n else if (final === 'K') {\n const mode = toNumber(csi.split(';')[0])\n if (mode !== undefined && mode <= 2) line.eraseInLine(mode)\n }\n }\n\n function write(chunk: string): void {\n for (let i = 0; i < chunk.length; i += 1) {\n const code = chunk.charCodeAt(i)\n\n switch (state) {\n case 'text': {\n if (!isDroppedControl(code)) {\n // Take the whole run of ordinary characters at once.\n let end = i + 1\n while (end < chunk.length && !isDroppedControl(chunk.charCodeAt(end))) end += 1\n line.put(chunk.slice(i, end), style)\n i = end - 1\n break\n }\n if (code === 0x1b) state = 'esc'\n else if (code === 0x0a) finishLine()\n else if (code === 0x0d) line.carriageReturn()\n else if (code === 0x08) line.backspace()\n else if (code === 0x9b) {\n state = 'csi'\n csi = ''\n csiOverflow = false\n csiHonoured = false\n } else if (\n code === 0x9d ||\n code === 0x90 ||\n code === 0x98 ||\n code === 0x9e ||\n code === 0x9f\n ) {\n state = 'string'\n }\n // Every other control character is dropped.\n break\n }\n case 'esc': {\n if (code === 0x5b) {\n state = 'csi'\n csi = ''\n csiOverflow = false\n csiHonoured = true\n } else if (\n code === 0x5d ||\n code === 0x50 ||\n code === 0x58 ||\n code === 0x5e ||\n code === 0x5f\n ) {\n state = 'string'\n } else if (code >= 0x20 && code <= 0x2f) state = 'esc-intermediate'\n else if (code >= 0x30 && code <= 0x7e) state = 'text'\n else if (code === 0x1b) state = 'esc'\n else {\n state = 'text'\n i -= 1\n }\n break\n }\n case 'esc-intermediate': {\n if (code >= 0x20 && code <= 0x2f) break\n if (code >= 0x30 && code <= 0x7e) state = 'text'\n else {\n state = 'text'\n i -= 1\n }\n break\n }\n case 'csi': {\n if (code >= 0x20 && code <= 0x3f) {\n if (csi.length < CSI_MAX) csi += chunk[i]\n else csiOverflow = true\n } else if (code >= 0x40 && code <= 0x7e) {\n runCsi(chunk[i]!)\n state = 'text'\n } else if (code === 0x1b) state = 'esc'\n else {\n // A control character or non-ASCII byte cannot be part of a CSI: the\n // sequence was malformed. Drop it and read this character normally.\n state = 'text'\n i -= 1\n }\n break\n }\n case 'string': {\n if (code === 0x07 || code === 0x9c) state = 'text'\n else if (code === 0x1b) state = 'string-esc'\n else if (code === 0x0a || code === 0x0d) {\n // No real title or clipboard payload spans a line. Ending here bounds\n // what an unterminated string can swallow to the rest of its line.\n state = 'text'\n i -= 1\n }\n break\n }\n case 'string-esc': {\n if (code === 0x5c) state = 'text'\n else {\n state = 'esc'\n i -= 1\n }\n break\n }\n }\n }\n }\n\n return {\n write,\n lines,\n openLine: () => (line.isEmpty() ? undefined : line.snapshot()),\n get droppedLines() {\n return droppedLines\n },\n }\n}\n\n/** Parse a whole output at once: finished lines plus the open one, if any. */\nexport function parseAnsi(text: string, options?: AnsiParserOptions): AnsiLine[] {\n const parser = createAnsiParser(options)\n parser.write(text)\n const open = parser.openLine()\n return open ? [...parser.lines, open] : [...parser.lines]\n}\n\n/**\n * The whole output as a reader sees it, for the clipboard: every line, none\n * shortened, with escape sequences and overwritten text resolved away.\n */\nexport function ansiPlainText(text: string): string {\n const parser = createAnsiParser({\n maxLineLength: Number.POSITIVE_INFINITY,\n retainLines: Number.POSITIVE_INFINITY,\n })\n parser.write(text)\n const open = parser.openLine()\n // Finished lines carry their newline even when only control sequences follow.\n return [...parser.lines.map(ansiLineText), open ? ansiLineText(open) : ''].join('\\n')\n}\n\n/** A line's text with styling removed, for tests and for accessible names. */\nexport function ansiLineText(line: AnsiLine): string {\n return line.segments.map((segment) => segment.text).join('')\n}\n"],"mappings":";AAiFA,IAAa,uBAAuB;AACpC,IAAa,oBAAoB;;AAGjC,IAAM,UAAU;AAEhB,IAAM,QAAmB,OAAO,OAAO,CAAC,CAAC;AACzC,IAAM,6BAAa,IAAI,IAAuB;AAC9C,IAAM,oBAAoB;;;;;;AAO1B,SAAS,OAAO,OASF;CACZ,MAAM,MAAM;EACV,MAAM,MAAM;EACZ,MAAM,MAAM;EACZ,MAAM,OAAO,MAAM;EACnB,MAAM,MAAM,MAAM;EAClB,MAAM,SAAS,MAAM;EACrB,MAAM,YAAY,MAAM;EACxB,MAAM,SAAS,MAAM;EACrB,MAAM,UAAU,MAAM;CACxB,CAAC,CAAC,KAAK,GAAG;CACV,IAAI,QAAQ,WAAW,OAAO;CAC9B,MAAM,SAAS,WAAW,IAAI,GAAG;CACjC,IAAI,QAAQ,OAAO;CACnB,MAAM,OAAkB,OAAO,OAAO;EACpC,GAAI,MAAM,OAAO,KAAA,KAAa,EAAE,IAAI,MAAM,GAAG;EAC7C,GAAI,MAAM,OAAO,KAAA,KAAa,EAAE,IAAI,MAAM,GAAG;EAC7C,GAAI,MAAM,QAAQ,EAAE,MAAM,KAAc;EACxC,GAAI,MAAM,OAAO,EAAE,KAAK,KAAc;EACtC,GAAI,MAAM,UAAU,EAAE,QAAQ,KAAc;EAC5C,GAAI,MAAM,aAAa,EAAE,WAAW,KAAc;EAClD,GAAI,MAAM,UAAU,EAAE,QAAQ,KAAc;EAC5C,GAAI,MAAM,WAAW,EAAE,SAAS,KAAc;CAChD,CAAC;CACD,IAAI,WAAW,OAAO,mBAAmB,WAAW,IAAI,KAAK,IAAI;CACjE,OAAO;AACT;;AAGA,SAAgB,aAAa,OAA2B;CACtD,OACE,MAAM,OAAO,KAAA,KACb,MAAM,OAAO,KA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,OAAO,OAAO,SAAS;CAE7B,OAAO,CAAC,GAAG,OAAO,MAAM,IAAI,YAAY,GAAG,OAAO,aAAa,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,IAAI;AACtF;;AAGA,SAAgB,aAAa,MAAwB;CACnD,OAAO,KAAK,SAAS,KAAK,YAAY,QAAQ,IAAI,CAAC,CAAC,KAAK,EAAE;AAC7D"}
@@ -1 +1 @@
1
- {"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/terminal/terminal.tsx"],"names":[],"mappings":"AASA,OAAO,EAQL,KAAK,cAAc,EACpB,MAAM,UAAU,CAAA;AAWjB,OAAO,EAML,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAA;AAEzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,GAAG;IACpE,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAA;IACd,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB,8FAA8F;IAC9F,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,yFAAyF;IACzF,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,4FAA4F;IAC5F,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC3B,sGAAsG;IACtG,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,wEAAwE;IACxE,IAAI,CAAC,EAAE,SAAS,GAAG,IAAI,CAAA;IACvB,0FAA0F;IAC1F,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,6EAA6E;IAC7E,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,IAAI,CAAA;CAC/B,CAAA;AAED,yCAAyC;AACzC,eAAO,MAAM,kBAAkB,OAAO,CAAA;AAwItC,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,kCA2T5C"}
1
+ {"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/terminal/terminal.tsx"],"names":[],"mappings":"AASA,OAAO,EAQL,KAAK,cAAc,EACpB,MAAM,UAAU,CAAA;AAYjB,OAAO,EAML,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAA;AAEzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,GAAG;IACpE,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAA;IACd,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB,8FAA8F;IAC9F,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,yFAAyF;IACzF,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,4FAA4F;IAC5F,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC3B,sGAAsG;IACtG,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,wEAAwE;IACxE,IAAI,CAAC,EAAE,SAAS,GAAG,IAAI,CAAA;IACvB,0FAA0F;IAC1F,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,6EAA6E;IAC7E,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,IAAI,CAAA;CAC/B,CAAA;AAED,yCAAyC;AACzC,eAAO,MAAM,kBAAkB,OAAO,CAAA;AAwItC,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,kCA2T5C"}
@@ -1,7 +1,7 @@
1
1
  import { writeClipboardText } from "../../../lib/clipboard.js";
2
2
  import { cn } from "../../../lib/utils.js";
3
3
  import { Button } from "../../ui/button/button.js";
4
- import { createAnsiParser, isPlainStyle, resolveColors } from "./ansi.js";
4
+ import { ansiPlainText, createAnsiParser, isPlainStyle, resolveColors } from "./ansi.js";
5
5
  import { isAtBottom, isFailedExit, revealEarlier, terminalStatusLabel, terminalWindow } from "./terminal-model.js";
6
6
  import { className, createComponent, effect, insert, memo, mergeProps, setAttribute, setStyleProperty, spread, template, use } from "solid-js/web";
7
7
  import { ArrowDown, Check, CircleAlert, CircleSlash, Copy, Eraser, LoaderCircle } from "lucide-solid";
@@ -264,7 +264,7 @@ function Terminal$1(props) {
264
264
  const copy = async () => {
265
265
  let ok = true;
266
266
  try {
267
- await writeClipboardText(local.output);
267
+ await writeClipboardText(ansiPlainText(local.output));
268
268
  } catch {
269
269
  ok = false;
270
270
  }
@@ -1 +1 @@
1
- {"version":3,"file":"terminal.js","names":["ArrowDown","Check","CircleAlert","CircleSlash","Copy","Eraser","LoaderCircle","createEffect","createMemo","createSignal","For","on","Show","splitProps","ComponentProps","writeClipboardText","cn","Button","createAnsiParser","isPlainStyle","resolveColors","AnsiLine","AnsiStyle","isAtBottom","isFailedExit","revealEarlier","terminalStatusLabel","terminalWindow","TerminalStatus","TerminalProps","Omit","output","command","status","maxLines","retainLines","maxHeight","wrap","size","onClear","copyLabel","copiedLabel","clearLabel","onCopy","ok","TERMINAL_MAX_LINES","FG_CLASS","const","BG_CLASS","segmentClass","style","fg","bg","bold","dim","italic","underline","strike","LineView","props","line","_el$","_tmpl$2","_$insert","_$createComponent","each","segments","children","segment","text","_el$7","_tmpl$3","_$effect","_$className","when","truncated","_el$2","_tmpl$","_el$3","firstChild","_el$6","nextSibling","_el$5","toLocaleString","sameAnsiLine","left","right","length","every","index","StatusReadout","_el$8","_tmpl$5","state","_el$9","_tmpl$4","fallback","_p$","_v$","_v$2","e","_$setAttribute","t","undefined","Terminal","local","rest","small","pageSize","Math","max","floor","newParser","parser","consumed","epoch","revision","next","startsWith","write","slice","equals","limit","setLimit","defer","empty","outputRows","rows","lines","open","openLine","push","parked","setParked","end","total","droppedLines","anchorEnd","current","position","lineWindow","visibleRows","start","retainedIndex","changedParkedLine","newerRows","later","scroller","HTMLDivElement","following","onScroll","atEnd","scrollHeight","scrollTop","clientHeight","currentEpoch","jumpToLatest","focus","copied","setCopied","copyFailed","setCopyFailed","copy","setTimeout","regionLabel","_el$0","_tmpl$0","_el$1","_el$13","_el$16","_el$17","_$spread","_$mergeProps","data-size","aria-busy","class","_tmpl$1","_el$10","_tmpl$6","_el$11","_el$12","_$memo","variant","aria-label","onClick","title","hidden","evicted","_el$14","_tmpl$7","_el$15","lost","revealable","min","addEventListener","_$use","element","_el$26","_tmpl$10","_el$27","_el$18","_tmpl$8","_el$19","_tmpl$9","_el$20","_el$23","_el$21","_el$24","_el$22","_v$3","_v$4","_v$5","a","_$setStyleProperty","_$createComponent","_$className","_$setAttribute","Terminal","_$mergeProps","_$memo","_$setStyleProperty"],"sources":["../../../../src/components/composites/terminal/terminal.tsx"],"sourcesContent":["import {\n ArrowDown,\n Check,\n CircleAlert,\n CircleSlash,\n Copy,\n Eraser,\n LoaderCircle,\n} from 'lucide-solid'\nimport {\n createEffect,\n createMemo,\n createSignal,\n For,\n on,\n Show,\n splitProps,\n type ComponentProps,\n} from 'solid-js'\nimport { writeClipboardText } from '#lib/clipboard'\nimport { cn } from '#lib/utils'\nimport { Button } from '../../ui/button'\nimport {\n createAnsiParser,\n isPlainStyle,\n resolveColors,\n type AnsiLine,\n type AnsiStyle,\n} from './ansi'\nimport {\n isAtBottom,\n isFailedExit,\n revealEarlier,\n terminalStatusLabel,\n terminalWindow,\n type TerminalStatus,\n} from './terminal-model'\n\n/**\n * Terminal.\n *\n * A command and its output, as it arrives. It is the thing to put inside an\n * agent's \"ran a command\" line (a `TraceLine`, with `size=\"sm\"`) when the output\n * is the evidence; reach for `CodeBlock` instead when the text is source or a\n * finished log that needs no live behaviour, and for `TestResults` when the\n * output is a test run the host can structure.\n *\n * It does not wrap `CodeBlock`. A block's `highlight` seam re-renders the whole\n * body whenever the code changes, which is exactly wrong for output that grows a\n * line at a time, and a terminal has to own its scroller to follow the tail. It\n * keeps the block's header and surface vocabulary so the two read as one family.\n *\n * ## What the output is allowed to do\n *\n * Output is untrusted bytes. It is parsed by `createAnsiParser` into plain text\n * and a fixed set of styles — sixteen theme colours, bold, dim, italic,\n * underline, strike-through, reverse — and everything else (cursor movement,\n * title and clipboard sequences, anything malformed) is dropped, never echoed.\n * Colours come from the theme's `--terminal-ansi-*` tokens, painted on the\n * theme's own terminal background, so a program's colours keep the contrast the\n * theme measured for them. Nothing is rendered as markup.\n *\n * ## Streaming\n *\n * `output` is the whole string so far. When the new value begins with the old\n * one, only the appended text is parsed, so a chunk costs the size of the chunk\n * and not of the transcript. Finished lines are keyed by identity and are never\n * re-rendered; only the line still being written changes, which is what makes a\n * `\\r` progress bar redraw in place. Batch appends per frame — the host sees a\n * prefix check proportional to the output on every change.\n *\n * Only the last `maxLines` finished lines are mounted. The rest are counted in\n * an explicit note with a control to show them a page at a time, because tens of\n * thousands of row elements are a frozen page, not a transcript. Copy still\n * writes `output` exactly as given — not the rendered lines, not the visible tail.\n *\n * ## Following the tail\n *\n * The terminal scrolls inside its own bounded box and follows new output only\n * while the reader is at the bottom of that box. Scrolling up *parks* the view:\n * the lines mounted are the ones that were there when they left, however much\n * output arrives, and \"Jump to latest\" is the only way back to the tail (reaching\n * the bottom of a parked view with nothing newer resumes it, because nothing was\n * missed). If retention discards the lines they were reading the note says how\n * many, and when none are left the oldest retained lines are shown. The page\n * itself is never scrolled. Scrolling is instant, so there is no animation to\n * reduce.\n *\n * ## Status is a claim\n *\n * `status` is drawn only when the host passes it, in words as well as an icon,\n * and only a non-zero exit is toned as a failure: this component does not decide\n * that a command \"passed\". Without a status the header says nothing about whether\n * the command is still running. `onClear` adds a clear button; without it the\n * output is the host's record and nothing here offers to erase it.\n */\nexport type TerminalProps = Omit<ComponentProps<'div'>, 'children'> & {\n /** Everything the command has printed so far, exactly as received. */\n output: string\n /** The command line. Shown as text; the prompt glyph is decoration. */\n command?: string\n status?: TerminalStatus\n /** Finished lines mounted at once; earlier ones are counted and revealed a page at a time. */\n maxLines?: number\n /** Finished lines kept at all; older ones are discarded and counted. Default 200 000. */\n retainLines?: number\n /** Height of the output box, which scrolls past it. A number is pixels. Default `20rem`. */\n maxHeight?: number | string\n /** Soft-wrap long lines instead of scrolling sideways. Off: terminal columns keep their alignment. */\n wrap?: boolean\n /** `sm` is the compact chrome for output nested inside a Trace line. */\n size?: 'default' | 'sm'\n /** Show a clear button. The host empties `output`; the terminal erases nothing itself. */\n onClear?: () => void\n copyLabel?: string\n copiedLabel?: string\n clearLabel?: string\n /** Called after each copy attempt with whether the clipboard accepted it. */\n onCopy?: (ok: boolean) => void\n}\n\n/** Finished lines mounted by default. */\nexport const TERMINAL_MAX_LINES = 1000\n\n// One literal class per colour, written out in full so the stylesheet generator\n// can see each of them; a class assembled from an index would never be emitted.\nconst FG_CLASS = [\n 'text-(color:--terminal-ansi-black)',\n 'text-(color:--terminal-ansi-red)',\n 'text-(color:--terminal-ansi-green)',\n 'text-(color:--terminal-ansi-yellow)',\n 'text-(color:--terminal-ansi-blue)',\n 'text-(color:--terminal-ansi-magenta)',\n 'text-(color:--terminal-ansi-cyan)',\n 'text-(color:--terminal-ansi-white)',\n 'text-(color:--terminal-ansi-bright-black)',\n 'text-(color:--terminal-ansi-bright-red)',\n 'text-(color:--terminal-ansi-bright-green)',\n 'text-(color:--terminal-ansi-bright-yellow)',\n 'text-(color:--terminal-ansi-bright-blue)',\n 'text-(color:--terminal-ansi-bright-magenta)',\n 'text-(color:--terminal-ansi-bright-cyan)',\n 'text-(color:--terminal-ansi-bright-white)',\n] as const\nconst BG_CLASS = [\n 'bg-(--terminal-ansi-black)',\n 'bg-(--terminal-ansi-red)',\n 'bg-(--terminal-ansi-green)',\n 'bg-(--terminal-ansi-yellow)',\n 'bg-(--terminal-ansi-blue)',\n 'bg-(--terminal-ansi-magenta)',\n 'bg-(--terminal-ansi-cyan)',\n 'bg-(--terminal-ansi-white)',\n 'bg-(--terminal-ansi-bright-black)',\n 'bg-(--terminal-ansi-bright-red)',\n 'bg-(--terminal-ansi-bright-green)',\n 'bg-(--terminal-ansi-bright-yellow)',\n 'bg-(--terminal-ansi-bright-blue)',\n 'bg-(--terminal-ansi-bright-magenta)',\n 'bg-(--terminal-ansi-bright-cyan)',\n 'bg-(--terminal-ansi-bright-white)',\n] as const\n\nfunction segmentClass(style: AnsiStyle): string {\n const { fg, bg } = resolveColors(style)\n return cn(\n {\n 'font-bold': style.bold,\n 'opacity-70': style.dim,\n italic: style.italic,\n underline: style.underline && !style.strike,\n 'line-through': style.strike && !style.underline,\n '[text-decoration-line:underline_line-through]': style.underline && style.strike,\n 'text-(color:--terminal-background)': fg === 'default-bg',\n 'bg-(--terminal-foreground)': bg === 'default-fg',\n },\n typeof fg === 'number' && FG_CLASS[fg],\n typeof bg === 'number' && BG_CLASS[bg]\n )\n}\n\nfunction LineView(props: { line: AnsiLine; wrap: boolean }) {\n return (\n // `min-h-lh` keeps an empty line one line tall; a block with no text would\n // collapse and the transcript would lose its blank lines.\n <div\n class={cn('min-h-lh', {\n 'whitespace-pre-wrap [overflow-wrap:anywhere]': props.wrap,\n 'w-max min-w-full': !props.wrap,\n })}\n >\n <For each={props.line.segments}>\n {(segment) =>\n isPlainStyle(segment.style) ? (\n segment.text\n ) : (\n <span class={segmentClass(segment.style)}>{segment.text}</span>\n )\n }\n </For>\n <Show when={props.line.truncated > 0}>\n <span class=\"opacity-70 select-none\">\n {' '}\n … {props.line.truncated.toLocaleString()} more characters not shown\n </span>\n </Show>\n </div>\n )\n}\n\nfunction sameAnsiLine(left: AnsiLine, right: AnsiLine): boolean {\n return (\n left.truncated === right.truncated &&\n left.segments.length === right.segments.length &&\n left.segments.every(\n (segment, index) =>\n segment.text === right.segments[index]?.text &&\n segment.style === right.segments[index]?.style\n )\n )\n}\n\nfunction StatusReadout(props: { status: TerminalStatus }) {\n return (\n // A live region, so a command that finishes while the reader is elsewhere is\n // announced once, in words.\n <span\n role=\"status\"\n data-slot=\"terminal-status\"\n data-state={props.status.state}\n class={cn('flex shrink-0 items-center gap-1 text-xs', {\n 'text-destructive': isFailedExit(props.status),\n 'text-info': props.status.state === 'running',\n 'text-muted-foreground': props.status.state !== 'running' && !isFailedExit(props.status),\n })}\n >\n {/* A zero exit gets no glyph: a tick would be this component deciding the\n command succeeded, and some tools exit non-zero on purpose or zero on\n failure. The words carry the fact; only a non-zero code is toned. */}\n <Show when={props.status.state !== 'exited' || isFailedExit(props.status)}>\n <span aria-hidden=\"true\" class=\"grid size-3.5 place-items-center [&_svg]:size-3.5\">\n <Show\n when={props.status.state === 'running'}\n fallback={\n <Show when={props.status.state === 'cancelled'} fallback={<CircleAlert />}>\n <CircleSlash />\n </Show>\n }\n >\n <LoaderCircle class=\"motion-safe:animate-spin\" />\n </Show>\n </span>\n </Show>\n {terminalStatusLabel(props.status)}\n </span>\n )\n}\n\nexport function Terminal(props: TerminalProps) {\n const [local, rest] = splitProps(props, [\n 'output',\n 'command',\n 'status',\n 'maxLines',\n 'retainLines',\n 'maxHeight',\n 'wrap',\n 'size',\n 'onClear',\n 'copyLabel',\n 'copiedLabel',\n 'clearLabel',\n 'onCopy',\n 'class',\n ])\n\n const small = () => local.size === 'sm'\n const pageSize = () => Math.max(1, Math.floor(local.maxLines ?? TERMINAL_MAX_LINES))\n const maxHeight = () =>\n typeof local.maxHeight === 'number' ? `${local.maxHeight}px` : (local.maxHeight ?? '20rem')\n\n // The parser outlives renders: it holds the half-read escape sequence, the\n // current style and the open line. A new `output` that extends the old one is\n // fed only its tail; anything else (a clear, a different command) starts over.\n const newParser = () => createAnsiParser({ retainLines: local.retainLines })\n let parser = newParser()\n let consumed = ''\n // Bumped when the output restarts, so a parked position from the old output\n // is never applied to the new one.\n let epoch = 0\n const revision = createMemo(\n () => {\n const next = local.output\n if (next.length >= consumed.length && next.startsWith(consumed)) {\n parser.write(next.slice(consumed.length))\n } else {\n parser = newParser()\n parser.write(next)\n epoch += 1\n }\n consumed = next\n return epoch\n },\n undefined,\n { equals: false }\n )\n\n const [limit, setLimit] = createSignal(pageSize())\n createEffect(on(pageSize, (size) => setLimit(size), { defer: true }))\n // A cleared terminal is a fresh one: the next command starts at the page size.\n createEffect(\n on(\n () => local.output === '',\n (empty) => {\n if (empty) setLimit(pageSize())\n },\n { defer: true }\n )\n )\n\n const outputRows = createMemo(\n () => {\n revision()\n const rows = parser.lines.slice()\n const open = parser.openLine()\n if (open) rows.push(open)\n return rows\n },\n [],\n { equals: false }\n )\n // Where the reader parked, as a count of lines since the output began. An open\n // line is a row too: freeze its snapshot so streamed characters and CR redraws\n // do not rewrite the text under a parked reader.\n const [parked, setParked] = createSignal<{ epoch: number; end: number; open?: AnsiLine }>()\n const total = () => parser.droppedLines + outputRows().length\n const anchorEnd = () => {\n const current = revision()\n const position = parked()\n return position && position.epoch === current ? position.end : undefined\n }\n const lineWindow = createMemo(() => {\n revision()\n return terminalWindow(outputRows().length, parser.droppedLines, limit(), anchorEnd())\n })\n // Finished rows keep their parser identity. If an open row existed when the\n // reader parked, substitute its immutable snapshot until they jump to latest.\n const visibleRows = createMemo(\n () => {\n revision()\n const start = lineWindow().start\n const end = lineWindow().end\n const rows = outputRows().slice(start, end)\n const position = parked()\n if (position?.epoch === revision() && position.open) {\n const retainedIndex = position.end - 1 - parser.droppedLines\n if (retainedIndex >= start && retainedIndex < end) {\n rows[retainedIndex - start] = position.open\n }\n }\n return rows\n },\n [],\n { equals: false }\n )\n const changedParkedLine = () => {\n const position = parked()\n if (position?.epoch !== revision() || !position.open) return false\n const retainedIndex = position.end - 1 - parser.droppedLines\n const current = outputRows()[retainedIndex]\n return current !== undefined && !sameAnsiLine(position.open, current)\n }\n const newerRows = () => lineWindow().later + (changedParkedLine() ? 1 : 0)\n\n let scroller: HTMLDivElement | undefined\n const following = () => anchorEnd() === undefined\n\n const onScroll = () => {\n if (!scroller) return\n const atEnd = isAtBottom(scroller.scrollHeight, scroller.scrollTop, scroller.clientHeight)\n const position = anchorEnd()\n if (!atEnd) {\n if (position === undefined) {\n const currentEpoch = revision()\n setParked({ epoch: currentEpoch, end: total(), open: parser.openLine() })\n }\n } else if (position !== undefined && position >= total() && !changedParkedLine()) {\n // Back at the end of a view with nothing newer: nothing was missed.\n setParked(undefined)\n }\n }\n createEffect(\n on(revision, () => {\n if (scroller && following()) scroller.scrollTop = scroller.scrollHeight\n })\n )\n const jumpToLatest = () => {\n if (!scroller) return\n setParked(undefined)\n scroller.scrollTop = scroller.scrollHeight\n // The button is about to disappear; leave focus somewhere real.\n scroller.focus()\n }\n\n const [copied, setCopied] = createSignal(false)\n const [copyFailed, setCopyFailed] = createSignal(false)\n const copy = async () => {\n let ok = true\n try {\n await writeClipboardText(local.output)\n } catch {\n ok = false\n }\n setCopied(ok)\n setCopyFailed(!ok)\n local.onCopy?.(ok)\n if (ok) setTimeout(() => setCopied(false), 1500)\n }\n\n const empty = () => local.output === ''\n const regionLabel = () =>\n local.command ? `Output of ${local.command.slice(0, 120)}` : 'Terminal output'\n\n return (\n <div\n data-slot=\"terminal\"\n data-size={local.size ?? 'default'}\n aria-busy={local.status?.state === 'running' || undefined}\n class={cn(\n 'group/terminal overflow-hidden border border-border bg-card',\n small() ? 'rounded-lg' : 'rounded-xl',\n local.class\n )}\n {...rest}\n >\n <div class={cn('flex items-center gap-2', small() ? 'px-2 py-0.5' : 'px-3 py-1')}>\n <Show\n when={local.command !== undefined}\n fallback={<span class=\"flex-1 text-xs text-muted-foreground\">Terminal</span>}\n >\n <span class=\"flex min-w-0 flex-1 items-baseline gap-2\">\n <span\n aria-hidden=\"true\"\n class=\"shrink-0 font-code text-code text-muted-foreground select-none\"\n >\n $\n </span>\n <code\n title={local.command}\n class=\"line-clamp-2 min-w-0 font-code text-code text-foreground [overflow-wrap:anywhere]\"\n >\n {local.command}\n </code>\n </span>\n </Show>\n <Show when={local.status}>{(status) => <StatusReadout status={status()} />}</Show>\n {/* Hidden until the terminal is hovered or holds focus, never removed:\n a control that only exists under the pointer is unreachable by\n keyboard, and a touch screen has no hover, so it always shows there. */}\n <div class=\"flex items-center gap-1 opacity-0 transition-opacity group-focus-within/terminal:opacity-100 group-hover/terminal:opacity-100 [@media(hover:none)]:opacity-100\">\n <Show when={local.onClear !== undefined && !empty()}>\n <Button\n variant=\"ghost\"\n size=\"icon-2xs\"\n aria-label={local.clearLabel ?? 'Clear output'}\n onClick={() => local.onClear?.()}\n >\n <Eraser aria-hidden=\"true\" />\n </Button>\n </Show>\n <Show when={!empty()}>\n <Button\n variant=\"ghost\"\n size=\"icon-2xs\"\n aria-label={\n copied() ? (local.copiedLabel ?? 'Copied') : (local.copyLabel ?? 'Copy output')\n }\n title={copyFailed() ? 'Copying is unavailable in this context' : undefined}\n onClick={() => void copy()}\n >\n <Show when={copied()} fallback={<Copy aria-hidden=\"true\" />}>\n <Check aria-hidden=\"true\" />\n </Show>\n </Button>\n </Show>\n </div>\n </div>\n\n <Show when={lineWindow().hidden > 0 || lineWindow().evicted > 0}>\n <div\n data-slot=\"terminal-hidden-note\"\n class=\"flex items-center gap-2 border-t border-border px-3 py-1 text-xs text-muted-foreground\"\n >\n <span>\n <Show when={lineWindow().hidden > 0}>\n {lineWindow().hidden.toLocaleString()} earlier{' '}\n {lineWindow().hidden === 1 ? 'line' : 'lines'} hidden\n <Show when={parser.droppedLines > 0}>\n {' '}\n ({parser.droppedLines.toLocaleString()} only in the copy)\n </Show>\n .\n </Show>\n <Show when={lineWindow().evicted > 0}>\n {' '}\n {lineWindow().lost\n ? `The lines you were reading were discarded to keep memory bounded; showing the oldest ${lineWindow().end.toLocaleString()} still kept.`\n : `${lineWindow().evicted.toLocaleString()} of the lines you were reading were discarded to keep memory bounded.`}\n </Show>\n </span>\n <Show when={lineWindow().revealable > 0}>\n <Button\n variant=\"ghost\"\n size=\"2xs\"\n onClick={() => setLimit(revealEarlier(limit(), pageSize(), outputRows().length))}\n >\n Show {Math.min(pageSize(), lineWindow().revealable).toLocaleString()} earlier\n </Button>\n </Show>\n </div>\n </Show>\n\n <div class=\"relative\">\n <div\n ref={(element) => (scroller = element)}\n data-slot=\"terminal-body\"\n // A region that scrolls must be focusable, and a tab stop needs a name.\n role=\"region\"\n tabindex=\"0\"\n aria-label={regionLabel()}\n onScroll={onScroll}\n style={{ 'max-height': maxHeight() }}\n class=\"scroll-fade overflow-auto border-t border-border bg-(--terminal-background) text-(color:--terminal-foreground)\"\n >\n <Show\n when={!empty()}\n fallback={\n <p class={cn('m-0 opacity-70', small() ? 'px-2 py-1.5' : 'px-3 py-2')}>\n <span class=\"font-code text-code\">\n {local.status?.state === 'running' ? 'Waiting for output…' : 'No output'}\n </span>\n </p>\n }\n >\n <pre\n class={cn(\n 'm-0 font-code text-code leading-normal',\n small() ? 'px-2 py-1.5' : 'px-3 py-2'\n )}\n >\n <For each={visibleRows()}>\n {(line) => <LineView line={line} wrap={local.wrap === true} />}\n </For>\n </pre>\n </Show>\n </div>\n <Show when={newerRows() > 0}>\n <Button\n variant=\"secondary\"\n size=\"2xs\"\n class=\"absolute end-3 bottom-2 shadow-sm\"\n onClick={jumpToLatest}\n >\n <ArrowDown aria-hidden=\"true\" />\n Jump to latest\n <span class=\"text-muted-foreground tabular-nums\">\n ({newerRows().toLocaleString()} newer {newerRows() === 1 ? 'line' : 'lines'})\n </span>\n </Button>\n </Show>\n </div>\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0HA,IAAa6C,qBAAqB;AAIlC,IAAMC,WAAW;CACf;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAA2C;AA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iBAAA3C,QAAA,cAAAzE,IAAAmH,IAAAD,IAAA;GAAA,OAAAlH;EAAA,GAAA;GAAAG,GAAAG,KAAAA;GAAAD,GAAAC,KAAAA;GAAA6G,GAAA7G,KAAAA;EAAA,CAAA;EAAA,OAAA8D;CAAA,EAAA,CAAA;AA0C5C"}
1
+ {"version":3,"file":"terminal.js","names":["ArrowDown","Check","CircleAlert","CircleSlash","Copy","Eraser","LoaderCircle","createEffect","createMemo","createSignal","For","on","Show","splitProps","ComponentProps","writeClipboardText","cn","Button","createAnsiParser","isPlainStyle","resolveColors","AnsiLine","AnsiStyle","ansiPlainText","isAtBottom","isFailedExit","revealEarlier","terminalStatusLabel","terminalWindow","TerminalStatus","TerminalProps","Omit","output","command","status","maxLines","retainLines","maxHeight","wrap","size","onClear","copyLabel","copiedLabel","clearLabel","onCopy","ok","TERMINAL_MAX_LINES","FG_CLASS","const","BG_CLASS","segmentClass","style","fg","bg","bold","dim","italic","underline","strike","LineView","props","line","_el$","_tmpl$2","_$insert","_$createComponent","each","segments","children","segment","text","_el$7","_tmpl$3","_$effect","_$className","when","truncated","_el$2","_tmpl$","_el$3","firstChild","_el$6","nextSibling","_el$5","toLocaleString","sameAnsiLine","left","right","length","every","index","StatusReadout","_el$8","_tmpl$5","state","_el$9","_tmpl$4","fallback","_p$","_v$","_v$2","e","_$setAttribute","t","undefined","Terminal","local","rest","small","pageSize","Math","max","floor","newParser","parser","consumed","epoch","revision","next","startsWith","write","slice","equals","limit","setLimit","defer","empty","outputRows","rows","lines","open","openLine","push","parked","setParked","end","total","droppedLines","anchorEnd","current","position","lineWindow","visibleRows","start","retainedIndex","changedParkedLine","newerRows","later","scroller","HTMLDivElement","following","onScroll","atEnd","scrollHeight","scrollTop","clientHeight","currentEpoch","jumpToLatest","focus","copied","setCopied","copyFailed","setCopyFailed","copy","setTimeout","regionLabel","_el$0","_tmpl$0","_el$1","_el$13","_el$16","_el$17","_$spread","_$mergeProps","data-size","aria-busy","class","_tmpl$1","_el$10","_tmpl$6","_el$11","_el$12","_$memo","variant","aria-label","onClick","title","hidden","evicted","_el$14","_tmpl$7","_el$15","lost","revealable","min","addEventListener","_$use","element","_el$26","_tmpl$10","_el$27","_el$18","_tmpl$8","_el$19","_tmpl$9","_el$20","_el$23","_el$21","_el$24","_el$22","_v$3","_v$4","_v$5","a","_$setStyleProperty","_$createComponent","_$className","_$setAttribute","Terminal","_$mergeProps","_$memo","_$setStyleProperty"],"sources":["../../../../src/components/composites/terminal/terminal.tsx"],"sourcesContent":["import {\n ArrowDown,\n Check,\n CircleAlert,\n CircleSlash,\n Copy,\n Eraser,\n LoaderCircle,\n} from 'lucide-solid'\nimport {\n createEffect,\n createMemo,\n createSignal,\n For,\n on,\n Show,\n splitProps,\n type ComponentProps,\n} from 'solid-js'\nimport { writeClipboardText } from '#lib/clipboard'\nimport { cn } from '#lib/utils'\nimport { Button } from '../../ui/button'\nimport {\n createAnsiParser,\n isPlainStyle,\n resolveColors,\n type AnsiLine,\n type AnsiStyle,\n ansiPlainText,\n} from './ansi'\nimport {\n isAtBottom,\n isFailedExit,\n revealEarlier,\n terminalStatusLabel,\n terminalWindow,\n type TerminalStatus,\n} from './terminal-model'\n\n/**\n * Terminal.\n *\n * A command and its output, as it arrives. It is the thing to put inside an\n * agent's \"ran a command\" line (a `TraceLine`, with `size=\"sm\"`) when the output\n * is the evidence; reach for `CodeBlock` instead when the text is source or a\n * finished log that needs no live behaviour, and for `TestResults` when the\n * output is a test run the host can structure.\n *\n * It does not wrap `CodeBlock`. A block's `highlight` seam re-renders the whole\n * body whenever the code changes, which is exactly wrong for output that grows a\n * line at a time, and a terminal has to own its scroller to follow the tail. It\n * keeps the block's header and surface vocabulary so the two read as one family.\n *\n * ## What the output is allowed to do\n *\n * Output is untrusted bytes. It is parsed by `createAnsiParser` into plain text\n * and a fixed set of styles — sixteen theme colours, bold, dim, italic,\n * underline, strike-through, reverse — and everything else (cursor movement,\n * title and clipboard sequences, anything malformed) is dropped, never echoed.\n * Colours come from the theme's `--terminal-ansi-*` tokens, painted on the\n * theme's own terminal background, so a program's colours keep the contrast the\n * theme measured for them. Nothing is rendered as markup.\n *\n * ## Streaming\n *\n * `output` is the whole string so far. When the new value begins with the old\n * one, only the appended text is parsed, so a chunk costs the size of the chunk\n * and not of the transcript. Finished lines are keyed by identity and are never\n * re-rendered; only the line still being written changes, which is what makes a\n * `\\r` progress bar redraw in place. Batch appends per frame — the host sees a\n * prefix check proportional to the output on every change.\n *\n * Only the last `maxLines` finished lines are mounted. The rest are counted in\n * an explicit note with a control to show them a page at a time, because tens of\n * thousands of row elements are a frozen page, not a transcript. Copy still\n * writes `output` exactly as given — not the rendered lines, not the visible tail.\n *\n * ## Following the tail\n *\n * The terminal scrolls inside its own bounded box and follows new output only\n * while the reader is at the bottom of that box. Scrolling up *parks* the view:\n * the lines mounted are the ones that were there when they left, however much\n * output arrives, and \"Jump to latest\" is the only way back to the tail (reaching\n * the bottom of a parked view with nothing newer resumes it, because nothing was\n * missed). If retention discards the lines they were reading the note says how\n * many, and when none are left the oldest retained lines are shown. The page\n * itself is never scrolled. Scrolling is instant, so there is no animation to\n * reduce.\n *\n * ## Status is a claim\n *\n * `status` is drawn only when the host passes it, in words as well as an icon,\n * and only a non-zero exit is toned as a failure: this component does not decide\n * that a command \"passed\". Without a status the header says nothing about whether\n * the command is still running. `onClear` adds a clear button; without it the\n * output is the host's record and nothing here offers to erase it.\n */\nexport type TerminalProps = Omit<ComponentProps<'div'>, 'children'> & {\n /** Everything the command has printed so far, exactly as received. */\n output: string\n /** The command line. Shown as text; the prompt glyph is decoration. */\n command?: string\n status?: TerminalStatus\n /** Finished lines mounted at once; earlier ones are counted and revealed a page at a time. */\n maxLines?: number\n /** Finished lines kept at all; older ones are discarded and counted. Default 200 000. */\n retainLines?: number\n /** Height of the output box, which scrolls past it. A number is pixels. Default `20rem`. */\n maxHeight?: number | string\n /** Soft-wrap long lines instead of scrolling sideways. Off: terminal columns keep their alignment. */\n wrap?: boolean\n /** `sm` is the compact chrome for output nested inside a Trace line. */\n size?: 'default' | 'sm'\n /** Show a clear button. The host empties `output`; the terminal erases nothing itself. */\n onClear?: () => void\n copyLabel?: string\n copiedLabel?: string\n clearLabel?: string\n /** Called after each copy attempt with whether the clipboard accepted it. */\n onCopy?: (ok: boolean) => void\n}\n\n/** Finished lines mounted by default. */\nexport const TERMINAL_MAX_LINES = 1000\n\n// One literal class per colour, written out in full so the stylesheet generator\n// can see each of them; a class assembled from an index would never be emitted.\nconst FG_CLASS = [\n 'text-(color:--terminal-ansi-black)',\n 'text-(color:--terminal-ansi-red)',\n 'text-(color:--terminal-ansi-green)',\n 'text-(color:--terminal-ansi-yellow)',\n 'text-(color:--terminal-ansi-blue)',\n 'text-(color:--terminal-ansi-magenta)',\n 'text-(color:--terminal-ansi-cyan)',\n 'text-(color:--terminal-ansi-white)',\n 'text-(color:--terminal-ansi-bright-black)',\n 'text-(color:--terminal-ansi-bright-red)',\n 'text-(color:--terminal-ansi-bright-green)',\n 'text-(color:--terminal-ansi-bright-yellow)',\n 'text-(color:--terminal-ansi-bright-blue)',\n 'text-(color:--terminal-ansi-bright-magenta)',\n 'text-(color:--terminal-ansi-bright-cyan)',\n 'text-(color:--terminal-ansi-bright-white)',\n] as const\nconst BG_CLASS = [\n 'bg-(--terminal-ansi-black)',\n 'bg-(--terminal-ansi-red)',\n 'bg-(--terminal-ansi-green)',\n 'bg-(--terminal-ansi-yellow)',\n 'bg-(--terminal-ansi-blue)',\n 'bg-(--terminal-ansi-magenta)',\n 'bg-(--terminal-ansi-cyan)',\n 'bg-(--terminal-ansi-white)',\n 'bg-(--terminal-ansi-bright-black)',\n 'bg-(--terminal-ansi-bright-red)',\n 'bg-(--terminal-ansi-bright-green)',\n 'bg-(--terminal-ansi-bright-yellow)',\n 'bg-(--terminal-ansi-bright-blue)',\n 'bg-(--terminal-ansi-bright-magenta)',\n 'bg-(--terminal-ansi-bright-cyan)',\n 'bg-(--terminal-ansi-bright-white)',\n] as const\n\nfunction segmentClass(style: AnsiStyle): string {\n const { fg, bg } = resolveColors(style)\n return cn(\n {\n 'font-bold': style.bold,\n 'opacity-70': style.dim,\n italic: style.italic,\n underline: style.underline && !style.strike,\n 'line-through': style.strike && !style.underline,\n '[text-decoration-line:underline_line-through]': style.underline && style.strike,\n 'text-(color:--terminal-background)': fg === 'default-bg',\n 'bg-(--terminal-foreground)': bg === 'default-fg',\n },\n typeof fg === 'number' && FG_CLASS[fg],\n typeof bg === 'number' && BG_CLASS[bg]\n )\n}\n\nfunction LineView(props: { line: AnsiLine; wrap: boolean }) {\n return (\n // `min-h-lh` keeps an empty line one line tall; a block with no text would\n // collapse and the transcript would lose its blank lines.\n <div\n class={cn('min-h-lh', {\n 'whitespace-pre-wrap [overflow-wrap:anywhere]': props.wrap,\n 'w-max min-w-full': !props.wrap,\n })}\n >\n <For each={props.line.segments}>\n {(segment) =>\n isPlainStyle(segment.style) ? (\n segment.text\n ) : (\n <span class={segmentClass(segment.style)}>{segment.text}</span>\n )\n }\n </For>\n <Show when={props.line.truncated > 0}>\n <span class=\"opacity-70 select-none\">\n {' '}\n … {props.line.truncated.toLocaleString()} more characters not shown\n </span>\n </Show>\n </div>\n )\n}\n\nfunction sameAnsiLine(left: AnsiLine, right: AnsiLine): boolean {\n return (\n left.truncated === right.truncated &&\n left.segments.length === right.segments.length &&\n left.segments.every(\n (segment, index) =>\n segment.text === right.segments[index]?.text &&\n segment.style === right.segments[index]?.style\n )\n )\n}\n\nfunction StatusReadout(props: { status: TerminalStatus }) {\n return (\n // A live region, so a command that finishes while the reader is elsewhere is\n // announced once, in words.\n <span\n role=\"status\"\n data-slot=\"terminal-status\"\n data-state={props.status.state}\n class={cn('flex shrink-0 items-center gap-1 text-xs', {\n 'text-destructive': isFailedExit(props.status),\n 'text-info': props.status.state === 'running',\n 'text-muted-foreground': props.status.state !== 'running' && !isFailedExit(props.status),\n })}\n >\n {/* A zero exit gets no glyph: a tick would be this component deciding the\n command succeeded, and some tools exit non-zero on purpose or zero on\n failure. The words carry the fact; only a non-zero code is toned. */}\n <Show when={props.status.state !== 'exited' || isFailedExit(props.status)}>\n <span aria-hidden=\"true\" class=\"grid size-3.5 place-items-center [&_svg]:size-3.5\">\n <Show\n when={props.status.state === 'running'}\n fallback={\n <Show when={props.status.state === 'cancelled'} fallback={<CircleAlert />}>\n <CircleSlash />\n </Show>\n }\n >\n <LoaderCircle class=\"motion-safe:animate-spin\" />\n </Show>\n </span>\n </Show>\n {terminalStatusLabel(props.status)}\n </span>\n )\n}\n\nexport function Terminal(props: TerminalProps) {\n const [local, rest] = splitProps(props, [\n 'output',\n 'command',\n 'status',\n 'maxLines',\n 'retainLines',\n 'maxHeight',\n 'wrap',\n 'size',\n 'onClear',\n 'copyLabel',\n 'copiedLabel',\n 'clearLabel',\n 'onCopy',\n 'class',\n ])\n\n const small = () => local.size === 'sm'\n const pageSize = () => Math.max(1, Math.floor(local.maxLines ?? TERMINAL_MAX_LINES))\n const maxHeight = () =>\n typeof local.maxHeight === 'number' ? `${local.maxHeight}px` : (local.maxHeight ?? '20rem')\n\n // The parser outlives renders: it holds the half-read escape sequence, the\n // current style and the open line. A new `output` that extends the old one is\n // fed only its tail; anything else (a clear, a different command) starts over.\n const newParser = () => createAnsiParser({ retainLines: local.retainLines })\n let parser = newParser()\n let consumed = ''\n // Bumped when the output restarts, so a parked position from the old output\n // is never applied to the new one.\n let epoch = 0\n const revision = createMemo(\n () => {\n const next = local.output\n if (next.length >= consumed.length && next.startsWith(consumed)) {\n parser.write(next.slice(consumed.length))\n } else {\n parser = newParser()\n parser.write(next)\n epoch += 1\n }\n consumed = next\n return epoch\n },\n undefined,\n { equals: false }\n )\n\n const [limit, setLimit] = createSignal(pageSize())\n createEffect(on(pageSize, (size) => setLimit(size), { defer: true }))\n // A cleared terminal is a fresh one: the next command starts at the page size.\n createEffect(\n on(\n () => local.output === '',\n (empty) => {\n if (empty) setLimit(pageSize())\n },\n { defer: true }\n )\n )\n\n const outputRows = createMemo(\n () => {\n revision()\n const rows = parser.lines.slice()\n const open = parser.openLine()\n if (open) rows.push(open)\n return rows\n },\n [],\n { equals: false }\n )\n // Where the reader parked, as a count of lines since the output began. An open\n // line is a row too: freeze its snapshot so streamed characters and CR redraws\n // do not rewrite the text under a parked reader.\n const [parked, setParked] = createSignal<{ epoch: number; end: number; open?: AnsiLine }>()\n const total = () => parser.droppedLines + outputRows().length\n const anchorEnd = () => {\n const current = revision()\n const position = parked()\n return position && position.epoch === current ? position.end : undefined\n }\n const lineWindow = createMemo(() => {\n revision()\n return terminalWindow(outputRows().length, parser.droppedLines, limit(), anchorEnd())\n })\n // Finished rows keep their parser identity. If an open row existed when the\n // reader parked, substitute its immutable snapshot until they jump to latest.\n const visibleRows = createMemo(\n () => {\n revision()\n const start = lineWindow().start\n const end = lineWindow().end\n const rows = outputRows().slice(start, end)\n const position = parked()\n if (position?.epoch === revision() && position.open) {\n const retainedIndex = position.end - 1 - parser.droppedLines\n if (retainedIndex >= start && retainedIndex < end) {\n rows[retainedIndex - start] = position.open\n }\n }\n return rows\n },\n [],\n { equals: false }\n )\n const changedParkedLine = () => {\n const position = parked()\n if (position?.epoch !== revision() || !position.open) return false\n const retainedIndex = position.end - 1 - parser.droppedLines\n const current = outputRows()[retainedIndex]\n return current !== undefined && !sameAnsiLine(position.open, current)\n }\n const newerRows = () => lineWindow().later + (changedParkedLine() ? 1 : 0)\n\n let scroller: HTMLDivElement | undefined\n const following = () => anchorEnd() === undefined\n\n const onScroll = () => {\n if (!scroller) return\n const atEnd = isAtBottom(scroller.scrollHeight, scroller.scrollTop, scroller.clientHeight)\n const position = anchorEnd()\n if (!atEnd) {\n if (position === undefined) {\n const currentEpoch = revision()\n setParked({ epoch: currentEpoch, end: total(), open: parser.openLine() })\n }\n } else if (position !== undefined && position >= total() && !changedParkedLine()) {\n // Back at the end of a view with nothing newer: nothing was missed.\n setParked(undefined)\n }\n }\n createEffect(\n on(revision, () => {\n if (scroller && following()) scroller.scrollTop = scroller.scrollHeight\n })\n )\n const jumpToLatest = () => {\n if (!scroller) return\n setParked(undefined)\n scroller.scrollTop = scroller.scrollHeight\n // The button is about to disappear; leave focus somewhere real.\n scroller.focus()\n }\n\n const [copied, setCopied] = createSignal(false)\n const [copyFailed, setCopyFailed] = createSignal(false)\n const copy = async () => {\n let ok = true\n try {\n await writeClipboardText(ansiPlainText(local.output))\n } catch {\n ok = false\n }\n setCopied(ok)\n setCopyFailed(!ok)\n local.onCopy?.(ok)\n if (ok) setTimeout(() => setCopied(false), 1500)\n }\n\n const empty = () => local.output === ''\n const regionLabel = () =>\n local.command ? `Output of ${local.command.slice(0, 120)}` : 'Terminal output'\n\n return (\n <div\n data-slot=\"terminal\"\n data-size={local.size ?? 'default'}\n aria-busy={local.status?.state === 'running' || undefined}\n class={cn(\n 'group/terminal overflow-hidden border border-border bg-card',\n small() ? 'rounded-lg' : 'rounded-xl',\n local.class\n )}\n {...rest}\n >\n <div class={cn('flex items-center gap-2', small() ? 'px-2 py-0.5' : 'px-3 py-1')}>\n <Show\n when={local.command !== undefined}\n fallback={<span class=\"flex-1 text-xs text-muted-foreground\">Terminal</span>}\n >\n <span class=\"flex min-w-0 flex-1 items-baseline gap-2\">\n <span\n aria-hidden=\"true\"\n class=\"shrink-0 font-code text-code text-muted-foreground select-none\"\n >\n $\n </span>\n <code\n title={local.command}\n class=\"line-clamp-2 min-w-0 font-code text-code text-foreground [overflow-wrap:anywhere]\"\n >\n {local.command}\n </code>\n </span>\n </Show>\n <Show when={local.status}>{(status) => <StatusReadout status={status()} />}</Show>\n {/* Hidden until the terminal is hovered or holds focus, never removed:\n a control that only exists under the pointer is unreachable by\n keyboard, and a touch screen has no hover, so it always shows there. */}\n <div class=\"flex items-center gap-1 opacity-0 transition-opacity group-focus-within/terminal:opacity-100 group-hover/terminal:opacity-100 [@media(hover:none)]:opacity-100\">\n <Show when={local.onClear !== undefined && !empty()}>\n <Button\n variant=\"ghost\"\n size=\"icon-2xs\"\n aria-label={local.clearLabel ?? 'Clear output'}\n onClick={() => local.onClear?.()}\n >\n <Eraser aria-hidden=\"true\" />\n </Button>\n </Show>\n <Show when={!empty()}>\n <Button\n variant=\"ghost\"\n size=\"icon-2xs\"\n aria-label={\n copied() ? (local.copiedLabel ?? 'Copied') : (local.copyLabel ?? 'Copy output')\n }\n title={copyFailed() ? 'Copying is unavailable in this context' : undefined}\n onClick={() => void copy()}\n >\n <Show when={copied()} fallback={<Copy aria-hidden=\"true\" />}>\n <Check aria-hidden=\"true\" />\n </Show>\n </Button>\n </Show>\n </div>\n </div>\n\n <Show when={lineWindow().hidden > 0 || lineWindow().evicted > 0}>\n <div\n data-slot=\"terminal-hidden-note\"\n class=\"flex items-center gap-2 border-t border-border px-3 py-1 text-xs text-muted-foreground\"\n >\n <span>\n <Show when={lineWindow().hidden > 0}>\n {lineWindow().hidden.toLocaleString()} earlier{' '}\n {lineWindow().hidden === 1 ? 'line' : 'lines'} hidden\n <Show when={parser.droppedLines > 0}>\n {' '}\n ({parser.droppedLines.toLocaleString()} only in the copy)\n </Show>\n .\n </Show>\n <Show when={lineWindow().evicted > 0}>\n {' '}\n {lineWindow().lost\n ? `The lines you were reading were discarded to keep memory bounded; showing the oldest ${lineWindow().end.toLocaleString()} still kept.`\n : `${lineWindow().evicted.toLocaleString()} of the lines you were reading were discarded to keep memory bounded.`}\n </Show>\n </span>\n <Show when={lineWindow().revealable > 0}>\n <Button\n variant=\"ghost\"\n size=\"2xs\"\n onClick={() => setLimit(revealEarlier(limit(), pageSize(), outputRows().length))}\n >\n Show {Math.min(pageSize(), lineWindow().revealable).toLocaleString()} earlier\n </Button>\n </Show>\n </div>\n </Show>\n\n <div class=\"relative\">\n <div\n ref={(element) => (scroller = element)}\n data-slot=\"terminal-body\"\n // A region that scrolls must be focusable, and a tab stop needs a name.\n role=\"region\"\n tabindex=\"0\"\n aria-label={regionLabel()}\n onScroll={onScroll}\n style={{ 'max-height': maxHeight() }}\n class=\"scroll-fade overflow-auto border-t border-border bg-(--terminal-background) text-(color:--terminal-foreground)\"\n >\n <Show\n when={!empty()}\n fallback={\n <p class={cn('m-0 opacity-70', small() ? 'px-2 py-1.5' : 'px-3 py-2')}>\n <span class=\"font-code text-code\">\n {local.status?.state === 'running' ? 'Waiting for output…' : 'No output'}\n </span>\n </p>\n }\n >\n <pre\n class={cn(\n 'm-0 font-code text-code leading-normal',\n small() ? 'px-2 py-1.5' : 'px-3 py-2'\n )}\n >\n <For each={visibleRows()}>\n {(line) => <LineView line={line} wrap={local.wrap === true} />}\n </For>\n </pre>\n </Show>\n </div>\n <Show when={newerRows() > 0}>\n <Button\n variant=\"secondary\"\n size=\"2xs\"\n class=\"absolute end-3 bottom-2 shadow-sm\"\n onClick={jumpToLatest}\n >\n <ArrowDown aria-hidden=\"true\" />\n Jump to latest\n <span class=\"text-muted-foreground tabular-nums\">\n ({newerRows().toLocaleString()} newer {newerRows() === 1 ? 'line' : 'lines'})\n </span>\n </Button>\n </Show>\n </div>\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA2HA,IAAa8C,qBAAqB;AAIlC,IAAMC,WAAW;CACf;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAA2C;AAE7C,IAAME,WAAW;CACf;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAAmC;AAGrC,SAASC,aAAaC,OAA0B;CAC9C,MAAM,EAAEC,IAAIC,OAAOjC,cAAc+B,KAAK;CACtC,OAAOnC,GACL;EACE,aAAamC,MAAMG;EACnB,cAAcH,MAAMI;EACpBC,QAAQL,MAAMK;EACdC,WAAWN,MAAMM,aAAa,CAACN,MAAMO;EACrC,gBAAgBP,MAAMO,UAAU,CAACP,MAAMM;EACvC,iDAAiDN,MAAMM,aAAaN,MAAMO;EAC1E,sCAAsCN,OAAO;EAC7C,8BAA8BC,OAAO;CACvC,GACA,OAAOD,OAAO,YAAYL,SAASK,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AAO;KACPhJ,MAAI;KAAA,SAAA;KAEJkJ,SAAS5B;KAAY,IAAAzF,WAAA;MAAA,OAAA;OAAAH,gBAEpBjE,WAAS,EAAA,eAAA,OAAA,CAAA;OAAA;cAAA;QAAA,IAAA2M,SAAAC,QAAA,GAAAE,SAAAH,OAAA3H,WAAAE,aAAA8H,SAAAF,OAAA5H,YAAAA;QAAA8H,OAAA9H;QAAAlB,OAAA2I,cAGNzD,UAAU,CAAC,CAAC9D,eAAe,GAAC0H,MAAA;QAAA9I,OAAA2I,cAASzD,UAAU,MAAM,IAAI,SAAS,SAAO8D,MAAA;QAAA,OAAAL;OAAA,EAAA,CAAA;MAAA;KAAA;IAAA,CAAA;GAAA;EAAA,CAAA,GAAA,IAAA;EAAAlI,QAAAyB,QAAA;GAAA,IAAAgH,OAnIvElM,GAAG,2BAA2B4F,MAAM,IAAI,gBAAgB,WAAW,GAACuG,OA8FhE9C,YAAY,GAAC+C,OAEF/K,UAAU;GAAC6K,SAAAhH,IAAAG,KAAA3B,UAAA8F,OAAAtE,IAAAG,IAAA6G,IAAA;GAAAC,SAAAjH,IAAAK,KAAAD,aAAAqE,QAAA,cAAAzE,IAAAK,IAAA4G,IAAA;GAAAC,SAAAlH,IAAAmH,KAAAC,iBAAA3C,QAAA,cAAAzE,IAAAmH,IAAAD,IAAA;GAAA,OAAAlH;EAAA,GAAA;GAAAG,GAAAG,KAAAA;GAAAD,GAAAC,KAAAA;GAAA6G,GAAA7G,KAAAA;EAAA,CAAA;EAAA,OAAA8D;CAAA,EAAA,CAAA;AA0C5C"}
@@ -4,7 +4,7 @@
4
4
  "title": "Appearance Editor",
5
5
  "description": "",
6
6
  "dependencies": [
7
- "@adea-ai/themes@^0.11.4",
7
+ "@adea-ai/themes@^0.11.5",
8
8
  "@kobalte/core@^0.13.14",
9
9
  "lucide-solid@^1.65.0"
10
10
  ],
package/dist/r/lib.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "title": "Class-name and token helpers",
5
5
  "description": "The private helpers the components import: the class-name merge, the variant recipes, the token manifest and the theme bridge. Installed automatically as a peer of any component that needs it.",
6
6
  "dependencies": [
7
- "@adea-ai/themes@^0.11.4",
7
+ "@adea-ai/themes@^0.11.5",
8
8
  "class-variance-authority@^0.7.1",
9
9
  "cn@^0.5.1"
10
10
  ],
@@ -2298,7 +2298,7 @@
2298
2298
  "title": "Appearance Editor",
2299
2299
  "description": "",
2300
2300
  "dependencies": [
2301
- "@adea-ai/themes@^0.11.4",
2301
+ "@adea-ai/themes@^0.11.5",
2302
2302
  "@kobalte/core@^0.13.14",
2303
2303
  "lucide-solid@^1.65.0"
2304
2304
  ],
@@ -3458,7 +3458,7 @@
3458
3458
  "title": "Theming",
3459
3459
  "description": "",
3460
3460
  "dependencies": [
3461
- "@adea-ai/themes@^0.11.4",
3461
+ "@adea-ai/themes@^0.11.5",
3462
3462
  "@kobalte/core@^0.13.14",
3463
3463
  "lucide-solid@^1.65.0"
3464
3464
  ],
@@ -3643,7 +3643,7 @@
3643
3643
  "title": "Class-name and token helpers",
3644
3644
  "description": "The private helpers the components import: the class-name merge, the variant recipes, the token manifest and the theme bridge. Installed automatically as a peer of any component that needs it.",
3645
3645
  "dependencies": [
3646
- "@adea-ai/themes@^0.11.4",
3646
+ "@adea-ai/themes@^0.11.5",
3647
3647
  "class-variance-authority@^0.7.1",
3648
3648
  "cn@^0.5.1"
3649
3649
  ],
@@ -668,6 +668,21 @@ export function parseAnsi(text: string, options?: AnsiParserOptions): AnsiLine[]
668
668
  return open ? [...parser.lines, open] : [...parser.lines]
669
669
  }
670
670
 
671
+ /**
672
+ * The whole output as a reader sees it, for the clipboard: every line, none
673
+ * shortened, with escape sequences and overwritten text resolved away.
674
+ */
675
+ export function ansiPlainText(text: string): string {
676
+ const parser = createAnsiParser({
677
+ maxLineLength: Number.POSITIVE_INFINITY,
678
+ retainLines: Number.POSITIVE_INFINITY,
679
+ })
680
+ parser.write(text)
681
+ const open = parser.openLine()
682
+ // Finished lines carry their newline even when only control sequences follow.
683
+ return [...parser.lines.map(ansiLineText), open ? ansiLineText(open) : ''].join('\n')
684
+ }
685
+
671
686
  /** A line's text with styling removed, for tests and for accessible names. */
672
687
  export function ansiLineText(line: AnsiLine): string {
673
688
  return line.segments.map((segment) => segment.text).join('')
@@ -26,6 +26,7 @@ import {
26
26
  resolveColors,
27
27
  type AnsiLine,
28
28
  type AnsiStyle,
29
+ ansiPlainText,
29
30
  } from './ansi'
30
31
  import {
31
32
  isAtBottom,
@@ -407,7 +408,7 @@ export function Terminal(props: TerminalProps) {
407
408
  const copy = async () => {
408
409
  let ok = true
409
410
  try {
410
- await writeClipboardText(local.output)
411
+ await writeClipboardText(ansiPlainText(local.output))
411
412
  } catch {
412
413
  ok = false
413
414
  }
@@ -4,7 +4,7 @@
4
4
  "title": "Theming",
5
5
  "description": "",
6
6
  "dependencies": [
7
- "@adea-ai/themes@^0.11.4",
7
+ "@adea-ai/themes@^0.11.5",
8
8
  "@kobalte/core@^0.13.14",
9
9
  "lucide-solid@^1.65.0"
10
10
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adea-ai/ui",
3
- "version": "0.149.4",
3
+ "version": "0.149.6",
4
4
  "description": "The Adea design system: Kobalte-backed Solid components, semantic OKLCH tokens, and the app-shell layout primitives shared by Adea and Cortana.",
5
5
  "keywords": [
6
6
  "adea",
@@ -120,7 +120,7 @@
120
120
  "build": "bun run cn:build && vite build && tsc -p tsconfig.json --emitDeclarationOnly",
121
121
  "dev": "bun run cn:build && vite build --watch",
122
122
  "lint": "oxlint",
123
- "test": "bun run cn:check && bun test --conditions=browser --preload ./src/testing/solid-transform.ts tests",
123
+ "test": "bun run cn:check && bun test --conditions=browser --preload ./src/testing/solid-transform.ts tests src",
124
124
  "typecheck": "bun check -p tsconfig.check.json",
125
125
  "cn:build": "bun scripts/build-cn-tables.ts",
126
126
  "cn:check": "bun scripts/check-cn-tables.ts",
@@ -150,7 +150,7 @@
150
150
  "check:packed-paste-model": "node scripts/check-packed-paste-model.mjs"
151
151
  },
152
152
  "dependencies": {
153
- "@adea-ai/themes": "^0.11.4",
153
+ "@adea-ai/themes": "^0.11.5",
154
154
  "@corvu/calendar": "^0.1.2",
155
155
  "@corvu/drawer": "^0.2.4",
156
156
  "@corvu/otp-field": "^0.1.4",
package/registry.json CHANGED
@@ -2298,7 +2298,7 @@
2298
2298
  "title": "Appearance Editor",
2299
2299
  "description": "",
2300
2300
  "dependencies": [
2301
- "@adea-ai/themes@^0.11.4",
2301
+ "@adea-ai/themes@^0.11.5",
2302
2302
  "@kobalte/core@^0.13.14",
2303
2303
  "lucide-solid@^1.65.0"
2304
2304
  ],
@@ -3458,7 +3458,7 @@
3458
3458
  "title": "Theming",
3459
3459
  "description": "",
3460
3460
  "dependencies": [
3461
- "@adea-ai/themes@^0.11.4",
3461
+ "@adea-ai/themes@^0.11.5",
3462
3462
  "@kobalte/core@^0.13.14",
3463
3463
  "lucide-solid@^1.65.0"
3464
3464
  ],
@@ -3643,7 +3643,7 @@
3643
3643
  "title": "Class-name and token helpers",
3644
3644
  "description": "The private helpers the components import: the class-name merge, the variant recipes, the token manifest and the theme bridge. Installed automatically as a peer of any component that needs it.",
3645
3645
  "dependencies": [
3646
- "@adea-ai/themes@^0.11.4",
3646
+ "@adea-ai/themes@^0.11.5",
3647
3647
  "class-variance-authority@^0.7.1",
3648
3648
  "cn@^0.5.1"
3649
3649
  ],
@@ -668,6 +668,21 @@ export function parseAnsi(text: string, options?: AnsiParserOptions): AnsiLine[]
668
668
  return open ? [...parser.lines, open] : [...parser.lines]
669
669
  }
670
670
 
671
+ /**
672
+ * The whole output as a reader sees it, for the clipboard: every line, none
673
+ * shortened, with escape sequences and overwritten text resolved away.
674
+ */
675
+ export function ansiPlainText(text: string): string {
676
+ const parser = createAnsiParser({
677
+ maxLineLength: Number.POSITIVE_INFINITY,
678
+ retainLines: Number.POSITIVE_INFINITY,
679
+ })
680
+ parser.write(text)
681
+ const open = parser.openLine()
682
+ // Finished lines carry their newline even when only control sequences follow.
683
+ return [...parser.lines.map(ansiLineText), open ? ansiLineText(open) : ''].join('\n')
684
+ }
685
+
671
686
  /** A line's text with styling removed, for tests and for accessible names. */
672
687
  export function ansiLineText(line: AnsiLine): string {
673
688
  return line.segments.map((segment) => segment.text).join('')
@@ -26,6 +26,7 @@ import {
26
26
  resolveColors,
27
27
  type AnsiLine,
28
28
  type AnsiStyle,
29
+ ansiPlainText,
29
30
  } from './ansi'
30
31
  import {
31
32
  isAtBottom,
@@ -407,7 +408,7 @@ export function Terminal(props: TerminalProps) {
407
408
  const copy = async () => {
408
409
  let ok = true
409
410
  try {
410
- await writeClipboardText(local.output)
411
+ await writeClipboardText(ansiPlainText(local.output))
411
412
  } catch {
412
413
  ok = false
413
414
  }