xonecas.io
70160
Ce

cel-tui / commit db7529d

Add text editor reference example

Exercises: HStack root layout, fixed+flex sizing, controlled scroll,
onClick with focusable opt-out, TextInput as editor, repeat/fill for
colored status bar background.

xonecas2026-04-03 db7529db1c68daab37aa11e4735debda045ec33e parent 27ea458

1 file changed

spec.md+88−0
@@ -411,6 +411,94 @@ VStack({ height: "100%" }, [
411411
412412 ---
413413
414+## Reference Example: Text Editor
415+
416+```
417+┌──────────────┬───────────────────────────────┐
418+│ files/ │ main.ts │
419+│ ▸ main.ts │ │
420+│ utils.ts │ import { foo } from "./utils"; │
421+│ test.ts │ │
422+│ │ function main() { │
423+│ │ console.log(foo()); │
424+│ │ } │
425+│ │ │
426+│ │ │
427+├──────────────┴───────────────────────────────┤
428+│ main.ts Ln 3, Col 1 TypeScript ✓ │
429+└──────────────────────────────────────────────┘
430+```
431+
432+```ts
433+HStack({ height: "100%" }, [
434+ // Sidebar
435+ VStack(
436+ {
437+ width: 20,
438+ overflow: "scroll",
439+ scrollOffset: sidebarScroll,
440+ onScroll: (o) => {
441+ sidebarScroll = o;
442+ },
443+ },
444+ [
445+ Text("files/", { bold: true }),
446+ ...files.map((file) =>
447+ HStack(
448+ {
449+ onClick: () => selectFile(file),
450+ focusable: false,
451+ },
452+ [
453+ Text(
454+ `${file === activeFile ? "▸" : " "} ${file.name}`,
455+ file === activeFile
456+ ? { fgColor: "cyan", bgColor: "brightBlack" }
457+ : {},
458+ ),
459+ ],
460+ ),
461+ ),
462+ ],
463+ ),
464+
465+ // Main area
466+ VStack({ flex: 1 }, [
467+ // Tab bar
468+ HStack({ height: 1 }, [
469+ Text(` ${activeFile.name} `, { bold: true, bgColor: "brightBlack" }),
470+ Text(" ", { repeat: "fill" }),
471+ ]),
472+
473+ // Editor
474+ TextInput({
475+ value: activeFile.content,
476+ onChange: handleEdit,
477+ focused: editorFocused,
478+ onFocus: () => {
479+ editorFocused = true;
480+ },
481+ onBlur: () => {
482+ editorFocused = false;
483+ },
484+ }),
485+
486+ // Status bar
487+ HStack({ height: 1 }, [
488+ Text(` ${activeFile.name}`, { fgColor: "white", bgColor: "blue" }),
489+ Text(` Ln ${cursor.line}, Col ${cursor.col}`, {
490+ fgColor: "white",
491+ bgColor: "blue",
492+ }),
493+ Text(" ", { repeat: "fill", bgColor: "blue" }),
494+ Text(`TypeScript ✓ `, { fgColor: "white", bgColor: "blue" }),
495+ ]),
496+ ]),
497+]);
498+```
499+
500+---
501+
414502 ## Open Questions
415503
416504 - [x] `Text` styling props and text wrapping