@@ -1,7 +1,7 @@
11 /**
22 * cel-tui: SyntaxHighlight demo
33 *
4- * Streams TypeScript code into the SyntaxHighlight component.
4+ * Streams TypeScript and Bash code into SyntaxHighlight.
55 * Shows synchronous lowlight highlighting plus append-only incremental updates.
66 *
77 * Run: bun run examples/syntax-highlight.ts
@@ -12,12 +12,16 @@ import {
1212 Divider,
1313 Spacer,
1414 SyntaxHighlight,
15+ VDivider,
1516 type SyntaxHighlightTheme,
1617 } from "@cel-tui/components";
1718
1819 const LANGUAGE = "typescript";
20+const BASH_LANGUAGE = "bash";
1921 const MIN_COLS = 52;
2022 const MIN_ROWS = 16;
23+const STACKED_MIN_ROWS = 20;
24+const SIDE_BY_SIDE_MIN_COLS = 100;
2125 const CHUNK_SIZE = 3;
2226 const TICK_MS = 18;
2327
@@ -109,7 +113,28 @@ const FULL_CODE = [
109113 "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.",
110114 ].join("\n");
111115
116+const BASH_CODE = [
117+ "#!/usr/bin/env bash",
118+ "set -euo pipefail",
119+ "",
120+ 'project_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)',
121+ "",
122+ "build() {",
123+ " local target=${1:-debug}",
124+ ' echo "==> building ${target} from ${project_root}"',
125+ " bun run typecheck",
126+ " bun test",
127+ "}",
128+ "",
129+ "for target in debug release; do",
130+ ' if [[ "$target" == "release" ]]; then',
131+ ' build "$target"',
132+ " fi",
133+ "done",
134+].join("\n");
135+
112136 let content = "";
137+let bashContent = "";
113138 let paused = false;
114139 let themeIndex = 0;
115140 let streamTimer: ReturnType<typeof setTimeout> | null = null;
@@ -128,7 +153,9 @@ function stopStreaming() {
128153 }
129154
130155 function isDone(): boolean {
131- return content.length >= FULL_CODE.length;
156+ return (
157+ content.length >= FULL_CODE.length && bashContent.length >= BASH_CODE.length
158+ );
132159 }
133160
134161 function startStreaming() {
@@ -144,7 +171,17 @@ function streamNext() {
144171 return;
145172 }
146173
147- content += FULL_CODE.slice(content.length, content.length + CHUNK_SIZE);
174+ const nextContentLength = Math.min(
175+ FULL_CODE.length,
176+ content.length + CHUNK_SIZE,
177+ );
178+ const nextBashLength = Math.min(
179+ BASH_CODE.length,
180+ Math.round((nextContentLength / FULL_CODE.length) * BASH_CODE.length),
181+ );
182+
183+ content = FULL_CODE.slice(0, nextContentLength);
184+ bashContent = BASH_CODE.slice(0, nextBashLength);
148185 cel.render();
149186
150187 if (isDone()) {
@@ -157,6 +194,7 @@ function streamNext() {
157194
158195 function restart() {
159196 content = "";
197+ bashContent = "";
160198 paused = false;
161199 startStreaming();
162200 cel.render();
@@ -175,14 +213,48 @@ function toggleTheme() {
175213 cel.render();
176214 }
177215
216+function codePane(
217+ title: string,
218+ status: string,
219+ content: string,
220+ language: string,
221+ theme?: SyntaxHighlightTheme,
222+) {
223+ return VStack({ flex: 1 }, [
224+ HStack(
225+ {
226+ height: 1,
227+ padding: { x: 1 },
228+ bgColor: "color08",
229+ },
230+ [
231+ Text(title, { bold: true, fgColor: "color06" }),
232+ Spacer(),
233+ Text(status, { fgColor: "color15" }),
234+ ],
235+ ),
236+ VStack(
237+ {
238+ flex: 1,
239+ overflow: "scroll",
240+ scrollbar: true,
241+ padding: { x: 1 },
242+ },
243+ [SyntaxHighlight(content, language, { theme })],
244+ ),
245+ ]);
246+}
247+
178248 startStreaming();
179249
180250 cel.init(new ProcessTerminal());
181251 cel.viewport(() => {
182252 const cols = process.stdout.columns || 80;
183253 const rows = process.stdout.rows || 24;
254+ const useSideBySide = cols >= SIDE_BY_SIDE_MIN_COLS;
255+ const minRows = useSideBySide ? MIN_ROWS : STACKED_MIN_ROWS;
184256
185- if (cols < MIN_COLS || rows < MIN_ROWS) {
257+ if (cols < MIN_COLS || rows < minRows) {
186258 return VStack(
187259 {
188260 height: "100%",
@@ -198,7 +270,7 @@ cel.viewport(() => {
198270 Text("│ │", { fgColor: "color03" }),
199271 Text("│ Please resize to at least │", { fgColor: "color03" }),
200272 Text(
201- `│ ${String(MIN_COLS).padStart(3)}×${String(MIN_ROWS).padStart(2)} characters. │`,
273+ `│ ${String(MIN_COLS).padStart(3)}×${String(minRows).padStart(2)} characters. │`,
202274 { fgColor: "color03" },
203275 ),
204276 Text("│ │", { fgColor: "color03" }),
@@ -211,6 +283,17 @@ cel.viewport(() => {
211283 const status = isDone() ? "done" : paused ? "paused" : "streaming";
212284 const statusColor = isDone() ? "color02" : paused ? "color03" : "color06";
213285 const theme = THEME_OPTIONS[themeIndex]!;
286+ const panes = useSideBySide
287+ ? HStack({ flex: 1 }, [
288+ codePane("TypeScript", "streaming", content, LANGUAGE, theme.theme),
289+ VDivider({ fgColor: "color08" }),
290+ codePane("Bash", "streaming", bashContent, BASH_LANGUAGE, theme.theme),
291+ ])
292+ : VStack({ flex: 1 }, [
293+ codePane("TypeScript", "streaming", content, LANGUAGE, theme.theme),
294+ Divider({ fgColor: "color08" }),
295+ codePane("Bash", "streaming", bashContent, BASH_LANGUAGE, theme.theme),
296+ ]);
214297
215298 return VStack(
216299 {
@@ -227,12 +310,15 @@ cel.viewport(() => {
227310 Text("SyntaxHighlight Demo", { bold: true, fgColor: "color06" }),
228311 Spacer(),
229312 Text(`theme: ${theme.label}`, { fgColor: "color03" }),
230- Text(LANGUAGE, { fgColor: "color08" }),
313+ Text(`${LANGUAGE} + ${BASH_LANGUAGE}`, { fgColor: "color08" }),
231314 ]),
232315 Divider({ fgColor: "color08" }),
233316 HStack({ padding: { x: 1 }, gap: 2 }, [
234317 Text(`status: ${status}`, { fgColor: statusColor, bold: true }),
235- Text(`chars: ${content.length}/${FULL_CODE.length}`, {
318+ Text(`ts chars: ${content.length}/${FULL_CODE.length}`, {
319+ fgColor: "color08",
320+ }),
321+ Text(`bash chars: ${bashContent.length}/${BASH_CODE.length}`, {
236322 fgColor: "color08",
237323 }),
238324 ]),
@@ -243,15 +329,7 @@ cel.viewport(() => {
243329 }),
244330 ]),
245331 Divider({ fgColor: "color08" }),
246- VStack(
247- {
248- flex: 1,
249- overflow: "scroll",
250- scrollbar: true,
251- padding: { x: 1 },
252- },
253- [SyntaxHighlight(content, LANGUAGE, { theme: theme.theme })],
254- ),
332+ panes,
255333 Divider({ fgColor: "color08" }),
256334 VStack({ padding: { x: 1 } }, [
257335 HStack({ gap: 1 }, [