xonecas.io
70160
Ce

cel-tui / commit ea2bbed

chore: fix repo-wide biome checks

xonecas2026-04-11 ea2bbedc89e105277cffacc894d50fa59b2f567c parent b1bc988

37 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

biome.json+1−1
@@ -1,5 +1,5 @@
11 {
2- "$schema": "https://biomejs.dev/schemas/2.4.10/schema.json",
2+ "$schema": "https://biomejs.dev/schemas/2.4.11/schema.json",
33 "assist": {
44 "actions": {
55 "source": {
package.json+2−2
@@ -5,8 +5,8 @@
55 "packages/*"
66 ],
77 "scripts": {
8- "check": "biome check packages/*/src/**/*.ts",
9- "check:fix": "biome check --write packages/*/src/**/*.ts",
8+ "check": "biome check",
9+ "check:fix": "biome check --write",
1010 "format": "prettier --check .",
1111 "format:fix": "prettier --write .",
1212 "typecheck": "tsc --noEmit",
packages/components/src/button.ts+2−2
@@ -1,5 +1,5 @@
1-import type { ContainerNode, StyleProps } from "@cel-tui/types";
21 import { HStack, Text } from "@cel-tui/core";
2+import type { ContainerNode, ContainerProps, StyleProps } from "@cel-tui/types";
33
44 /**
55 * Props for the {@link Button} component.
@@ -37,7 +37,7 @@ export interface ButtonProps extends StyleProps {
3737 * Key event handler. Receives normalized semantic keys that bubble up
3838 * to this button. Return `false` to keep bubbling.
3939 */
40- onKeyPress?: (key: string) => boolean | void;
40+ onKeyPress?: ContainerProps["onKeyPress"];
4141 /** Internal padding in cells. */
4242 padding?: { x?: number; y?: number };
4343 }
packages/components/src/divider.ts+1−1
@@ -1,5 +1,5 @@
1-import type { Color, TextNode } from "@cel-tui/types";
21 import { Text } from "@cel-tui/core";
2+import type { Color, TextNode } from "@cel-tui/types";
33
44 /** Props for the {@link Divider} component. */
55 export interface DividerProps {
packages/components/src/index.ts+12−12
@@ -16,26 +16,26 @@
1616 * ```
1717 */
1818
19-export { Spacer } from "./spacer.js";
20-export { Divider, type DividerProps } from "./divider.js";
21-export { VDivider, type VDividerProps } from "./vdivider.js";
2219 export { Button, type ButtonProps } from "./button.js";
20+export { Divider, type DividerProps } from "./divider.js";
2321 export {
24- Select,
25- type SelectProps,
26- type SelectItem,
27- type SelectInstance,
28-} from "./select.js";
29-export {
22+ type BlockToken,
23+ type InlineSpan,
3024 Markdown,
31- tokenize,
3225 type MarkdownProps,
3326 type MarkdownTheme,
34- type BlockToken,
35- type InlineSpan,
27+ tokenize,
3628 } from "./markdown.js";
29+export {
30+ Select,
31+ type SelectInstance,
32+ type SelectItem,
33+ type SelectProps,
34+} from "./select.js";
35+export { Spacer } from "./spacer.js";
3736 export {
3837 SyntaxHighlight,
3938 type SyntaxHighlightProps,
4039 type SyntaxHighlightTheme,
4140 } from "./syntax-highlight.js";
41+export { VDivider, type VDividerProps } from "./vdivider.js";
packages/components/src/markdown.test.ts+68−59
@@ -1,4 +1,4 @@
1-import { describe, test, expect } from "bun:test";
1+import { describe, expect, test } from "bun:test";
22 import type { ContainerNode, Node, TextNode } from "@cel-tui/types";
33 import { Markdown } from "./markdown";
44
@@ -22,6 +22,15 @@ function asContainer(node: Node): ContainerNode {
2222 return node as ContainerNode;
2323 }
2424
25+function item<T>(items: readonly T[], index: number): T {
26+ const value = items[index];
27+ expect(value).toBeDefined();
28+ if (value === undefined) {
29+ throw new Error(`Missing item at index ${index}`);
30+ }
31+ return value;
32+}
33+
2534 // ─── Markdown component ─────────────────────────────────────────
2635
2736 describe("Markdown", () => {
@@ -33,7 +42,7 @@ describe("Markdown", () => {
3342 test("heading renders as styled Text", () => {
3443 const nodes = Markdown("# Hello");
3544 expect(nodes).toHaveLength(1);
36- const t = asText(nodes[0]!);
45+ const t = asText(item(nodes, 0));
3746 expect(t.content).toBe("Hello");
3847 expect(t.props.bold).toBe(true);
3948 expect(t.props.fgColor).toBe("color06");
@@ -41,9 +50,9 @@ describe("Markdown", () => {
4150
4251 test("heading levels have different styles", () => {
4352 const nodes = Markdown("# H1\n## H2\n### H3");
44- const h1 = asText(nodes[0]!);
45- const h2 = asText(nodes[1]!);
46- const h3 = asText(nodes[2]!);
53+ const h1 = asText(item(nodes, 0));
54+ const h2 = asText(item(nodes, 1));
55+ const h3 = asText(item(nodes, 2));
4756 expect(h1.props.fgColor).toBe("color06");
4857 expect(h2.props.fgColor).toBe("color03");
4958 expect(h3.props.fgColor).toBe("color02");
@@ -52,7 +61,7 @@ describe("Markdown", () => {
5261 test("plain paragraph renders as wrapping Text", () => {
5362 const nodes = Markdown("Hello world");
5463 expect(nodes).toHaveLength(1);
55- const t = asText(nodes[0]!);
64+ const t = asText(item(nodes, 0));
5665 expect(t.content).toBe("Hello world");
5766 expect(t.props.wrap).toBe("word");
5867 });
@@ -60,47 +69,47 @@ describe("Markdown", () => {
6069 test("paragraph with bold renders as wrapping HStack", () => {
6170 const nodes = Markdown("Hello **bold** world");
6271 expect(nodes).toHaveLength(1);
63- const hstack = asContainer(nodes[0]!);
72+ const hstack = asContainer(item(nodes, 0));
6473 expect(hstack.type).toBe("hstack");
6574 expect(hstack.props.flexWrap).toBe("wrap");
6675 // Children: "Hello", " ", bold("bold"), " ", "world"
6776 expect(hstack.children).toHaveLength(5);
68- expect(asText(hstack.children[0]!).content).toBe("Hello");
69- expect(asText(hstack.children[1]!).content).toBe(" ");
70- const boldNode = asText(hstack.children[2]!);
77+ expect(asText(item(hstack.children, 0)).content).toBe("Hello");
78+ expect(asText(item(hstack.children, 1)).content).toBe(" ");
79+ const boldNode = asText(item(hstack.children, 2));
7180 expect(boldNode.content).toBe("bold");
7281 expect(boldNode.props.bold).toBe(true);
73- expect(asText(hstack.children[3]!).content).toBe(" ");
74- expect(asText(hstack.children[4]!).content).toBe("world");
82+ expect(asText(item(hstack.children, 3)).content).toBe(" ");
83+ expect(asText(item(hstack.children, 4)).content).toBe("world");
7584 });
7685
7786 test("paragraph with italic renders styled nodes", () => {
7887 const nodes = Markdown("some *italic* text");
79- const hstack = asContainer(nodes[0]!);
88+ const hstack = asContainer(item(nodes, 0));
8089 expect(hstack.type).toBe("hstack");
8190 // "some", " ", italic("italic"), " ", "text"
82- const italicNode = asText(hstack.children[2]!);
91+ const italicNode = asText(item(hstack.children, 2));
8392 expect(italicNode.content).toBe("italic");
8493 expect(italicNode.props.italic).toBe(true);
8594 });
8695
8796 test("paragraph with inline code keeps code span atomic", () => {
8897 const nodes = Markdown("use `foo bar` here");
89- const hstack = asContainer(nodes[0]!);
98+ const hstack = asContainer(item(nodes, 0));
9099 expect(hstack.type).toBe("hstack");
91100 // "use", " ", code("foo bar"), " ", "here"
92101 expect(hstack.children).toHaveLength(5);
93- const codeNode = asText(hstack.children[2]!);
102+ const codeNode = asText(item(hstack.children, 2));
94103 expect(codeNode.content).toBe("foo bar");
95104 expect(codeNode.props.fgColor).toBe("color03");
96105 });
97106
98107 test("paragraph with link keeps link text atomic", () => {
99108 const nodes = Markdown("see [the docs](https://example.com) here");
100- const hstack = asContainer(nodes[0]!);
109+ const hstack = asContainer(item(nodes, 0));
101110 // "see", " ", link("the docs"), " ", "here"
102111 expect(hstack.children).toHaveLength(5);
103- const linkNode = asText(hstack.children[2]!);
112+ const linkNode = asText(item(hstack.children, 2));
104113 expect(linkNode.content).toBe("the docs");
105114 expect(linkNode.props.fgColor).toBe("color06");
106115 expect(linkNode.props.underline).toBe(true);
@@ -108,69 +117,69 @@ describe("Markdown", () => {
108117
109118 test("paragraph with mixed formatting", () => {
110119 const nodes = Markdown("Hello, **bold**!");
111- const hstack = asContainer(nodes[0]!);
120+ const hstack = asContainer(item(nodes, 0));
112121 // "Hello,", " ", bold("bold"), "!"
113122 expect(hstack.children).toHaveLength(4);
114- expect(asText(hstack.children[0]!).content).toBe("Hello,");
115- expect(asText(hstack.children[1]!).content).toBe(" ");
116- expect(asText(hstack.children[2]!).props.bold).toBe(true);
123+ expect(asText(item(hstack.children, 0)).content).toBe("Hello,");
124+ expect(asText(item(hstack.children, 1)).content).toBe(" ");
125+ expect(asText(item(hstack.children, 2)).props.bold).toBe(true);
117126 // No space before "!" — punctuation is adjacent
118- expect(asText(hstack.children[3]!).content).toBe("!");
127+ expect(asText(item(hstack.children, 3)).content).toBe("!");
119128 });
120129
121130 test("code block renders as VStack with Text", () => {
122131 const nodes = Markdown("```js\nconst x = 1;\n```");
123132 expect(nodes).toHaveLength(1);
124- const container = asContainer(nodes[0]!);
133+ const container = asContainer(item(nodes, 0));
125134 expect(container.type).toBe("vstack");
126135 expect(container.props.padding).toEqual({ x: 1 });
127136 expect(container.props.bgColor).toBe("color08");
128137 expect(container.children).toHaveLength(1);
129- expect(textContent(container.children[0]!)).toBe("const x = 1;");
138+ expect(textContent(item(container.children, 0))).toBe("const x = 1;");
130139 });
131140
132141 test("unordered list item renders as HStack with marker", () => {
133142 const nodes = Markdown("- hello world");
134143 expect(nodes).toHaveLength(1);
135- const row = asContainer(nodes[0]!);
144+ const row = asContainer(item(nodes, 0));
136145 expect(row.type).toBe("hstack");
137146 expect(row.children).toHaveLength(2);
138147
139148 // Marker
140- const marker = asText(row.children[0]!);
149+ const marker = asText(item(row.children, 0));
141150 expect(marker.content).toBe("• ");
142151 expect(marker.props.fgColor).toBe("color03");
143152
144153 // Content in flex VStack
145- const wrapper = asContainer(row.children[1]!);
154+ const wrapper = asContainer(item(row.children, 1));
146155 expect(wrapper.type).toBe("vstack");
147156 expect(wrapper.props.flex).toBe(1);
148- const content = asText(wrapper.children[0]!);
157+ const content = asText(item(wrapper.children, 0));
149158 expect(content.content).toBe("hello world");
150159 expect(content.props.wrap).toBe("word");
151160 });
152161
153162 test("ordered list item uses index as marker", () => {
154163 const nodes = Markdown("3. third item");
155- const row = asContainer(nodes[0]!);
156- const marker = asText(row.children[0]!);
164+ const row = asContainer(item(nodes, 0));
165+ const marker = asText(item(row.children, 0));
157166 expect(marker.content).toBe("3. ");
158167 });
159168
160169 test("blockquote renders with bar and italic content", () => {
161170 const nodes = Markdown("> quoted text");
162171 expect(nodes).toHaveLength(1);
163- const row = asContainer(nodes[0]!);
172+ const row = asContainer(item(nodes, 0));
164173 expect(row.type).toBe("hstack");
165174
166175 // Bar
167- const bar = asText(row.children[0]!);
176+ const bar = asText(item(row.children, 0));
168177 expect(bar.content).toBe("│ ");
169178 expect(bar.props.fgColor).toBe("color02");
170179
171180 // Content
172- const wrapper = asContainer(row.children[1]!);
173- const content = asText(wrapper.children[0]!);
181+ const wrapper = asContainer(item(row.children, 1));
182+ const content = asText(item(wrapper.children, 0));
174183 expect(content.content).toBe("quoted text");
175184 expect(content.props.italic).toBe(true);
176185 expect(content.props.wrap).toBe("word");
@@ -179,7 +188,7 @@ describe("Markdown", () => {
179188 test("horizontal rule renders as Divider", () => {
180189 const nodes = Markdown("---");
181190 expect(nodes).toHaveLength(1);
182- const t = asText(nodes[0]!);
191+ const t = asText(item(nodes, 0));
183192 // Divider is a Text with repeat: "fill"
184193 expect(t.content).toBe("─");
185194 expect(t.props.repeat).toBe("fill");
@@ -189,14 +198,14 @@ describe("Markdown", () => {
189198 test("blank line renders as empty Text", () => {
190199 const nodes = Markdown("hello\n\nworld");
191200 expect(nodes).toHaveLength(3);
192- expect(textContent(nodes[1]!)).toBe("");
201+ expect(textContent(item(nodes, 1))).toBe("");
193202 });
194203
195204 test("custom theme overrides defaults", () => {
196205 const nodes = Markdown("# Hello", {
197206 theme: { heading1: { bold: true, fgColor: "color05" } },
198207 });
199- const t = asText(nodes[0]!);
208+ const t = asText(item(nodes, 0));
200209 expect(t.props.fgColor).toBe("color05");
201210 });
202211
@@ -205,82 +214,82 @@ describe("Markdown", () => {
205214 theme: { heading1: { fgColor: "color01" } },
206215 });
207216 // Heading uses custom
208- expect(asText(nodes[0]!).props.fgColor).toBe("color01");
217+ expect(asText(item(nodes, 0)).props.fgColor).toBe("color01");
209218 // Blockquote bar uses default
210- const row = asContainer(nodes[1]!);
211- expect(asText(row.children[0]!).props.fgColor).toBe("color02");
219+ const row = asContainer(item(nodes, 1));
220+ expect(asText(item(row.children, 0)).props.fgColor).toBe("color02");
212221 });
213222
214223 test("inline formatting in headings is stripped to plain text", () => {
215224 const nodes = Markdown("# Hello **world** and `code`");
216- const t = asText(nodes[0]!);
225+ const t = asText(item(nodes, 0));
217226 expect(t.content).toBe("Hello world and code");
218227 });
219228
220229 test("link text is used, url is stripped", () => {
221230 const nodes = Markdown("See [the docs](https://example.com) here.");
222- const hstack = asContainer(nodes[0]!);
231+ const hstack = asContainer(item(nodes, 0));
223232 expect(hstack.type).toBe("hstack");
224233 expect(hstack.props.flexWrap).toBe("wrap");
225234 // "See", " ", link("the docs"), " ", "here."
226235 expect(hstack.children).toHaveLength(5);
227- expect(asText(hstack.children[0]!).content).toBe("See");
228- const link = asText(hstack.children[2]!);
236+ expect(asText(item(hstack.children, 0)).content).toBe("See");
237+ const link = asText(item(hstack.children, 2));
229238 expect(link.content).toBe("the docs");
230239 expect(link.props.fgColor).toBe("color06");
231- expect(asText(hstack.children[4]!).content).toBe("here.");
240+ expect(asText(item(hstack.children, 4)).content).toBe("here.");
232241 });
233242
234243 test("streaming: unclosed code block renders as code", () => {
235244 const nodes = Markdown("```js\nconst x = 1;");
236245 expect(nodes).toHaveLength(1);
237- const container = asContainer(nodes[0]!);
246+ const container = asContainer(item(nodes, 0));
238247 expect(container.props.bgColor).toBe("color08");
239- expect(textContent(container.children[0]!)).toBe("const x = 1;");
248+ expect(textContent(item(container.children, 0))).toBe("const x = 1;");
240249 });
241250
242251 test("streaming: unclosed bold appears as plain text", () => {
243252 // Unclosed ** is not parsed as bold — stays as text span
244253 const nodes = Markdown("hello **world");
245- const t = asText(nodes[0]!);
254+ const t = asText(item(nodes, 0));
246255 expect(t.content).toBe("hello **world");
247256 expect(t.props.wrap).toBe("word");
248257 });
249258
250259 test("list item with inline formatting", () => {
251260 const nodes = Markdown("- hello **bold** world");
252- const row = asContainer(nodes[0]!);
261+ const row = asContainer(item(nodes, 0));
253262 expect(row.type).toBe("hstack");
254- const wrapper = asContainer(row.children[1]!);
263+ const wrapper = asContainer(item(row.children, 1));
255264 expect(wrapper.type).toBe("vstack");
256265 // Content is a wrapping HStack
257- const content = asContainer(wrapper.children[0]!);
266+ const content = asContainer(item(wrapper.children, 0));
258267 expect(content.type).toBe("hstack");
259268 expect(content.props.flexWrap).toBe("wrap");
260269 // "hello", " ", bold("bold"), " ", "world"
261270 expect(content.children).toHaveLength(5);
262- expect(asText(content.children[2]!).props.bold).toBe(true);
271+ expect(asText(item(content.children, 2)).props.bold).toBe(true);
263272 });
264273
265274 test("blockquote with inline formatting", () => {
266275 const nodes = Markdown("> hello **bold** text");
267- const row = asContainer(nodes[0]!);
268- const wrapper = asContainer(row.children[1]!);
269- const content = asContainer(wrapper.children[0]!);
276+ const row = asContainer(item(nodes, 0));
277+ const wrapper = asContainer(item(row.children, 1));
278+ const content = asContainer(item(wrapper.children, 0));
270279 expect(content.type).toBe("hstack");
271280 expect(content.props.flexWrap).toBe("wrap");
272281 // blockquoteText style (italic) applied to the wrapping HStack
273282 expect(content.props.italic).toBe(true);
274283 // bold node inside inherits italic from parent, also has bold
275- expect(asText(content.children[2]!).props.bold).toBe(true);
284+ expect(asText(item(content.children, 2)).props.bold).toBe(true);
276285 });
277286
278287 test("inline code theme is customizable", () => {
279288 const nodes = Markdown("use `code` here", {
280289 theme: { inlineCode: { fgColor: "color01", bgColor: "color00" } },
281290 });
282- const hstack = asContainer(nodes[0]!);
283- const codeNode = asText(hstack.children[2]!);
291+ const hstack = asContainer(item(nodes, 0));
292+ const codeNode = asText(item(hstack.children, 2));
284293 expect(codeNode.props.fgColor).toBe("color01");
285294 expect(codeNode.props.bgColor).toBe("color00");
286295 });
packages/components/src/markdown.ts+2−2
@@ -1,6 +1,6 @@
1+import { HStack, Text, VStack } from "@cel-tui/core";
12 import type { Color, Node, StyleProps } from "@cel-tui/types";
2-import { VStack, HStack, Text } from "@cel-tui/core";
3-import { tokenize, type BlockToken, type InlineSpan } from "yoctomarkdown";
3+import { type InlineSpan, tokenize } from "yoctomarkdown";
44 import { Divider } from "./divider.js";
55
66 // Re-export token types so consumers don't need a direct yoctomarkdown dep
packages/components/src/select.test.ts+15−6
@@ -1,13 +1,22 @@
1-import { describe, it, expect } from "bun:test";
1+import { describe, expect, it } from "bun:test";
2+import type { NormalizedItem } from "./select.js";
23 import {
4+ adjustScroll,
5+ moveDown,
6+ moveUp,
37 normalizeItems,
48 prefixFilter,
5- moveUp,
6- moveDown,
7- adjustScroll,
89 Select,
910 } from "./select.js";
10-import type { NormalizedItem } from "./select.js";
11+
12+function item<T>(items: readonly T[], index: number): T {
13+ const value = items[index];
14+ expect(value).toBeDefined();
15+ if (value === undefined) {
16+ throw new Error(`Missing item at index ${index}`);
17+ }
18+ return value;
19+}
1120
1221 describe("normalizeItems", () => {
1322 it("normalizes string items", () => {
@@ -152,7 +161,7 @@ describe("Select", () => {
152161 // Search line + 5 visible items + overflow indicator = 7
153162 expect(node.children.length).toBe(7);
154163 // Last child should contain overflow text
155- const lastChild = node.children[6]!;
164+ const lastChild = item(node.children, 6);
156165 expect(lastChild.type).toBe("hstack");
157166 if (lastChild.type === "hstack") {
158167 const text = lastChild.children[0];
packages/components/src/select.ts+11−5
@@ -1,11 +1,12 @@
1+import { cel, HStack, Text, VStack } from "@cel-tui/core";
12 import type {
23 Color,
34 ContainerNode,
5+ ContainerProps,
46 Node,
57 SizeValue,
68 StyleProps,
79 } from "@cel-tui/types";
8-import { cel, VStack, HStack, Text } from "@cel-tui/core";
910
1011 /**
1112 * An item in the select list.
@@ -32,6 +33,8 @@ export type SelectItem =
3233 };
3334
3435 /** Configuration for the {@link Select} component. */
36+type SelectKeyPressHandler = NonNullable<ContainerProps["onKeyPress"]>;
37+
3538 export interface SelectProps {
3639 /** Items to choose from. */
3740 items: SelectItem[];
@@ -67,7 +70,7 @@ export interface SelectProps {
6770 *
6871 * @param key - The normalized semantic key string.
6972 */
70- onKeyPress?: (key: string) => boolean | void;
73+ onKeyPress?: SelectKeyPressHandler;
7174 /** Fixed width in cells or percentage. */
7275 width?: SizeValue;
7376 /** Fixed height in cells or percentage. */
@@ -245,7 +248,7 @@ export function Select(props: SelectProps): SelectInstance {
245248 // delegate to the user's handler for component-level interception.
246249 // If the user's handler also returns false, the framework continues
247250 // bubbling to ancestors automatically.
248- function composedKeyPress(key: string): boolean | void {
251+ function composedKeyPress(key: string): ReturnType<SelectKeyPressHandler> {
249252 const result = handleKey(key);
250253 if (result === false && userKeyPress) {
251254 return userKeyPress(key);
@@ -261,7 +264,7 @@ export function Select(props: SelectProps): SelectInstance {
261264 return prefixFilter(normalizeItems(rawItems), query);
262265 }
263266
264- function handleKey(key: string): boolean | void {
267+ function handleKey(key: string): ReturnType<SelectKeyPressHandler> {
265268 switch (key) {
266269 case "enter": {
267270 const filtered = getFiltered();
@@ -345,7 +348,10 @@ export function Select(props: SelectProps): SelectInstance {
345348 children.push(HStack({}, [Text(" no matches", { fgColor: "color08" })]));
346349 } else {
347350 for (let i = 0; i < visible.length; i++) {
348- const item = visible[i]!;
351+ const item = visible[i];
352+ if (item === undefined) {
353+ continue;
354+ }
349355 const globalIndex = scrollOffset + i;
350356 const isHighlighted = globalIndex === highlightIndex;
351357
packages/components/src/spacer.ts+1−1
@@ -1,5 +1,5 @@
1-import type { ContainerNode } from "@cel-tui/types";
21 import { VStack } from "@cel-tui/core";
2+import type { ContainerNode } from "@cel-tui/types";
33
44 /**
55 * Flexible spacer that fills available space along the parent's main axis.
packages/components/src/syntax-highlight.test.ts+28−16
@@ -16,6 +16,15 @@ function asText(node: Node): TextNode {
1616 return node as TextNode;
1717 }
1818
19+function item<T>(items: readonly T[], index: number): T {
20+ const value = items[index];
21+ expect(value).toBeDefined();
22+ if (value === undefined) {
23+ throw new Error(`Missing item at index ${index}`);
24+ }
25+ return value;
26+}
27+
1928 function lineText(line: Node): string {
2029 const container = asContainer(line);
2130 return container.children.map((child) => asText(child).content).join("");
@@ -23,7 +32,7 @@ function lineText(line: Node): string {
2332
2433 function firstText(line: Node): TextNode {
2534 const container = asContainer(line);
26- return asText(container.children[0]!);
35+ return asText(item(container.children, 0));
2736 }
2837
2938 function textNodes(node: ContainerNode): TextNode[] {
@@ -79,7 +88,7 @@ describe("SyntaxHighlight", () => {
7988
8089 expect(node.type).toBe("vstack");
8190 expect(node.children).toHaveLength(1);
82- expect(lineText(node.children[0]!)).toBe("plain text");
91+ expect(lineText(item(node.children, 0))).toBe("plain text");
8392 expect(hasStyledText(node)).toBe(false);
8493 });
8594
@@ -89,8 +98,8 @@ describe("SyntaxHighlight", () => {
8998 expect(node.type).toBe("vstack");
9099 expect(node.children).toHaveLength(1);
91100
92- const firstLine = asContainer(node.children[0]!);
93- const firstToken = asText(firstLine.children[0]!);
101+ const firstLine = asContainer(item(node.children, 0));
102+ const firstToken = asText(item(firstLine.children, 0));
94103 expect(firstLine.props.flexWrap).toBe("wrap");
95104 expect(firstToken.content).toBe("const");
96105 expect(firstToken.props.fgColor).toBeDefined();
@@ -165,8 +174,8 @@ describe("SyntaxHighlight", () => {
165174 const node = render("const first = 1\nconst second = 2", "javascript");
166175
167176 expect(node.children).toHaveLength(2);
168- expect(lineText(node.children[0]!)).toBe("const first = 1");
169- expect(lineText(node.children[1]!)).toBe("const second = 2");
177+ expect(lineText(item(node.children, 0))).toBe("const first = 1");
178+ expect(lineText(item(node.children, 1))).toBe("const second = 2");
170179 });
171180
172181 test("updates append-only content without duplicating previous text", () => {
@@ -174,7 +183,7 @@ describe("SyntaxHighlight", () => {
174183 const node = render('const message = "hello"', "javascript");
175184
176185 expect(node.children).toHaveLength(1);
177- expect(lineText(node.children[0]!)).toBe('const message = "hello"');
186+ expect(lineText(item(node.children, 0))).toBe('const message = "hello"');
178187 });
179188
180189 test("preserves highlighting across appended multiline comment", () => {
@@ -182,21 +191,24 @@ describe("SyntaxHighlight", () => {
182191 const node = render("/* hello\nworld */", "javascript");
183192
184193 expect(node.children).toHaveLength(2);
185- expect(lineText(node.children[0]!)).toBe("/* hello");
186- expect(lineText(node.children[1]!)).toBe("world */");
194+ expect(lineText(item(node.children, 0))).toBe("/* hello");
195+ expect(lineText(item(node.children, 1))).toBe("world */");
187196
188- const firstLine = firstText(node.children[0]!);
189- const secondLine = firstText(node.children[1]!);
197+ const firstLine = firstText(item(node.children, 0));
198+ const secondLine = firstText(item(node.children, 1));
190199 expect(firstLine.props.fgColor).toBeDefined();
191200 expect(secondLine.props.fgColor).toBe(firstLine.props.fgColor);
192201 });
193202
194203 test("template substitutions reset back to base text style", () => {
195- const node = render("`hi ${name}`", "javascript");
204+ const interpolation = `${"$"}{name}`;
205+ const node = render(`\`hi ${interpolation}\``, "javascript");
196206
197207 expect(findText(node, "`hi").props.fgColor).toBe("color02");
198208 expect(findText(node, " ").props.fgColor).toBe("color02");
199- expect(findTextContaining(node, "${name}").props.fgColor).toBeUndefined();
209+ expect(
210+ findTextContaining(node, interpolation).props.fgColor,
211+ ).toBeUndefined();
200212 });
201213
202214 test("falls back to full rehighlight on non-append edits", () => {
@@ -204,8 +216,8 @@ describe("SyntaxHighlight", () => {
204216 const node = render("function value() {}", "javascript");
205217
206218 expect(node.children).toHaveLength(1);
207- expect(lineText(node.children[0]!)).toBe("function value() {}");
208- expect(firstText(node.children[0]!).content).toBe("function");
209- expect(firstText(node.children[0]!).props.fgColor).toBeDefined();
219+ expect(lineText(item(node.children, 0))).toBe("function value() {}");
220+ expect(firstText(item(node.children, 0)).content).toBe("function");
221+ expect(firstText(item(node.children, 0)).props.fgColor).toBeDefined();
210222 });
211223 });
packages/components/src/syntax-highlight.ts+21−5
@@ -1,5 +1,5 @@
1-import type { Color, ContainerNode, Node, StyleProps } from "@cel-tui/types";
21 import { HStack, Text, VStack } from "@cel-tui/core";
2+import type { Color, ContainerNode, Node, StyleProps } from "@cel-tui/types";
33 import {
44 all,
55 createLowlight,
@@ -130,6 +130,18 @@ const rgbCache = new Map<string, readonly [number, number, number]>();
130130 const colorSlotCache = new Map<string, Color>();
131131 const statesByKey = new Map<string, SyntaxHighlightState[]>();
132132
133+function requiredAt<T>(
134+ items: readonly T[],
135+ index: number,
136+ description: string,
137+): T {
138+ const item = items[index];
139+ if (item === undefined) {
140+ throw new Error(`Missing ${description} at index ${index}`);
141+ }
142+ return item;
143+}
144+
133145 const DEFAULT_CATEGORY_STYLES: Readonly<Record<TokenCategory, StyleProps>> = {
134146 addition: { fgColor: "color02" },
135147 comment: { fgColor: "color08", italic: true },
@@ -307,7 +319,7 @@ function colorToSlot(color: string | undefined): Color | undefined {
307319 }
308320
309321 const rgb = parseHex(normalized);
310- let best = ANSI_SLOT_HEX[0]![0];
322+ let best = requiredAt(ANSI_SLOT_HEX, 0, "ANSI color slot")[0];
311323 let bestDistance = Number.POSITIVE_INFINITY;
312324
313325 for (const [slot, hex] of ANSI_SLOT_HEX) {
@@ -490,7 +502,7 @@ function findState(
490502 const states = getStates(key);
491503
492504 for (let i = states.length - 1; i >= 0; i--) {
493- const state = states[i]!;
505+ const state = requiredAt(states, i, "syntax highlight state");
494506 if (state.lastContent === content) {
495507 return state;
496508 }
@@ -500,7 +512,7 @@ function findState(
500512 let bestLength = -1;
501513
502514 for (let i = states.length - 1; i >= 0; i--) {
503- const state = states[i]!;
515+ const state = requiredAt(states, i, "syntax highlight state");
504516 if (!content.startsWith(state.lastContent)) {
505517 continue;
506518 }
@@ -606,7 +618,11 @@ function pushText(
606618 const pieces = content.split("\n");
607619
608620 for (let i = 0; i < pieces.length; i++) {
609- pushRun(lines[lines.length - 1]!, pieces[i]!, style);
621+ pushRun(
622+ requiredAt(lines, lines.length - 1, "highlight line"),
623+ requiredAt(pieces, i, "text piece"),
624+ style,
625+ );
610626 if (i < pieces.length - 1) {
611627 lines.push([]);
612628 }
packages/components/src/vdivider.ts+1−1
@@ -1,5 +1,5 @@
1+import { Text, VStack } from "@cel-tui/core";
12 import type { Color, ContainerNode } from "@cel-tui/types";
2-import { VStack, Text } from "@cel-tui/core";
33
44 /** Props for the {@link VDivider} component. */
55 export interface VDividerProps {
packages/core/src/cel.test.ts+46−27
@@ -1,9 +1,9 @@
11 import { afterEach, describe, expect, test } from "bun:test";
22 import { cel } from "./cel.js";
3-import { MockTerminal } from "./terminal.js";
3+import { HStack, VStack } from "./primitives/stacks.js";
44 import { Text } from "./primitives/text.js";
55 import { TextInput } from "./primitives/text-input.js";
6-import { VStack, HStack } from "./primitives/stacks.js";
6+import { MockTerminal } from "./terminal.js";
77 import { kittyEncode } from "./test-helpers.js";
88
99 // Kitty protocol byte sequences for commonly used keys
@@ -13,10 +13,20 @@ const ESCAPE = kittyEncode("escape");
1313 const SHIFT_TAB = kittyEncode("shift+tab");
1414 const CTRL_S = kittyEncode("ctrl+s");
1515 const LEGACY_CTRL_R = "\x12";
16-const TITLE_SEQUENCE_RE = /\x1b\][02];([^\x07\x1b]*)(?:\x07|\x1b\\)/g;
16+// biome-ignore lint/complexity/useRegexLiterals: using RegExp here avoids control-character regex diagnostics.
17+const TITLE_SEQUENCE_RE = new RegExp(
18+ String.raw`\x1b\][02];([^\x07\x1b]*)(?:\x07|\x1b\\)`,
19+ "g",
20+);
1721
1822 function extractTitlePayloads(output: string): string[] {
19- return Array.from(output.matchAll(TITLE_SEQUENCE_RE), (match) => match[1]!);
23+ return Array.from(output.matchAll(TITLE_SEQUENCE_RE), (match) => {
24+ const payload = match[1];
25+ if (payload === undefined) {
26+ throw new Error("Missing terminal title payload");
27+ }
28+ return payload;
29+ });
2030 }
2131
2232 describe("cel end-to-end", () => {
@@ -37,6 +47,15 @@ describe("cel end-to-end", () => {
3747 await new Promise((resolve) => setTimeout(resolve, 10));
3848 }
3949
50+ function currentBuffer() {
51+ const buf = cel._getBuffer();
52+ expect(buf).not.toBeNull();
53+ if (buf === null) {
54+ throw new Error("Expected a rendered buffer");
55+ }
56+ return buf;
57+ }
58+
4059 test("renders a single Text node", async () => {
4160 const term = setup(10, 1);
4261 cel.viewport(() => Text("Hello"));
@@ -404,14 +423,14 @@ describe("cel end-to-end", () => {
404423 await waitForRender();
405424
406425 // Before scroll, line 1 should be visible at row 0
407- const buf1 = cel._getBuffer()!;
426+ const buf1 = currentBuffer();
408427 expect(buf1.get(0, 0).char).toBe("l"); // "line 1"
409428
410429 term.sendInput("\x1b[<65;4;3M");
411430 await waitForRender();
412431
413432 // After scrolling by the adaptive step (4), line 5 should now be at row 0
414- const buf2 = cel._getBuffer()!;
433+ const buf2 = currentBuffer();
415434 let row0 = "";
416435 for (let x = 0; x < 6; x++) row0 += buf2.get(x, 0).char;
417436 expect(row0).toBe("line 5");
@@ -439,7 +458,7 @@ describe("cel end-to-end", () => {
439458 }
440459
441460 // Row 0 should show item 3 (offset=2), row 2 should show item 5
442- const buf = cel._getBuffer()!;
461+ const buf = currentBuffer();
443462 let row0 = "";
444463 for (let x = 0; x < 6; x++) row0 += buf.get(x, 0).char;
445464 expect(row0).toBe("item 3");
@@ -755,14 +774,14 @@ describe("cel end-to-end", () => {
755774 width: 20,
756775 height: 5,
757776 onKeyPress: (key) => {
758- received.push("root:" + key);
777+ received.push(`root:${key}`);
759778 },
760779 },
761780 [
762781 VStack(
763782 {
764783 onKeyPress: (key) => {
765- received.push("mid:" + key);
784+ received.push(`mid:${key}`);
766785 // void return = consumed
767786 },
768787 },
@@ -798,14 +817,14 @@ describe("cel end-to-end", () => {
798817 width: 20,
799818 height: 5,
800819 onKeyPress: (key) => {
801- received.push("root:" + key);
820+ received.push(`root:${key}`);
802821 },
803822 },
804823 [
805824 VStack(
806825 {
807826 onKeyPress: (key) => {
808- received.push("mid:" + key);
827+ received.push(`mid:${key}`);
809828 return false; // not consumed — keep bubbling
810829 },
811830 },
@@ -841,14 +860,14 @@ describe("cel end-to-end", () => {
841860 width: 20,
842861 height: 5,
843862 onKeyPress: (key) => {
844- received.push("root:" + key);
863+ received.push(`root:${key}`);
845864 },
846865 },
847866 [
848867 VStack(
849868 {
850869 onKeyPress: (key) => {
851- received.push("mid:" + key);
870+ received.push(`mid:${key}`);
852871 // Consume "a" but pass through everything else
853872 if (key === "a") return; // consumed
854873 return false; // not consumed
@@ -889,7 +908,7 @@ describe("cel end-to-end", () => {
889908 width: 20,
890909 height: 5,
891910 onKeyPress: (key) => {
892- received.push("root:" + key);
911+ received.push(`root:${key}`);
893912 return false;
894913 },
895914 },
@@ -897,7 +916,7 @@ describe("cel end-to-end", () => {
897916 VStack(
898917 {
899918 onKeyPress: (key) => {
900- received.push("mid:" + key);
919+ received.push(`mid:${key}`);
901920 return false;
902921 },
903922 },
@@ -1353,7 +1372,7 @@ describe("cel end-to-end", () => {
13531372 await waitForRender();
13541373
13551374 // Initially line1 should be visible
1356- const buf1 = cel._getBuffer()!;
1375+ const buf1 = currentBuffer();
13571376 let row0 = "";
13581377 for (let x = 0; x < 5; x++) row0 += buf1.get(x, 0).char;
13591378 expect(row0).toBe("line1");
@@ -1362,7 +1381,7 @@ describe("cel end-to-end", () => {
13621381 term.sendInput("\x1b[<65;6;2M");
13631382 await waitForRender();
13641383
1365- const buf2 = cel._getBuffer()!;
1384+ const buf2 = currentBuffer();
13661385 let row0After = "";
13671386 for (let x = 0; x < 5; x++) row0After += buf2.get(x, 0).char;
13681387 expect(row0After).toBe("line5");
@@ -1391,7 +1410,7 @@ describe("cel end-to-end", () => {
13911410 await waitForRender();
13921411
13931412 // line1 should still be at row 0
1394- const buf = cel._getBuffer()!;
1413+ const buf = currentBuffer();
13951414 let row0 = "";
13961415 for (let x = 0; x < 5; x++) row0 += buf.get(x, 0).char;
13971416 expect(row0).toBe("line1");
@@ -1436,7 +1455,7 @@ describe("cel end-to-end", () => {
14361455 expect(outerScrolled).toBe(false);
14371456
14381457 // Verify TextInput scrolled by the adaptive step (4)
1439- const buf = cel._getBuffer()!;
1458+ const buf = currentBuffer();
14401459 let row0 = "";
14411460 for (let x = 0; x < 5; x++) row0 += buf.get(x, 0).char;
14421461 expect(row0).toBe("line5");
@@ -1852,7 +1871,7 @@ describe("cel end-to-end", () => {
18521871 await waitForRender();
18531872
18541873 // Before focus — normal bgColor
1855- let buf = cel._getBuffer()!;
1874+ let buf = currentBuffer();
18561875 expect(buf.get(0, 0).bgColor).toBe("color00");
18571876
18581877 // Tab to focus
@@ -1860,7 +1879,7 @@ describe("cel end-to-end", () => {
18601879 await waitForRender();
18611880
18621881 // After focus — focusStyle bgColor
1863- buf = cel._getBuffer()!;
1882+ buf = currentBuffer();
18641883 expect(buf.get(0, 0).bgColor).toBe("color06");
18651884 });
18661885
@@ -1892,14 +1911,14 @@ describe("cel end-to-end", () => {
18921911 // Tab to first
18931912 term.sendInput(TAB);
18941913 await waitForRender();
1895- let buf = cel._getBuffer()!;
1914+ let buf = currentBuffer();
18961915 expect(buf.get(0, 0).bgColor).toBe("color06");
18971916 expect(buf.get(0, 1).bgColor).toBe("color00");
18981917
18991918 // Tab to second — first loses focusStyle, second gains it
19001919 term.sendInput(TAB);
19011920 await waitForRender();
1902- buf = cel._getBuffer()!;
1921+ buf = currentBuffer();
19031922 expect(buf.get(0, 0).bgColor).toBe("color00");
19041923 expect(buf.get(0, 1).bgColor).toBe("color03");
19051924 });
@@ -1922,7 +1941,7 @@ describe("cel end-to-end", () => {
19221941 await waitForRender();
19231942
19241943 // Before focus — Text inherits white
1925- let buf = cel._getBuffer()!;
1944+ let buf = currentBuffer();
19261945 expect(buf.get(0, 0).fgColor).toBe("color07");
19271946
19281947 // Tab to focus
@@ -1930,7 +1949,7 @@ describe("cel end-to-end", () => {
19301949 await waitForRender();
19311950
19321951 // After focus — Text inherits black from focusStyle
1933- buf = cel._getBuffer()!;
1952+ buf = currentBuffer();
19341953 expect(buf.get(0, 0).fgColor).toBe("color00");
19351954 });
19361955
@@ -1957,7 +1976,7 @@ describe("cel end-to-end", () => {
19571976 await waitForRender();
19581977
19591978 // Controlled focused=true — focusStyle applies
1960- let buf = cel._getBuffer()!;
1979+ let buf = currentBuffer();
19611980 expect(buf.get(0, 0).bgColor).toBe("color06");
19621981
19631982 // Escape to blur
@@ -1965,7 +1984,7 @@ describe("cel end-to-end", () => {
19651984 await waitForRender();
19661985
19671986 // focused=false — normal style
1968- buf = cel._getBuffer()!;
1987+ buf = currentBuffer();
19691988 expect(buf.get(0, 0).bgColor).toBe("color00");
19701989 });
19711990 });
packages/core/src/cel.ts+90−47
@@ -5,36 +5,36 @@ import type {
55 Theme,
66 } from "@cel-tui/types";
77 import { CellBuffer } from "./cell-buffer.js";
8-import { emitBuffer, emitDiff, defaultTheme } from "./emitter.js";
8+import { defaultTheme, emitBuffer, emitDiff } from "./emitter.js";
99 import {
10- hitTest,
10+ collectFocusable,
11+ collectKeyPressHandlers,
1112 findClickHandler,
1213 findScrollTarget,
13- collectKeyPressHandlers,
14- collectFocusable,
14+ hitTest,
1515 } from "./hit-test.js";
1616 import { decodeKeyEvents, isEditingKey, type KeyInput } from "./keys.js";
17-import { layout, type LayoutNode } from "./layout.js";
17+import { type LayoutNode, layout } from "./layout.js";
1818 import {
19- paint,
2019 getTextInputCursor,
21- setTextInputCursor,
20+ getTextInputCursorScreenPos,
2221 getTextInputScroll,
22+ paint,
23+ setTextInputCursor,
2324 setTextInputScroll,
24- getTextInputCursorScreenPos,
2525 } from "./paint.js";
26+import { getMaxScrollOffset, getScrollStep } from "./scroll.js";
27+import type { Terminal } from "./terminal.js";
2628 import {
27- insertChar,
2829 deleteBackward,
2930 deleteForward,
3031 deleteWordBackward,
3132 deleteWordForward,
33+ type EditState,
34+ insertChar,
3235 moveCursor,
Cut short: this commit's diff is over 1000 lines.
packages/core/src/cell-buffer.test.ts+1−1
Cut short: this commit's diff is over 1000 lines.
packages/core/src/cell-buffer.ts+7−2
Cut short: this commit's diff is over 1000 lines.
packages/core/src/composite.test.ts+16−7
Cut short: this commit's diff is over 1000 lines.
packages/core/src/emitter.test.ts+2−1
Cut short: this commit's diff is over 1000 lines.
packages/core/src/emitter.ts+1−2
Cut short: this commit's diff is over 1000 lines.
packages/core/src/hit-test.test.ts+57−28
Cut short: this commit's diff is over 1000 lines.
packages/core/src/hit-test.ts+30−15
Cut short: this commit's diff is over 1000 lines.
packages/core/src/index.ts+15−16
Cut short: this commit's diff is over 1000 lines.
packages/core/src/keys.test.ts+1−1
Cut short: this commit's diff is over 1000 lines.
packages/core/src/keys.ts+29−9
Cut short: this commit's diff is over 1000 lines.
packages/core/src/layout.test.ts+135−126
Cut short: this commit's diff is over 1000 lines.
packages/core/src/layout.ts+70−32
Cut short: this commit's diff is over 1000 lines.
packages/core/src/paint.test.ts+2−11
Cut short: this commit's diff is over 1000 lines.
packages/core/src/paint.ts+11−8
Cut short: this commit's diff is over 1000 lines.
packages/core/src/scroll.test.ts+11−2
Cut short: this commit's diff is over 1000 lines.
packages/core/src/scroll.ts+10−6
Cut short: this commit's diff is over 1000 lines.
packages/core/src/test-helpers.ts+25−6
Cut short: this commit's diff is over 1000 lines.
packages/core/src/text-edit.test.ts+8−8
Cut short: this commit's diff is over 1000 lines.
packages/core/src/text-input.test.ts+14−5
Cut short: this commit's diff is over 1000 lines.
packages/core/src/text-layout.ts+32−9
Cut short: this commit's diff is over 1000 lines.
packages/core/src/width.ts+9−4
Cut short: this commit's diff is over 1000 lines.
packages/types/src/index.ts+5−2
Cut short: this commit's diff is over 1000 lines.