xonecas.io
70160
Ce

cel-tui / commit f4339cc

feat: refresh deps and improve syntax highlight streaming demo

xonecas2026-04-12 f4339cc81c27d3436e07f5d041f6059fb808e314 parent 34b6b7e

4 files changed

bun.lock+4−4
@@ -10,7 +10,7 @@
1010 "lefthook": "^2.1.5",
1111 "mitata": "^1.0.34",
1212 "prettier": "^3.8.2",
13- "typedoc": "^0.28.18",
13+ "typedoc": "^0.28.19",
1414 "typedoc-plugin-markdown": "^4.11.0",
1515 "typescript": "^6.0.2",
1616 },
@@ -21,7 +21,7 @@
2121 "dependencies": {
2222 "@cel-tui/core": "workspace:*",
2323 "@cel-tui/types": "workspace:*",
24- "lextide": "^0.2.0",
24+ "lextide": "^0.2.1",
2525 "yoctomarkdown": "^0.1.0",
2626 },
2727 "peerDependencies": {
@@ -128,7 +128,7 @@
128128
129129 "lefthook-windows-x64": ["lefthook-windows-x64@2.1.5", "", { "os": "win32", "cpu": "x64" }, "sha512-yiAh8qxml6uqy10jDxOdN9fOQpyLxBFY1fgCEAhn7sVJYmJKRhjqSBwZX6LG5MQjzr29KStrIdw7TR3lf3rT7Q=="],
130130
131- "lextide": ["lextide@0.2.0", "", {}, "sha512-EGORriYc1h2xHVcIpLdfETIVOp4impZ+X2nnm5EJOt3L55Jf/U9zFLxONfl3kWiB5WhyzUJLHL1m/7Rv17lb0g=="],
131+ "lextide": ["lextide@0.2.1", "", {}, "sha512-fP7liS0LoNJz2EF6G7+K21yvB58bJEjaTrsDcPi4Qv7xZynB9NzjY44N6tFK6SJaECHIUqF2kcWbWQ84hPfmlg=="],
132132
133133 "linkify-it": ["linkify-it@5.0.0", "", { "dependencies": { "uc.micro": "^2.0.0" } }, "sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ=="],
134134
@@ -150,7 +150,7 @@
150150
151151 "strip-ansi": ["strip-ansi@7.2.0", "", { "dependencies": { "ansi-regex": "^6.2.2" } }, "sha512-yDPMNjp4WyfYBkHnjIRLfca1i6KMyGCtsVgoKe/z1+6vukgaENdgGBZt+ZmKPc4gavvEZ5OgHfHdrazhgNyG7w=="],
152152
153- "typedoc": ["typedoc@0.28.18", "", { "dependencies": { "@gerrit0/mini-shiki": "^3.23.0", "lunr": "^2.3.9", "markdown-it": "^14.1.1", "minimatch": "^10.2.4", "yaml": "^2.8.2" }, "peerDependencies": { "typescript": "5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x || 5.7.x || 5.8.x || 5.9.x || 6.0.x" }, "bin": { "typedoc": "bin/typedoc" } }, "sha512-NTWTUOFRQ9+SGKKTuWKUioUkjxNwtS3JDRPVKZAXGHZy2wCA8bdv2iJiyeePn0xkmK+TCCqZFT0X7+2+FLjngA=="],
153+ "typedoc": ["typedoc@0.28.19", "", { "dependencies": { "@gerrit0/mini-shiki": "^3.23.0", "lunr": "^2.3.9", "markdown-it": "^14.1.1", "minimatch": "^10.2.5", "yaml": "^2.8.3" }, "peerDependencies": { "typescript": "5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x || 5.7.x || 5.8.x || 5.9.x || 6.0.x" }, "bin": { "typedoc": "bin/typedoc" } }, "sha512-wKh+lhdmMFivMlc6vRRcMGXeGEHGU2g8a2CkPTJjJlwRf1iXbimWIPcFolCqe4E0d/FRtGszpIrsp3WLpDB8Pw=="],
154154
155155 "typedoc-plugin-markdown": ["typedoc-plugin-markdown@4.11.0", "", { "peerDependencies": { "typedoc": "0.28.x" } }, "sha512-2iunh2ALyfyh204OF7h2u0kuQ84xB3jFZtFyUr01nThJkLvR8oGGSSDlyt2gyO4kXhvUxDcVbO0y43+qX+wFbw=="],
156156
examples/syntax-highlight.ts+529−145
@@ -1,13 +1,14 @@
11 /**
2- * cel-tui: SyntaxHighlight demo
2+ * cel-tui: SyntaxHighlight streaming demo
33 *
4- * Streams TypeScript and Bash code into SyntaxHighlight.
5- * Shows lextide-backed highlighting with append-only incremental updates.
4+ * Streams every built-in lextide language through SyntaxHighlight.
5+ * The large pane renders SyntaxHighlight, while the stream board mirrors
6+ * lextide's recall/stable/unstable updates for the same append-only chunks.
67 *
78 * Run: bun run examples/syntax-highlight.ts
89 */
910
10-import { cel, VStack, HStack, Text, ProcessTerminal } from "@cel-tui/core";
11+import { cel, HStack, ProcessTerminal, Text, VStack } from "@cel-tui/core";
1112 import {
1213 Divider,
1314 Spacer,
@@ -15,16 +16,21 @@ import {
1516 VDivider,
1617 type SyntaxHighlightTheme,
1718 } from "@cel-tui/components";
19+import {
20+ all,
21+ createLowlight,
22+ type HighlightStream,
23+ type StreamUpdate,
24+} from "lextide";
1825 import { warningBox } from "./warning-box";
1926
20-const LANGUAGE = "typescript";
21-const BASH_LANGUAGE = "bash";
22-const MIN_COLS = 52;
23-const MIN_ROWS = 16;
24-const STACKED_MIN_ROWS = 20;
25-const SIDE_BY_SIDE_MIN_COLS = 100;
26-const CHUNK_SIZE = 3;
27-const TICK_MS = 18;
27+const lowlight = createLowlight(all);
28+
29+const MIN_COLS = 72;
30+const MIN_ROWS = 22;
31+const STACKED_MIN_ROWS = 29;
32+const SIDE_BY_SIDE_MIN_COLS = 116;
33+const TICK_MS = 72;
2834
2935 const CUSTOM_THEME: SyntaxHighlightTheme = {
3036 name: "cel-demo-sunset",
@@ -89,61 +95,197 @@ const THEME_OPTIONS: ReadonlyArray<{
8995 },
9096 ];
9197
92-const FULL_CODE = [
93- "/**",
94- " * Streaming syntax highlight demo.",
95- " */",
96- "interface User {",
97- " id: number;",
98- " name: string;",
99- "}",
100- "",
101- "const users: User[] = [",
102- ' { id: 1, name: "Ada" },',
103- ' { id: 2, name: "Linus" },',
104- "];",
105- "",
106- "function greet(user: User): string {",
107- " return `Hello, ${user.name}!`;",
108- "}",
109- "",
110- "/* Multi-line comment to test streamed grammar state */",
111- "for (const user of users) {",
112- " console.log(greet(user));",
113- "}",
114- "Long ass line to see the wrapping behaviuour on the example.Long ass line to see the wrapping behaviuour on the example.Long ass line to see the wrapping behaviuour on the example.Long ass line to see the wrapping behaviuour on the example.Long ass line to see the wrapping behaviuour on the example.Long ass line to see the wrapping behaviuour on the example.",
115-].join("\n");
116-
117-const BASH_CODE = [
118- "#!/usr/bin/env bash",
119- "set -euo pipefail",
120- "",
121- "readonly script_path=${BASH_SOURCE[0]}",
122- "script_dir=${script_path%/*}",
123- "targets=(debug release)",
124- "count=0",
125- "",
126- "build() {",
127- " local target=${1:-debug}",
128- ' printf \'==> building %s from %s\\n\' "$target" "$script_dir"',
129- " ((count += 1))",
130- " bun run typecheck",
131- " bun test",
132- "}",
133- "",
134- 'for target in "${targets[@]}"; do',
135- ' case "$target" in',
136- ' release) build "$target" ;;',
137- " esac",
138- "done",
139-].join("\n");
140-
141-let content = "";
142-let bashContent = "";
98+interface DemoSample {
99+ language: string;
100+ title: string;
101+ aliases: readonly string[];
102+ description: string;
103+ chunkSize: number;
104+ source: string;
105+}
106+
107+const SAMPLE_BY_LANGUAGE = {
108+ bash: {
109+ title: "Bash",
110+ aliases: ["sh", "shell", "zsh"],
111+ description: "Variables, conditionals, and a heredoc.",
112+ chunkSize: 5,
113+ source: [
114+ "#!/usr/bin/env bash",
115+ "set -euo pipefail",
116+ "",
117+ "name=${1:-stream}",
118+ 'printf "start %s\\n" "$name"',
119+ "",
120+ 'if [[ "$name" == "stream" ]]; then',
121+ " cat <<'EOF'",
122+ "append-only shell chunks",
123+ "keep parser state warm",
124+ "EOF",
125+ "fi",
126+ ].join("\n"),
127+ },
128+ javascript: {
129+ title: "JavaScript",
130+ aliases: ["js", "jsx", "mjs", "cjs"],
131+ description: "Async code, destructuring, and template literals.",
132+ chunkSize: 5,
133+ source: [
134+ "async function loadUsers(signal) {",
135+ ' const response = await fetch("/api/users", { signal });',
136+ " if (!response.ok) {",
137+ " throw new Error(`HTTP ${response.status}`);",
138+ " }",
139+ " const users = await response.json();",
140+ " return users",
141+ " .map(({ id, name }) => `${id}:${name}`)",
142+ ' .join(", ");',
143+ "}",
144+ ].join("\n"),
145+ },
146+ markdown: {
147+ title: "Markdown",
148+ aliases: ["md", "mkdown", "mkd"],
149+ description: "Headings, lists, inline code, and a fenced block.",
150+ chunkSize: 6,
151+ source: [
152+ "# Streaming markdown",
153+ "",
154+ "`SyntaxHighlight` keeps append-only updates cheap.",
155+ "",
156+ "- headings",
157+ "- emphasis",
158+ "- `inline code`",
159+ "",
160+ "```ts",
161+ 'const status = "streaming";',
162+ "console.log(status);",
163+ "```",
164+ "",
165+ "> Fences and inline spans arrive a few bytes at a time.",
166+ ].join("\n"),
167+ },
168+ python: {
169+ title: "Python",
170+ aliases: ["py"],
171+ description:
172+ "Decorators, dataclasses, triple-quoted strings, and f-strings.",
173+ chunkSize: 5,
174+ source: [
175+ "from dataclasses import dataclass",
176+ "",
177+ "@dataclass(slots=True)",
178+ "class Job:",
179+ " name: str",
180+ " retries: int = 0",
181+ "",
182+ "def describe(job: Job) -> str:",
183+ ' note = """append-only streams',
184+ ' stay highlighted across chunks"""',
185+ ' return f"{job.name}:{job.retries} -> {note.strip()}"',
186+ ].join("\n"),
187+ },
188+ typescript: {
189+ title: "TypeScript",
190+ aliases: ["ts", "tsx", "mts", "cts"],
191+ description: "Types, generics, comments, and a template literal.",
192+ chunkSize: 4,
193+ source: [
194+ "/**",
195+ " * Streaming state stays append-only.",
196+ " */",
197+ 'type Phase = "idle" | "streaming" | "done";',
198+ "",
199+ "interface Chunk<T> {",
200+ " id: number;",
201+ " payload: T;",
202+ "}",
203+ "",
204+ "function renderChunk<T extends string | number>(chunk: Chunk<T>): string {",
205+ " return `${chunk.id}:${String(chunk.payload)}`;",
206+ "}",
207+ "",
208+ 'const preview: Chunk<string> = { id: 7, payload: "hello" };',
209+ "renderChunk(preview);",
210+ ].join("\n"),
211+ },
212+} satisfies Record<string, Omit<DemoSample, "language">>;
213+
214+function hasDemoSample(
215+ language: string,
216+): language is keyof typeof SAMPLE_BY_LANGUAGE {
217+ return Object.prototype.hasOwnProperty.call(SAMPLE_BY_LANGUAGE, language);
218+}
219+
220+const REGISTERED_LANGUAGES = lowlight.listLanguages().sort();
221+const MISSING_SAMPLES = REGISTERED_LANGUAGES.filter(
222+ (language) => !hasDemoSample(language),
223+);
224+
225+if (MISSING_SAMPLES.length > 0) {
226+ throw new Error(
227+ `Missing syntax-highlight demo samples for lextide languages: ${MISSING_SAMPLES.join(", ")}`,
228+ );
229+}
230+
231+const DEMO_SAMPLES: readonly DemoSample[] = REGISTERED_LANGUAGES.map(
232+ (language) => {
233+ if (!hasDemoSample(language)) {
234+ throw new Error(`Unsupported demo language: ${language}`);
235+ }
236+
237+ return {
238+ language,
239+ ...SAMPLE_BY_LANGUAGE[language],
240+ };
241+ },
242+);
243+
244+interface StreamDelta {
245+ recall: number;
246+ stable: number;
247+ unstable: number;
248+}
249+
250+interface DemoStreamState {
251+ sample: DemoSample;
252+ content: string;
253+ chunks: number;
254+ lastChunk: string;
255+ lastUpdate: StreamDelta;
256+ stream: HighlightStream;
257+}
258+
259+const EMPTY_DELTA: StreamDelta = {
260+ recall: 0,
261+ stable: 0,
262+ unstable: 0,
263+};
264+
265+let streams = createStreams();
143266 let paused = false;
144267 let themeIndex = 0;
268+let selectedIndex = Math.max(
269+ 0,
270+ DEMO_SAMPLES.findIndex((sample) => sample.language === "typescript"),
271+);
145272 let streamTimer: ReturnType<typeof setTimeout> | null = null;
146273
274+function createStreamState(sample: DemoSample): DemoStreamState {
275+ return {
276+ sample,
277+ content: "",
278+ chunks: 0,
279+ lastChunk: "",
280+ lastUpdate: EMPTY_DELTA,
281+ stream: lowlight.stream(sample.language, { allowRecalls: true }),
282+ };
283+}
284+
285+function createStreams(): DemoStreamState[] {
286+ return DEMO_SAMPLES.map(createStreamState);
287+}
288+
147289 function quit() {
148290 stopStreaming();
149291 cel.stop();
@@ -157,18 +299,37 @@ function stopStreaming() {
157299 }
158300 }
159301
302+function isStreamDone(state: DemoStreamState): boolean {
303+ return state.content.length >= state.sample.source.length;
304+}
305+
160306 function isDone(): boolean {
161- return (
162- content.length >= FULL_CODE.length && bashContent.length >= BASH_CODE.length
163- );
307+ return streams.every(isStreamDone);
164308 }
165309
166310 function startStreaming() {
167311 stopStreaming();
168- if (isDone() || paused) return;
312+ if (paused || isDone()) {
313+ return;
314+ }
169315 streamTimer = setTimeout(streamNext, TICK_MS);
170316 }
171317
318+function applyTelemetry(
319+ state: DemoStreamState,
320+ chunk: string,
321+ update: StreamUpdate,
322+): void {
323+ state.content += chunk;
324+ state.chunks += 1;
325+ state.lastChunk = chunk;
326+ state.lastUpdate = {
327+ recall: update.recall,
328+ stable: update.stable.length,
329+ unstable: update.unstable.length,
330+ };
331+}
332+
172333 function streamNext() {
173334 if (paused || isDone()) {
174335 streamTimer = null;
@@ -176,17 +337,24 @@ function streamNext() {
176337 return;
177338 }
178339
179- const nextContentLength = Math.min(
180- FULL_CODE.length,
181- content.length + CHUNK_SIZE,
182- );
183- const nextBashLength = Math.min(
184- BASH_CODE.length,
185- Math.round((nextContentLength / FULL_CODE.length) * BASH_CODE.length),
186- );
340+ for (const state of streams) {
341+ if (isStreamDone(state)) {
342+ continue;
343+ }
344+
345+ const nextLength = Math.min(
346+ state.sample.source.length,
347+ state.content.length + state.sample.chunkSize,
348+ );
349+ const chunk = state.sample.source.slice(state.content.length, nextLength);
350+ if (chunk.length === 0) {
351+ continue;
352+ }
353+
354+ const update = state.stream.write(chunk);
355+ applyTelemetry(state, chunk, update);
356+ }
187357
188- content = FULL_CODE.slice(0, nextContentLength);
189- bashContent = BASH_CODE.slice(0, nextBashLength);
190358 cel.render();
191359
192360 if (isDone()) {
@@ -198,18 +366,23 @@ function streamNext() {
198366 }
199367
200368 function restart() {
201- content = "";
202- bashContent = "";
369+ streams = createStreams();
203370 paused = false;
204371 startStreaming();
205372 cel.render();
206373 }
207374
208375 function togglePause() {
209- if (isDone()) return;
376+ if (isDone()) {
377+ return;
378+ }
379+
210380 paused = !paused;
211- if (!paused) startStreaming();
212- else stopStreaming();
381+ if (paused) {
382+ stopStreaming();
383+ } else {
384+ startStreaming();
385+ }
213386 cel.render();
214387 }
215388
@@ -218,26 +391,139 @@ function toggleTheme() {
218391 cel.render();
219392 }
220393
221-function codePane(
222- title: string,
223- status: string,
224- content: string,
225- language: string,
226- theme?: SyntaxHighlightTheme,
227-) {
394+function cycleSelection(delta: number) {
395+ selectedIndex =
396+ (selectedIndex + delta + streams.length) % Math.max(1, streams.length);
397+ cel.render();
398+}
399+
400+function currentTheme() {
401+ return THEME_OPTIONS[themeIndex]!;
402+}
403+
404+function globalStatus(): "done" | "paused" | "streaming" {
405+ if (isDone()) {
406+ return "done";
407+ }
408+ if (paused) {
409+ return "paused";
410+ }
411+ return "streaming";
412+}
413+
414+function streamStatus(state: DemoStreamState): "done" | "paused" | "streaming" {
415+ if (isStreamDone(state)) {
416+ return "done";
417+ }
418+ if (paused) {
419+ return "paused";
420+ }
421+ return "streaming";
422+}
423+
424+function statusColor(status: "done" | "paused" | "streaming") {
425+ if (status === "done") {
426+ return "color02";
427+ }
428+ if (status === "paused") {
429+ return "color03";
430+ }
431+ return "color06";
432+}
433+
434+function percentComplete(state: DemoStreamState): number {
435+ return Math.round((state.content.length / state.sample.source.length) * 100);
436+}
437+
438+function previewChunk(chunk: string, maxLength = 24): string {
439+ if (chunk.length === 0) {
440+ return "waiting";
441+ }
442+
443+ const escaped = chunk
444+ .replaceAll("\\", "\\\\")
445+ .replaceAll("\n", "\\n")
446+ .replaceAll("\t", "\\t")
447+ .replaceAll('"', '\\"');
448+
449+ if (escaped.length <= maxLength) {
450+ return escaped;
451+ }
452+
453+ return `${escaped.slice(0, maxLength - 3)}...`;
454+}
455+
456+function keycap(label: string) {
457+ return Text(` ${label} `, {
458+ fgColor: "color07",
459+ bgColor: "color08",
460+ bold: true,
461+ });
462+}
463+
464+function languageChip(state: DemoStreamState, index: number) {
465+ const selected = index === selectedIndex;
466+ const status = streamStatus(state);
467+ const bgColor = selected
468+ ? "color06"
469+ : status === "done"
470+ ? "color10"
471+ : "color08";
472+ const fgColor = selected || status === "done" ? "color00" : "color07";
473+
474+ return Text(` ${state.sample.language} `, {
475+ fgColor,
476+ bgColor,
477+ bold: true,
478+ });
479+}
480+
481+function detailPane(theme?: SyntaxHighlightTheme) {
482+ const selected = streams[selectedIndex]!;
483+ const status = streamStatus(selected);
484+
228485 return VStack({ flex: 1 }, [
229486 HStack(
230487 {
231488 height: 1,
232489 padding: { x: 1 },
490+ gap: 1,
233491 bgColor: "color08",
234492 },
235493 [
236- Text(title, { bold: true, fgColor: "color06" }),
494+ Text(`${selected.sample.title} (${selected.sample.language})`, {
495+ bold: true,
496+ fgColor: "color06",
497+ }),
237498 Spacer(),
238- Text(status, { fgColor: "color15" }),
499+ Text(`${selected.content.length}/${selected.sample.source.length}`, {
500+ fgColor: "color15",
501+ }),
502+ Text(status, {
503+ fgColor: statusColor(status),
504+ bold: true,
505+ }),
239506 ],
240507 ),
508+ VStack({ padding: { x: 1 } }, [
509+ Text(selected.sample.description, {
510+ fgColor: "color08",
511+ italic: true,
512+ }),
513+ Text(`aliases: ${selected.sample.aliases.join(", ")}`, {
514+ fgColor: "color08",
515+ }),
516+ Text(
517+ `append-only: ${selected.sample.chunkSize} chars/tick | last delta r${selected.lastUpdate.recall} s${selected.lastUpdate.stable} u${selected.lastUpdate.unstable}`,
518+ {
519+ fgColor: "color08",
520+ },
521+ ),
522+ Text(`last chunk: "${previewChunk(selected.lastChunk, 30)}"`, {
523+ fgColor: "color08",
524+ }),
525+ ]),
526+ Divider({ fgColor: "color08" }),
241527 VStack(
242528 {
243529 flex: 1,
@@ -245,7 +531,97 @@ function codePane(
245531 scrollbar: true,
246532 padding: { x: 1 },
247533 },
248- [SyntaxHighlight(content, language, { theme })],
534+ [SyntaxHighlight(selected.content, selected.sample.language, { theme })],
535+ ),
536+ ]);
537+}
538+
539+function streamRow(state: DemoStreamState, index: number) {
540+ const selected = index === selectedIndex;
541+ const status = streamStatus(state);
542+
543+ return VStack(
544+ {
545+ padding: { x: 1 },
546+ bgColor: selected ? "color08" : undefined,
547+ },
548+ [
549+ HStack({ gap: 1 }, [
550+ Text(selected ? ">" : " ", {
551+ fgColor: selected ? "color15" : "color08",
552+ bold: selected || undefined,
553+ }),
554+ Text(state.sample.title, {
555+ fgColor: selected ? "color15" : "color06",
556+ bold: true,
557+ }),
558+ Spacer(),
559+ Text(`${percentComplete(state)}%`, {
560+ fgColor: "color08",
561+ }),
562+ Text(status, {
563+ fgColor: statusColor(status),
564+ bold: true,
565+ }),
566+ ]),
567+ HStack({ gap: 1 }, [
568+ Text(`+"${previewChunk(state.lastChunk, 18)}"`, {
569+ fgColor: "color08",
570+ }),
571+ Spacer(),
572+ Text(`r${state.lastUpdate.recall}`, { fgColor: "color01" }),
573+ Text(`s${state.lastUpdate.stable}`, { fgColor: "color02" }),
574+ Text(`u${state.lastUpdate.unstable}`, { fgColor: "color03" }),
575+ Text(`c${state.chunks}`, { fgColor: "color06" }),
576+ ]),
577+ ],
578+ );
579+}
580+
581+function streamBoard() {
582+ const status = globalStatus();
583+
584+ return VStack({ flex: 1 }, [
585+ HStack(
586+ {
587+ height: 1,
588+ padding: { x: 1 },
589+ bgColor: "color08",
590+ },
591+ [
592+ Text("Live stream board", {
593+ bold: true,
594+ fgColor: "color06",
595+ }),
596+ Spacer(),
597+ Text(status, {
598+ fgColor: statusColor(status),
599+ bold: true,
600+ }),
601+ ],
602+ ),
603+ VStack({ padding: { x: 1 } }, [
604+ Text("Parallel lowlight.stream(..., { allowRecalls: true }).", {
605+ fgColor: "color08",
606+ italic: true,
607+ }),
608+ Text("Each row shows the last chunk plus r/s/u counts.", {
609+ fgColor: "color08",
610+ italic: true,
611+ }),
612+ ]),
613+ Divider({ fgColor: "color08" }),
614+ VStack(
615+ {
616+ flex: 1,
617+ overflow: "hidden",
618+ },
619+ streams.flatMap((state, index) => [
620+ streamRow(state, index),
621+ ...(index < streams.length - 1
622+ ? [Divider({ fgColor: "color08" })]
623+ : []),
624+ ]),
249625 ),
250626 ]);
251627 }
@@ -258,6 +634,7 @@ cel.viewport(() => {
258634 const rows = process.stdout.rows || 24;
259635 const useSideBySide = cols >= SIDE_BY_SIDE_MIN_COLS;
260636 const minRows = useSideBySide ? MIN_ROWS : STACKED_MIN_ROWS;
637+ const theme = currentTheme();
261638
262639 if (cols < MIN_COLS || rows < minRows) {
263640 return VStack(
@@ -266,7 +643,9 @@ cel.viewport(() => {
266643 justifyContent: "center",
267644 alignItems: "center",
268645 onKeyPress: (key) => {
269- if (key === "ctrl+q" || key === "ctrl+c") quit();
646+ if (key === "ctrl+q" || key === "ctrl+c") {
647+ quit();
648+ }
270649 },
271650 },
272651 [
@@ -274,7 +653,7 @@ cel.viewport(() => {
274653 " Terminal too small :(",
275654 "",
276655 " Please resize to at least",
277- ` ${String(MIN_COLS).padStart(3)}×${String(minRows).padStart(2)} characters.`,
656+ ` ${String(MIN_COLS).padStart(3)}x${String(minRows).padStart(2)} characters.`,
278657 "",
279658 " Ctrl+Q to quit",
280659 ]),
@@ -282,89 +661,94 @@ cel.viewport(() => {
282661 );
283662 }
284663
285- const status = isDone() ? "done" : paused ? "paused" : "streaming";
286- const statusColor = isDone() ? "color02" : paused ? "color03" : "color06";
287- const theme = THEME_OPTIONS[themeIndex]!;
288- const panes = useSideBySide
664+ const mainPane = useSideBySide
289665 ? HStack({ flex: 1 }, [
290- codePane("TypeScript", status, content, LANGUAGE, theme.theme),
666+ detailPane(theme.theme),
291667 VDivider({ fgColor: "color08" }),
292- codePane("Bash", status, bashContent, BASH_LANGUAGE, theme.theme),
668+ streamBoard(),
293669 ])
294670 : VStack({ flex: 1 }, [
295- codePane("TypeScript", status, content, LANGUAGE, theme.theme),
671+ detailPane(theme.theme),
296672 Divider({ fgColor: "color08" }),
297- codePane("Bash", status, bashContent, BASH_LANGUAGE, theme.theme),
673+ streamBoard(),
298674 ]);
299675
300676 return VStack(
301677 {
302678 height: "100%",
303679 onKeyPress: (key) => {
304- if (key === "ctrl+q" || key === "ctrl+c") quit();
305- if (key === "ctrl+r") restart();
306- if (key === "ctrl+p") togglePause();
307- if (key === "ctrl+t") toggleTheme();
680+ if (key === "ctrl+q" || key === "ctrl+c") {
681+ quit();
682+ }
683+ if (key === "ctrl+r") {
684+ restart();
685+ }
686+ if (key === "ctrl+p") {
687+ togglePause();
688+ }
689+ if (key === "ctrl+t") {
690+ toggleTheme();
691+ }
692+ if (key === "left" || key === "shift+tab") {
693+ cycleSelection(-1);
694+ }
695+ if (key === "right" || key === "tab") {
696+ cycleSelection(1);
697+ }
308698 },
309699 },
310700 [
311701 HStack({ padding: { x: 1 }, gap: 2 }, [
312- Text("SyntaxHighlight Demo", { bold: true, fgColor: "color06" }),
702+ Text("SyntaxHighlight streaming demo", {
703+ bold: true,
704+ fgColor: "color06",
705+ }),
313706 Spacer(),
314707 Text(`theme: ${theme.label}`, { fgColor: "color03" }),
315- Text(`${LANGUAGE} + ${BASH_LANGUAGE}`, { fgColor: "color08" }),
708+ Text(`built-ins: ${DEMO_SAMPLES.length}`, { fgColor: "color08" }),
316709 ]),
317710 Divider({ fgColor: "color08" }),
318- HStack({ padding: { x: 1 }, gap: 2 }, [
319- Text(`status: ${status}`, { fgColor: statusColor, bold: true }),
320- Text(`ts chars: ${content.length}/${FULL_CODE.length}`, {
321- fgColor: "color08",
322- }),
323- Text(`bash chars: ${bashContent.length}/${BASH_CODE.length}`, {
711+ VStack({ padding: { x: 1 } }, [
712+ Text("All registered lextide built-ins stream in append-only chunks.", {
324713 fgColor: "color08",
714+ italic: true,
325715 }),
326- ]),
327- HStack({ padding: { x: 1 } }, [
716+ Text(
717+ "The large pane renders SyntaxHighlight(); the board shows the matching lowlight.stream(...) deltas.",
718+ {
719+ fgColor: "color08",
720+ italic: true,
721+ },
722+ ),
328723 Text(theme.help, {
329724 fgColor: "color08",
330- italic: true,
331725 }),
332726 ]),
727+ HStack({ padding: { x: 1 }, gap: 1, flexWrap: "wrap" }, [
728+ ...streams.map(languageChip),
729+ ]),
333730 Divider({ fgColor: "color08" }),
334- panes,
731+ mainPane,
335732 Divider({ fgColor: "color08" }),
336733 VStack({ padding: { x: 1 } }, [
337- HStack({ gap: 1 }, [
338- Text("Ctrl+R", {
339- fgColor: "color07",
340- bgColor: "color08",
341- bold: true,
342- }),
343- Text("restart", { fgColor: "color08" }),
344- Text(" "),
345- Text("Ctrl+P", {
346- fgColor: "color07",
347- bgColor: "color08",
348- bold: true,
349- }),
734+ HStack({ gap: 1, flexWrap: "wrap" }, [
735+ keycap("Left/Right"),
736+ Text("select language", { fgColor: "color08" }),
737+ keycap("Ctrl+P"),
350738 Text("pause", { fgColor: "color08" }),
351- Text(" "),
352- Text("Ctrl+T", {
353- fgColor: "color07",
354- bgColor: "color08",
355- bold: true,
356- }),
739+ keycap("Ctrl+R"),
740+ Text("restart", { fgColor: "color08" }),
741+ keycap("Ctrl+T"),
357742 Text("theme", { fgColor: "color08" }),
358- ]),
359- HStack({ gap: 1 }, [
360- Spacer(),
361- Text("Ctrl+Q", {
362- fgColor: "color07",
363- bgColor: "color08",
364- bold: true,
365- }),
743+ keycap("Ctrl+Q"),
366744 Text("quit", { fgColor: "color08" }),
367745 ]),
746+ Text(
747+ "Append-only only: restarting rebuilds every stream from empty; non-append edits would reset the streaming parser state.",
748+ {
749+ fgColor: "color08",
750+ },
751+ ),
368752 ]),
369753 ],
370754 );
package.json+1−1
@@ -20,7 +20,7 @@
2020 "lefthook": "^2.1.5",
2121 "mitata": "^1.0.34",
2222 "prettier": "^3.8.2",
23- "typedoc": "^0.28.18",
23+ "typedoc": "^0.28.19",
2424 "typedoc-plugin-markdown": "^4.11.0",
2525 "typescript": "^6.0.2"
2626 }
packages/components/package.json+1−1
@@ -34,7 +34,7 @@
3434 "dependencies": {
3535 "@cel-tui/core": "workspace:*",
3636 "@cel-tui/types": "workspace:*",
37- "lextide": "^0.2.0",
37+ "lextide": "^0.2.1",
3838 "yoctomarkdown": "^0.1.0"
3939 },
4040 "peerDependencies": {