Something went wrong. Try again.
A reference for terminal control sequences whose examples run live in libghostty-vt compiled to WebAssembly.
Something went wrong. Try again.
1.7 kB · 46 lines
JavaScript
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
// Finding the validation cases in the site's SuperMD sources. Shared by// tools/check-cases.mjs, which runs them in libghostty-vt, and// emulators/harness.mjs, which runs them in a real terminal.
import { readdirSync, statSync } from "node:fs";import { join } from "node:path";
export function* walk(dir) { for (const name of readdirSync(dir).sort()) { const path = join(dir, name); if (statSync(path).isDirectory()) yield* walk(path); else if (name.endsWith(".smd")) yield path; }}
// A case in SuperMD source: a quote block opened by a `vt-case` block// directive and holding two fenced code blocks, after a heading.export function* extractCases(source) { const lines = source.split("\n"); let heading = "Case"; for (let i = 0; i < lines.length; i++) { const h = /^#+\s+(.*)$/.exec(lines[i]); if (h) heading = h[1]; const d = /^>\s*\[\]\(\$block\.attrs\(([^)]*)\)/.exec(lines[i]); if (!d) continue; const attrs = Array.from(d[1].matchAll(/"([^"]*)"/g), (m) => m[1]); if (!attrs.includes("vt-case")) continue; const body = []; for (i++; i < lines.length && lines[i].startsWith(">"); i++) body.push(lines[i].replace(/^> ?/, "")); const fences = []; let current = null; for (const line of body) { if (/^```/.test(line)) { if (current === null) current = []; else { fences.push(current.join("\n")); current = null; } } else if (current !== null) current.push(line); } yield { heading, attrs, line: i, fences }; }}