@alchemy.run/sigil 0.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,3192 @@
1
+ [![](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)
2
+
3
+ ---
4
+
5
+ <div align="center">
6
+ <br>
7
+ <h1>Sigil</h1>
8
+ <br>
9
+ </div>
10
+
11
+ > React for CLIs. Build and test your CLI output using components.
12
+
13
+ **Sigil is a fork of [Ink](https://github.com/vadimdemedes/ink)** by [Vadym Demedes](https://github.com/vadimdemedes), maintained by [Functionless Corp.](https://alchemy.run) and published as [`@alchemy.run/sigil`](https://npmjs.com/package/@alchemy.run/sigil). It differs from upstream Ink in a few deliberate ways:
14
+
15
+ - **Self-contained**: the only runtime dependencies are `react-reconciler` and `scheduler`. Everything else — the ANSI/terminal subsystem (`src/ansi/`), styling, width measurement, wrapping — is first-class TypeScript in this repository.
16
+ - **Integrated layout engine**: layout is computed by a TypeScript port of [Yoga](https://github.com/facebook/yoga) (`src/yoga/`) instead of the Yoga WASM binary, continuously verified against an f64-patched reference Yoga build via differential fuzzing.
17
+ - **Modern toolchain**: built with [Vite+](https://viteplus.dev) (Vitest, Oxlint, Oxfmt, tsdown) and TypeScript 7.
18
+
19
+ Upstream Ink and Yoga are tracked as submodules in `.vendor/` — upstream's test suites run against this codebase as part of the regular test run. See `THIRD_PARTY_NOTICES.md` for attribution.
20
+
21
+ The documentation below is inherited from Ink; the API is unchanged apart from imports
22
+
23
+ ---
24
+
25
+ Ink provides the same component-based UI building experience that React offers in the browser, but for command-line apps.
26
+ It uses [Yoga](https://github.com/facebook/yoga) to build Flexbox layouts in the terminal, so most CSS-like properties are available in Ink as well.
27
+ If you are already familiar with React, you already know Ink.
28
+
29
+ Since Ink is a React renderer, all features of React are supported.
30
+ Head over to the [React](https://reactjs.org) website for documentation on how to use it.
31
+ Only Ink's methods are documented in this readme.
32
+
33
+ **Fully AI-generated pull requests are not accepted. You can use AI, but should be verified and cleaned up by a human. Only Opus 4.6+ (high-effort) and Codex 5.4+ (extra high) are accepted models. Preferably created with Opus and verified by Codex.**
34
+
35
+ ---
36
+
37
+ <div align="center">
38
+ <p>
39
+ <p>
40
+ <sup>
41
+ <a href="https://opencollective.com/vadimdemedes">Vadym Demedes' open source work is supported by the community ❤️</a>
42
+ </sup>
43
+ </p>
44
+ </p>
45
+ </div>
46
+
47
+ ## Install
48
+
49
+ ```sh
50
+ pnpm add @alchemy.run/sigil react
51
+ ```
52
+
53
+ > [!NOTE]
54
+ > This readme documents the upcoming version of Ink. For the latest stable release, see [Ink on npm](https://www.npmjs.com/package/ink).
55
+
56
+ ## Usage
57
+
58
+ ```jsx
59
+ import React, { useState, useEffect } from "react";
60
+ import { render, Text } from "@alchemy.run/sigil";
61
+
62
+ const Counter = () => {
63
+ const [counter, setCounter] = useState(0);
64
+
65
+ useEffect(() => {
66
+ const timer = setInterval(() => {
67
+ setCounter((previousCounter) => previousCounter + 1);
68
+ }, 100);
69
+
70
+ return () => {
71
+ clearInterval(timer);
72
+ };
73
+ }, []);
74
+
75
+ return <Text color="green">{counter} tests passed</Text>;
76
+ };
77
+
78
+ render(<Counter />);
79
+ ```
80
+
81
+ <img src="media/demo.svg" width="600">
82
+
83
+ ## Who's Using Ink?
84
+
85
+ - [Claude Code](https://github.com/anthropics/claude-code) - An agentic coding tool made by Anthropic.
86
+ - [Gemini CLI](https://github.com/google-gemini/gemini-cli) - An agentic coding tool made by Google.
87
+ - [GitHub Copilot CLI](https://github.com/features/copilot/cli) - Just say what you want the shell to do.
88
+ - [Canva CLI](https://www.canva.dev/docs/apps/canva-cli/) - CLI for creating and managing Canva Apps.
89
+ - [Cloudflare's Wrangler](https://github.com/cloudflare/wrangler2) - The CLI for Cloudflare Workers.
90
+ - [Linear](https://linear.app) - Linear built an internal CLI for managing deployments, configs, and other housekeeping tasks.
91
+ - [Gatsby](https://www.gatsbyjs.org) - Gatsby is a modern web framework for blazing-fast websites.
92
+ - [tap](https://node-tap.org) - A Test-Anything-Protocol library for JavaScript.
93
+ - [Terraform CDK](https://github.com/hashicorp/terraform-cdk) - Cloud Development Kit (CDK) for HashiCorp Terraform.
94
+ - [Specify CLI](https://specifyapp.com) - Automate the distribution of your design tokens.
95
+ - [Twilio's SIGNAL](https://github.com/twilio-labs/plugin-signal2020) - CLI for Twilio's SIGNAL conference. [Blog post](https://www.twilio.com/blog/building-conference-cli-in-react).
96
+ - [Typewriter](https://github.com/segmentio/typewriter) - Generates strongly-typed [Segment](https://segment.com) analytics clients from arbitrary JSON Schema.
97
+ - [Prisma](https://www.prisma.io) - The unified data layer for modern applications.
98
+ - [Blitz](https://blitzjs.com) - The Fullstack React Framework.
99
+ - [New York Times](https://github.com/nytimes/kyt) - NYT uses Ink's `kyt` - a toolkit that encapsulates and manages the configuration for web apps.
100
+ - [tink](https://github.com/npm/tink) - A next-generation runtime and package manager.
101
+ - [Inkle](https://github.com/jrr/inkle) - A Wordle game.
102
+ - [loki](https://github.com/oblador/loki) - Visual regression testing tool for Storybook.
103
+ - [Bit](https://github.com/teambit/bit) - Build, distribute, and collaborate on components.
104
+ - [Remirror](https://github.com/remirror/remirror) - Your friendly, world-class editor toolkit.
105
+ - [Prime](https://github.com/birkir/prime) - Open-source GraphQL CMS.
106
+ - [emoj](https://github.com/sindresorhus/emoj) - Find relevant emojis.
107
+ - [emma](https://github.com/maticzav/emma-cli) - Find and install npm packages easily.
108
+ - [npm-check-extras](https://github.com/akgondber/npm-check-extras) - Check for outdated and unused dependencies, and run update/delete actions on selected ones.
109
+ - [swiff](https://github.com/simple-integrated-marketing/swiff) - Multi-environment command-line tools for time-saving web developers.
110
+ - [share](https://github.com/marionebl/share-cli) - Share files quickly.
111
+ - [Kubelive](https://github.com/ameerthehacker/kubelive) - A CLI for Kubernetes that provides live data about the cluster and its resources.
112
+ - [changelog-view](https://github.com/jdeniau/changelog-view) - View changelogs.
113
+ - [cfpush](https://github.com/mamachanko/cfpush) - Interactive Cloud Foundry tutorial.
114
+ - [startd](https://github.com/mgrip/startd) - Turn your React component into a web app.
115
+ - [wiki-cli](https://github.com/hexrcs/wiki-cli) - Search Wikipedia and read article summaries.
116
+ - [garson](https://github.com/goliney/garson) - Build interactive, config-based command-line interfaces.
117
+ - [git-contrib-calendar](https://github.com/giannisp/git-contrib-calendar) - Display a contributions calendar for any Git repository.
118
+ - [gitgud](https://github.com/GitGud-org/GitGud) - Interactive command-line GUI for Git.
119
+ - [Autarky](https://github.com/pranshuchittora/autarky) - Find and delete old `node_modules` directories to free up disk space.
120
+ - [fast-cli](https://github.com/sindresorhus/fast-cli) - Test your download and upload speeds.
121
+ - [tasuku](https://github.com/privatenumber/tasuku) - Minimal task runner.
122
+ - [mnswpr](https://github.com/mordv/mnswpr) - A Minesweeper game.
123
+ - [lrn](https://github.com/krychu/lrn) - Learning by repetition.
124
+ - [turdle](https://github.com/mynameisankit/turdle) - A Wordle game.
125
+ - [Shopify CLI](https://github.com/Shopify/cli) - Build apps, themes, and storefronts for the Shopify platform.
126
+ - [ToDesktop CLI](https://www.todesktop.com/electron) - All-in-one platform for building Electron apps.
127
+ - [Walle](https://github.com/Pobepto/walle) - A full-featured crypto wallet for EVM networks.
128
+ - [Sudoku](https://github.com/mrozio13pl/sudoku-in-terminal) - A Sudoku game.
129
+ - [Sea Trader](https://github.com/zyishai/sea-trader) - A Taipan!-inspired trading simulator game.
130
+ - [srtd](https://github.com/t1mmen/srtd) - Live-reloading SQL templates for Supabase projects.
131
+ - [tweakcc](https://github.com/Piebald-AI/tweakcc) - Customize your Claude Code styling.
132
+ - [argonaut](https://github.com/darksworm/argonaut) - Manage Argo CD resources.
133
+ - [Qodo Command](https://github.com/qodo-ai/command) - Build, run, and manage AI agents.
134
+ - [Nanocoder](https://github.com/nano-collective/nanocoder) - A community-built, local-first AI coding agent with multi-provider support.
135
+ - [dev3000](https://github.com/vercel-labs/dev3000) - An AI agent MCP orchestrator and developer browser.
136
+ - [Neovate Code](https://github.com/neovateai/neovate-code) - An agentic coding tool made by AntGroup.
137
+ - [instagram-cli](https://github.com/supreme-gg-gg/instagram-cli) - Instagram client.
138
+ - [ElevenLabs CLI](https://github.com/elevenlabs/cli) - ElevenLabs agents client.
139
+ - [SSH AI Chat](https://github.com/miantiao-me/ssh-ai-chat) - Chat with AI over SSH.
140
+ - [Deep Code CLI](https://github.com/lessweb/deepcode-cli) - AI coding assistant optimized for the DeepSeek model.
141
+
142
+ _(PRs welcome. Append new entries at the end. Repos must have 100+ stars and showcase Ink beyond a basic list picker.)_
143
+
144
+ ## Contents
145
+
146
+ - [Getting Started](#getting-started)
147
+ - [App Lifecycle](#app-lifecycle)
148
+ - [Components](#components)
149
+ - [`<Text>`](#text)
150
+ - [`<Box>`](#box)
151
+ - [`<Newline>`](#newline)
152
+ - [`<Spacer>`](#spacer)
153
+ - [`<Static>`](#static)
154
+ - [`<Transform>`](#transform)
155
+ - [Hooks](#hooks)
156
+ - [`useInput`](#useinputinputhandler-options)
157
+ - [`usePaste`](#usepastehandler-options)
158
+ - [`useApp`](#useapp)
159
+ - [`useStdin`](#usestdin)
160
+ - [`useStdout`](#usestdout)
161
+ - [`useBoxMetrics`](#useboxmetricsref)
162
+ - [`useStderr`](#usestderr)
163
+ - [`useWindowSize`](#usewindowsize)
164
+ - [`useFocus`](#usefocusoptions)
165
+ - [`useFocusManager`](#usefocusmanager)
166
+ - [`useCursor`](#usecursor)
167
+ - [`useAnimation`](#useanimationoptions)
168
+ - [API](#api)
169
+ - [Testing](#testing)
170
+ - [Using React Devtools](#using-react-devtools)
171
+ - [Screen Reader Support](#screen-reader-support)
172
+ - [Useful Components](#useful-components)
173
+ - [Useful Hooks](#useful-hooks)
174
+ - [Recipes](#recipes)
175
+ - [Examples](#examples)
176
+ - [Continuous Integration](#continuous-integration)
177
+
178
+ ## Getting Started
179
+
180
+ Use [create-ink-app](https://github.com/vadimdemedes/create-ink-app) to quickly scaffold a new Ink-based CLI.
181
+
182
+ ```sh
183
+ npx create-ink-app my-ink-cli
184
+ ```
185
+
186
+ Alternatively, create a TypeScript project:
187
+
188
+ ```sh
189
+ npx create-ink-app --typescript my-ink-cli
190
+ ```
191
+
192
+ <details><summary>Manual JavaScript setup</summary>
193
+ <p>
194
+ Ink requires the same Babel setup as you would do for regular React-based apps in the browser.
195
+
196
+ Set up Babel with a React preset to ensure all examples in this readme work as expected.
197
+ After [installing Babel](https://babeljs.io/docs/en/usage), install `@babel/preset-react` and insert the following configuration in `babel.config.json`:
198
+
199
+ ```sh
200
+ npm install --save-dev @babel/preset-react
201
+ ```
202
+
203
+ ```json
204
+ {
205
+ "presets": ["@babel/preset-react"]
206
+ }
207
+ ```
208
+
209
+ Next, create a file `source.js`, where you'll type code that uses Ink:
210
+
211
+ ```jsx
212
+ import React from "react";
213
+ import { render, Text } from "@alchemy.run/sigil";
214
+
215
+ const Demo = () => <Text>Hello World</Text>;
216
+
217
+ render(<Demo />);
218
+ ```
219
+
220
+ Then, transpile this file with Babel:
221
+
222
+ ```sh
223
+ npx babel source.js -o cli.js
224
+ ```
225
+
226
+ Now you can run `cli.js` with Node.js:
227
+
228
+ ```sh
229
+ node cli
230
+ ```
231
+
232
+ If you don't like transpiling files during development, you can use [import-jsx](https://github.com/vadimdemedes/import-jsx) or [@esbuild-kit/esm-loader](https://github.com/esbuild-kit/esm-loader) to `import` a JSX file and transpile it on the fly.
233
+
234
+ </p>
235
+ </details>
236
+
237
+ Ink uses [Yoga](https://github.com/facebook/yoga), a Flexbox layout engine, to build great user interfaces for your CLIs using familiar CSS-like properties you've used when building apps for the browser.
238
+ It's important to remember that each element is a Flexbox container.
239
+ Think of it as if every `<div>` in the browser had `display: flex`.
240
+ See [`<Box>`](#box) built-in component below for documentation on how to use Flexbox layouts in Ink.
241
+ Note that all text must be wrapped in a [`<Text>`](#text) component.
242
+
243
+ ## App Lifecycle
244
+
245
+ An Ink app is a Node.js process, so it stays alive only while there is active work in the event loop (timers, pending promises, [`useInput`](#useinputinputhandler-options) listening on `stdin`, etc.). If your component tree has no async work, the app will render once and exit immediately.
246
+
247
+ To exit the app, press **Ctrl+C** (enabled by default via [`exitOnCtrlC`](#exitonctrlc)), call [`exit()`](#exiterrororresult) from [`useApp`](#useapp) inside a component, or call [`unmount()`](#unmount) on the object returned by [`render()`](#rendertree-options).
248
+
249
+ Use [`waitUntilExit()`](#waituntilexit) to run code after the app is unmounted:
250
+
251
+ ```jsx
252
+ const { waitUntilExit } = render(<MyApp />);
253
+
254
+ await waitUntilExit();
255
+
256
+ console.log("App exited");
257
+ ```
258
+
259
+ ## Components
260
+
261
+ ### `<Text>`
262
+
263
+ This component can display text and change its style to make it bold, underlined, italic, or strikethrough.
264
+
265
+ ```jsx
266
+ import { render, Text } from "@alchemy.run/sigil";
267
+
268
+ const Example = () => (
269
+ <>
270
+ <Text color="green">I am green</Text>
271
+ <Text color="black" backgroundColor="white">
272
+ I am black on white
273
+ </Text>
274
+ <Text color="#ffffff">I am white</Text>
275
+ <Text bold>I am bold</Text>
276
+ <Text italic>I am italic</Text>
277
+ <Text underline>I am underline</Text>
278
+ <Text strikethrough>I am strikethrough</Text>
279
+ <Text inverse>I am inversed</Text>
280
+ </>
281
+ );
282
+
283
+ render(<Example />);
284
+ ```
285
+
286
+ > [!NOTE]
287
+ > `<Text>` allows only text nodes and nested `<Text>` components inside of it. For example, `<Box>` component can't be used inside `<Text>`.
288
+
289
+ #### color
290
+
291
+ Type: `string`
292
+
293
+ Change text color.
294
+ Ink uses [chalk](https://github.com/chalk/chalk) under the hood, so all its functionality is supported.
295
+
296
+ ```jsx
297
+ <Text color="green">Green</Text>
298
+ <Text color="#005cc5">Blue</Text>
299
+ <Text color="rgb(232, 131, 136)">Red</Text>
300
+ ```
301
+
302
+ <img src="media/text-color.jpg" width="247">
303
+
304
+ #### backgroundColor
305
+
306
+ Type: `string`
307
+
308
+ Same as `color` above, but for background.
309
+
310
+ ```jsx
311
+ <Text backgroundColor="green" color="white">Green</Text>
312
+ <Text backgroundColor="#005cc5" color="white">Blue</Text>
313
+ <Text backgroundColor="rgb(232, 131, 136)" color="white">Red</Text>
314
+ ```
315
+
316
+ <img src="media/text-backgroundColor.jpg" width="226">
317
+
318
+ #### dimColor
319
+
320
+ Type: `boolean`\
321
+ Default: `false`
322
+
323
+ Dim the color (make it less bright).
324
+
325
+ ```jsx
326
+ <Text color="red" dimColor>
327
+ Dimmed Red
328
+ </Text>
329
+ ```
330
+
331
+ <img src="media/text-dimColor.jpg" width="138">
332
+
333
+ #### bold
334
+
335
+ Type: `boolean`\
336
+ Default: `false`
337
+
338
+ Make the text bold.
339
+
340
+ #### italic
341
+
342
+ Type: `boolean`\
343
+ Default: `false`
344
+
345
+ Make the text italic.
346
+
347
+ #### underline
348
+
349
+ Type: `boolean`\
350
+ Default: `false`
351
+
352
+ Make the text underlined.
353
+
354
+ #### strikethrough
355
+
356
+ Type: `boolean`\
357
+ Default: `false`
358
+
359
+ Make the text crossed with a line.
360
+
361
+ #### inverse
362
+
363
+ Type: `boolean`\
364
+ Default: `false`
365
+
366
+ Invert background and foreground colors.
367
+
368
+ ```jsx
369
+ <Text inverse color="yellow">
370
+ Inversed Yellow
371
+ </Text>
372
+ ```
373
+
374
+ <img src="media/text-inverse.jpg" width="138">
375
+
376
+ #### wrap
377
+
378
+ Type: `string`\
379
+ Allowed values: `wrap` `hard` `truncate` `truncate-start` `truncate-middle` `truncate-end`\
380
+ Default: `wrap`
381
+
382
+ This property tells Ink to wrap or truncate text if its width is larger than the container.
383
+ If `wrap` is passed (the default), Ink will wrap text and split it into multiple lines.
384
+ If `hard` is passed, Ink will fill each line to the full column width, breaking words as necessary.
385
+ If `truncate-*` is passed, Ink will truncate text instead, resulting in one line of text with the rest cut off.
386
+
387
+ ```jsx
388
+ <Box width={7}>
389
+ <Text>Hello World</Text>
390
+ </Box>
391
+ //=> 'Hello\nWorld'
392
+
393
+ <Box width={7}>
394
+ <Text wrap="hard">Hello World</Text>
395
+ </Box>
396
+ //=> 'Hello W\norld'
397
+
398
+ // `truncate` is an alias to `truncate-end`
399
+ <Box width={7}>
400
+ <Text wrap="truncate">Hello World</Text>
401
+ </Box>
402
+ //=> 'Hello…'
403
+
404
+ <Box width={7}>
405
+ <Text wrap="truncate-middle">Hello World</Text>
406
+ </Box>
407
+ //=> 'He…ld'
408
+
409
+ <Box width={7}>
410
+ <Text wrap="truncate-start">Hello World</Text>
411
+ </Box>
412
+ //=> '…World'
413
+ ```
414
+
415
+ ### `<Box>`
416
+
417
+ `<Box>` is an essential Ink component to build your layout.
418
+ It's like `<div style="display: flex">` in the browser.
419
+
420
+ ```jsx
421
+ import { render, Box, Text } from "@alchemy.run/sigil";
422
+
423
+ const Example = () => (
424
+ <Box margin={2}>
425
+ <Text>This is a box with margin</Text>
426
+ </Box>
427
+ );
428
+
429
+ render(<Example />);
430
+ ```
431
+
432
+ #### Dimensions
433
+
434
+ ##### width
435
+
436
+ Type: `number` `string`
437
+
438
+ Width of the element in spaces.
439
+ You can also set it as a percentage, which will calculate the width based on the width of the parent element.
440
+
441
+ ```jsx
442
+ <Box width={4}>
443
+ <Text>X</Text>
444
+ </Box>
445
+ //=> 'X '
446
+ ```
447
+
448
+ ```jsx
449
+ <Box width={10}>
450
+ <Box width="50%">
451
+ <Text>X</Text>
452
+ </Box>
453
+ <Text>Y</Text>
454
+ </Box>
455
+ //=> 'X Y'
456
+ ```
457
+
458
+ ##### height
459
+
460
+ Type: `number` `string`
461
+
462
+ Height of the element in lines (rows).
463
+ You can also set it as a percentage, which will calculate the height based on the height of the parent element.
464
+
465
+ ```jsx
466
+ <Box height={4}>
467
+ <Text>X</Text>
468
+ </Box>
469
+ //=> 'X\n\n\n'
470
+ ```
471
+
472
+ ```jsx
473
+ <Box height={6} flexDirection="column">
474
+ <Box height="50%">
475
+ <Text>X</Text>
476
+ </Box>
477
+ <Text>Y</Text>
478
+ </Box>
479
+ //=> 'X\n\n\nY\n\n'
480
+ ```
481
+
482
+ ##### minWidth
483
+
484
+ Type: `number`
485
+
486
+ Sets a minimum width of the element.
487
+ Percentages aren't supported yet; see https://github.com/facebook/yoga/issues/872.
488
+
489
+ ##### minHeight
490
+
491
+ Type: `number` `string`
492
+
493
+ Sets a minimum height of the element in lines (rows).
494
+ You can also set it as a percentage, which will calculate the minimum height based on the height of the parent element.
495
+
496
+ ##### maxWidth
497
+
498
+ Type: `number`
499
+
500
+ Sets a maximum width of the element.
501
+ Percentages aren't supported yet; see https://github.com/facebook/yoga/issues/872.
502
+
503
+ ##### maxHeight
504
+
505
+ Type: `number` `string`
506
+
507
+ Sets a maximum height of the element in lines (rows).
508
+ You can also set it as a percentage, which will calculate the maximum height based on the height of the parent element.
509
+
510
+ ##### aspectRatio
511
+
512
+ Type: `number`
513
+
514
+ Defines the aspect ratio (width/height) for the element.
515
+
516
+ Use it with at least one size constraint (`width`, `height`, `minHeight`, or `maxHeight`) so Ink can derive the missing dimension.
517
+
518
+ #### Padding
519
+
520
+ ##### paddingTop
521
+
522
+ Type: `number`\
523
+ Default: `0`
524
+
525
+ Top padding.
526
+
527
+ ##### paddingBottom
528
+
529
+ Type: `number`\
530
+ Default: `0`
531
+
532
+ Bottom padding.
533
+
534
+ ##### paddingLeft
535
+
536
+ Type: `number`\
537
+ Default: `0`
538
+
539
+ Left padding.
540
+
541
+ ##### paddingRight
542
+
543
+ Type: `number`\
544
+ Default: `0`
545
+
546
+ Right padding.
547
+
548
+ ##### paddingX
549
+
550
+ Type: `number`\
551
+ Default: `0`
552
+
553
+ Horizontal padding. Equivalent to setting `paddingLeft` and `paddingRight`.
554
+
555
+ ##### paddingY
556
+
557
+ Type: `number`\
558
+ Default: `0`
559
+
560
+ Vertical padding. Equivalent to setting `paddingTop` and `paddingBottom`.
561
+
562
+ ##### padding
563
+
564
+ Type: `number`\
565
+ Default: `0`
566
+
567
+ Padding on all sides. Equivalent to setting `paddingTop`, `paddingBottom`, `paddingLeft` and `paddingRight`.
568
+
569
+ ```jsx
570
+ <Box paddingTop={2}><Text>Top</Text></Box>
571
+ <Box paddingBottom={2}><Text>Bottom</Text></Box>
572
+ <Box paddingLeft={2}><Text>Left</Text></Box>
573
+ <Box paddingRight={2}><Text>Right</Text></Box>
574
+ <Box paddingX={2}><Text>Left and right</Text></Box>
575
+ <Box paddingY={2}><Text>Top and bottom</Text></Box>
576
+ <Box padding={2}><Text>Top, bottom, left and right</Text></Box>
577
+ ```
578
+
579
+ #### Margin
580
+
581
+ ##### marginTop
582
+
583
+ Type: `number`\
584
+ Default: `0`
585
+
586
+ Top margin.
587
+
588
+ ##### marginBottom
589
+
590
+ Type: `number`\
591
+ Default: `0`
592
+
593
+ Bottom margin.
594
+
595
+ ##### marginLeft
596
+
597
+ Type: `number`\
598
+ Default: `0`
599
+
600
+ Left margin.
601
+
602
+ ##### marginRight
603
+
604
+ Type: `number`\
605
+ Default: `0`
606
+
607
+ Right margin.
608
+
609
+ ##### marginX
610
+
611
+ Type: `number`\
612
+ Default: `0`
613
+
614
+ Horizontal margin. Equivalent to setting `marginLeft` and `marginRight`.
615
+
616
+ ##### marginY
617
+
618
+ Type: `number`\
619
+ Default: `0`
620
+
621
+ Vertical margin. Equivalent to setting `marginTop` and `marginBottom`.
622
+
623
+ ##### margin
624
+
625
+ Type: `number`\
626
+ Default: `0`
627
+
628
+ Margin on all sides. Equivalent to setting `marginTop`, `marginBottom`, `marginLeft` and `marginRight`.
629
+
630
+ ```jsx
631
+ <Box marginTop={2}><Text>Top</Text></Box>
632
+ <Box marginBottom={2}><Text>Bottom</Text></Box>
633
+ <Box marginLeft={2}><Text>Left</Text></Box>
634
+ <Box marginRight={2}><Text>Right</Text></Box>
635
+ <Box marginX={2}><Text>Left and right</Text></Box>
636
+ <Box marginY={2}><Text>Top and bottom</Text></Box>
637
+ <Box margin={2}><Text>Top, bottom, left and right</Text></Box>
638
+ ```
639
+
640
+ #### Gap
641
+
642
+ #### gap
643
+
644
+ Type: `number`\
645
+ Default: `0`
646
+
647
+ Size of the gap between an element's columns and rows. A shorthand for `columnGap` and `rowGap`.
648
+
649
+ ```jsx
650
+ <Box gap={1} width={3} flexWrap="wrap">
651
+ <Text>A</Text>
652
+ <Text>B</Text>
653
+ <Text>C</Text>
654
+ </Box>
655
+ // A B
656
+ //
657
+ // C
658
+ ```
659
+
660
+ #### columnGap
661
+
662
+ Type: `number`\
663
+ Default: `0`
664
+
665
+ Size of the gap between an element's columns.
666
+
667
+ ```jsx
668
+ <Box columnGap={1}>
669
+ <Text>A</Text>
670
+ <Text>B</Text>
671
+ </Box>
672
+ // A B
673
+ ```
674
+
675
+ #### rowGap
676
+
677
+ Type: `number`\
678
+ Default: `0`
679
+
680
+ Size of the gap between an element's rows.
681
+
682
+ ```jsx
683
+ <Box flexDirection="column" rowGap={1}>
684
+ <Text>A</Text>
685
+ <Text>B</Text>
686
+ </Box>
687
+ // A
688
+ //
689
+ // B
690
+ ```
691
+
692
+ #### Flex
693
+
694
+ ##### flexGrow
695
+
696
+ Type: `number`\
697
+ Default: `0`
698
+
699
+ See [flex-grow](https://css-tricks.com/almanac/properties/f/flex-grow/).
700
+
701
+ ```jsx
702
+ <Box>
703
+ <Text>Label:</Text>
704
+ <Box flexGrow={1}>
705
+ <Text>Fills all remaining space</Text>
706
+ </Box>
707
+ </Box>
708
+ ```
709
+
710
+ ##### flexShrink
711
+
712
+ Type: `number`\
713
+ Default: `1`
714
+
715
+ See [flex-shrink](https://css-tricks.com/almanac/properties/f/flex-shrink/).
716
+
717
+ ```jsx
718
+ <Box width={20}>
719
+ <Box flexShrink={2} width={10}>
720
+ <Text>Will be 1/4</Text>
721
+ </Box>
722
+ <Box width={10}>
723
+ <Text>Will be 3/4</Text>
724
+ </Box>
725
+ </Box>
726
+ ```
727
+
728
+ ##### flexBasis
729
+
730
+ Type: `number` `string`
731
+
732
+ See [flex-basis](https://css-tricks.com/almanac/properties/f/flex-basis/).
733
+
734
+ ```jsx
735
+ <Box width={6}>
736
+ <Box flexBasis={3}>
737
+ <Text>X</Text>
738
+ </Box>
739
+ <Text>Y</Text>
740
+ </Box>
741
+ //=> 'X Y'
742
+ ```
743
+
744
+ ```jsx
745
+ <Box width={6}>
746
+ <Box flexBasis="50%">
747
+ <Text>X</Text>
748
+ </Box>
749
+ <Text>Y</Text>
750
+ </Box>
751
+ //=> 'X Y'
752
+ ```
753
+
754
+ ##### flexDirection
755
+
756
+ Type: `string`\
757
+ Allowed values: `row` `row-reverse` `column` `column-reverse`
758
+
759
+ See [flex-direction](https://css-tricks.com/almanac/properties/f/flex-direction/).
760
+
761
+ ```jsx
762
+ <Box>
763
+ <Box marginRight={1}>
764
+ <Text>X</Text>
765
+ </Box>
766
+ <Text>Y</Text>
767
+ </Box>
768
+ // X Y
769
+
770
+ <Box flexDirection="row-reverse">
771
+ <Text>X</Text>
772
+ <Box marginRight={1}>
773
+ <Text>Y</Text>
774
+ </Box>
775
+ </Box>
776
+ // Y X
777
+
778
+ <Box flexDirection="column">
779
+ <Text>X</Text>
780
+ <Text>Y</Text>
781
+ </Box>
782
+ // X
783
+ // Y
784
+
785
+ <Box flexDirection="column-reverse">
786
+ <Text>X</Text>
787
+ <Text>Y</Text>
788
+ </Box>
789
+ // Y
790
+ // X
791
+ ```
792
+
793
+ ##### flexWrap
794
+
795
+ Type: `string`\
796
+ Allowed values: `nowrap` `wrap` `wrap-reverse`
797
+
798
+ See [flex-wrap](https://css-tricks.com/almanac/properties/f/flex-wrap/).
799
+
800
+ ```jsx
801
+ <Box width={2} flexWrap="wrap">
802
+ <Text>A</Text>
803
+ <Text>BC</Text>
804
+ </Box>
805
+ // A
806
+ // B C
807
+ ```
808
+
809
+ ```jsx
810
+ <Box flexDirection="column" height={2} flexWrap="wrap">
811
+ <Text>A</Text>
812
+ <Text>B</Text>
813
+ <Text>C</Text>
814
+ </Box>
815
+ // A C
816
+ // B
817
+ ```
818
+
819
+ ##### alignItems
820
+
821
+ Type: `string`\
822
+ Allowed values: `flex-start` `center` `flex-end` `stretch` `baseline`
823
+
824
+ See [align-items](https://css-tricks.com/almanac/properties/a/align-items/).
825
+
826
+ ```jsx
827
+ <Box alignItems="flex-start">
828
+ <Box marginRight={1}>
829
+ <Text>X</Text>
830
+ </Box>
831
+ <Text>
832
+ A
833
+ <Newline/>
834
+ B
835
+ <Newline/>
836
+ C
837
+ </Text>
838
+ </Box>
839
+ // X A
840
+ // B
841
+ // C
842
+
843
+ <Box alignItems="center">
844
+ <Box marginRight={1}>
845
+ <Text>X</Text>
846
+ </Box>
847
+ <Text>
848
+ A
849
+ <Newline/>
850
+ B
851
+ <Newline/>
852
+ C
853
+ </Text>
854
+ </Box>
855
+ // A
856
+ // X B
857
+ // C
858
+
859
+ <Box alignItems="flex-end">
860
+ <Box marginRight={1}>
861
+ <Text>X</Text>
862
+ </Box>
863
+ <Text>
864
+ A
865
+ <Newline/>
866
+ B
867
+ <Newline/>
868
+ C
869
+ </Text>
870
+ </Box>
871
+ // A
872
+ // B
873
+ // X C
874
+ ```
875
+
876
+ ##### alignSelf
877
+
878
+ Type: `string`\
879
+ Default: `auto`\
880
+ Allowed values: `auto` `flex-start` `center` `flex-end` `stretch` `baseline`
881
+
882
+ See [align-self](https://css-tricks.com/almanac/properties/a/align-self/).
883
+
884
+ ```jsx
885
+ <Box height={3}>
886
+ <Box alignSelf="flex-start">
887
+ <Text>X</Text>
888
+ </Box>
889
+ </Box>
890
+ // X
891
+ //
892
+ //
893
+
894
+ <Box height={3}>
895
+ <Box alignSelf="center">
896
+ <Text>X</Text>
897
+ </Box>
898
+ </Box>
899
+ //
900
+ // X
901
+ //
902
+
903
+ <Box height={3}>
904
+ <Box alignSelf="flex-end">
905
+ <Text>X</Text>
906
+ </Box>
907
+ </Box>
908
+ //
909
+ //
910
+ // X
911
+ ```
912
+
913
+ ##### alignContent
914
+
915
+ Type: `string`\
916
+ Default: `flex-start`\
917
+ Allowed values: `flex-start` `flex-end` `center` `stretch` `space-between` `space-around` `space-evenly`
918
+
919
+ Defines alignment between flex lines on the cross axis when `flexWrap` creates multiple lines.
920
+ See [align-content](https://css-tricks.com/almanac/properties/a/align-content/).
921
+ Unlike CSS (`stretch`), Ink defaults to `flex-start` so wrapped lines stay compact and fixed-height boxes don't gain unexpected empty rows unless you opt in to stretching.
922
+
923
+ ##### justifyContent
924
+
925
+ Type: `string`\
926
+ Allowed values: `flex-start` `center` `flex-end` `space-between` `space-around` `space-evenly`
927
+
928
+ See [justify-content](https://css-tricks.com/almanac/properties/j/justify-content/).
929
+
930
+ ```jsx
931
+ <Box justifyContent="flex-start">
932
+ <Text>X</Text>
933
+ </Box>
934
+ // [X ]
935
+
936
+ <Box justifyContent="center">
937
+ <Text>X</Text>
938
+ </Box>
939
+ // [ X ]
940
+
941
+ <Box justifyContent="flex-end">
942
+ <Text>X</Text>
943
+ </Box>
944
+ // [ X]
945
+
946
+ <Box justifyContent="space-between">
947
+ <Text>X</Text>
948
+ <Text>Y</Text>
949
+ </Box>
950
+ // [X Y]
951
+
952
+ <Box justifyContent="space-around">
953
+ <Text>X</Text>
954
+ <Text>Y</Text>
955
+ </Box>
956
+ // [ X Y ]
957
+
958
+ <Box justifyContent="space-evenly">
959
+ <Text>X</Text>
960
+ <Text>Y</Text>
961
+ </Box>
962
+ // [ X Y ]
963
+ ```
964
+
965
+ #### Position
966
+
967
+ ##### position
968
+
969
+ Type: `string`\
970
+ Allowed values: `relative` `absolute` `static`\
971
+ Default: `relative`
972
+
973
+ Controls how the element is positioned.
974
+
975
+ When `position` is `static`, `top`, `right`, `bottom`, and `left` are ignored.
976
+
977
+ ##### top
978
+
979
+ Type: `number` `string`
980
+
981
+ Top offset for positioned elements.
982
+ You can also set it as a percentage of the parent size.
983
+
984
+ ##### right
985
+
986
+ Type: `number` `string`
987
+
988
+ Right offset for positioned elements.
989
+ You can also set it as a percentage of the parent size.
990
+
991
+ ##### bottom
992
+
993
+ Type: `number` `string`
994
+
995
+ Bottom offset for positioned elements.
996
+ You can also set it as a percentage of the parent size.
997
+
998
+ ##### left
999
+
1000
+ Type: `number` `string`
1001
+
1002
+ Left offset for positioned elements.
1003
+ You can also set it as a percentage of the parent size.
1004
+
1005
+ #### Visibility
1006
+
1007
+ ##### display
1008
+
1009
+ Type: `string`\
1010
+ Allowed values: `flex` `none`\
1011
+ Default: `flex`
1012
+
1013
+ Set this property to `none` to hide the element.
1014
+
1015
+ ##### overflowX
1016
+
1017
+ Type: `string`\
1018
+ Allowed values: `visible` `hidden`\
1019
+ Default: `visible`
1020
+
1021
+ Behavior for an element's overflow in the horizontal direction.
1022
+
1023
+ ##### overflowY
1024
+
1025
+ Type: `string`\
1026
+ Allowed values: `visible` `hidden`\
1027
+ Default: `visible`
1028
+
1029
+ Behavior for an element's overflow in the vertical direction.
1030
+
1031
+ ##### overflow
1032
+
1033
+ Type: `string`\
1034
+ Allowed values: `visible` `hidden`\
1035
+ Default: `visible`
1036
+
1037
+ A shortcut for setting `overflowX` and `overflowY` at the same time.
1038
+
1039
+ #### Borders
1040
+
1041
+ ##### borderStyle
1042
+
1043
+ Type: `string`\
1044
+ Allowed values: `single` `double` `round` `bold` `singleDouble` `doubleSingle` `classic` | `BoxStyle`
1045
+
1046
+ Add a border with a specified style.
1047
+ If `borderStyle` is `undefined` (the default), no border will be added.
1048
+ Ink uses border styles from the [`cli-boxes`](https://github.com/sindresorhus/cli-boxes) module.
1049
+
1050
+ ```jsx
1051
+ <Box flexDirection="column">
1052
+ <Box>
1053
+ <Box borderStyle="single" marginRight={2}>
1054
+ <Text>single</Text>
1055
+ </Box>
1056
+
1057
+ <Box borderStyle="double" marginRight={2}>
1058
+ <Text>double</Text>
1059
+ </Box>
1060
+
1061
+ <Box borderStyle="round" marginRight={2}>
1062
+ <Text>round</Text>
1063
+ </Box>
1064
+
1065
+ <Box borderStyle="bold">
1066
+ <Text>bold</Text>
1067
+ </Box>
1068
+ </Box>
1069
+
1070
+ <Box marginTop={1}>
1071
+ <Box borderStyle="singleDouble" marginRight={2}>
1072
+ <Text>singleDouble</Text>
1073
+ </Box>
1074
+
1075
+ <Box borderStyle="doubleSingle" marginRight={2}>
1076
+ <Text>doubleSingle</Text>
1077
+ </Box>
1078
+
1079
+ <Box borderStyle="classic">
1080
+ <Text>classic</Text>
1081
+ </Box>
1082
+ </Box>
1083
+ </Box>
1084
+ ```
1085
+
1086
+ <img src="media/box-borderStyle.jpg" width="521">
1087
+
1088
+ Alternatively, pass a custom border style like so:
1089
+
1090
+ ```jsx
1091
+ <Box
1092
+ borderStyle={{
1093
+ topLeft: "↘",
1094
+ top: "↓",
1095
+ topRight: "↙",
1096
+ left: "→",
1097
+ bottomLeft: "↗",
1098
+ bottom: "↑",
1099
+ bottomRight: "↖",
1100
+ right: "←",
1101
+ }}
1102
+ >
1103
+ <Text>Custom</Text>
1104
+ </Box>
1105
+ ```
1106
+
1107
+ See example in [examples/borders](examples/borders/borders.tsx).
1108
+
1109
+ ##### borderColor
1110
+
1111
+ Type: `string`
1112
+
1113
+ Change border color.
1114
+ A shorthand for setting `borderTopColor`, `borderRightColor`, `borderBottomColor`, and `borderLeftColor`.
1115
+
1116
+ ```jsx
1117
+ <Box borderStyle="round" borderColor="green">
1118
+ <Text>Green Rounded Box</Text>
1119
+ </Box>
1120
+ ```
1121
+
1122
+ <img src="media/box-borderColor.jpg" width="228">
1123
+
1124
+ ##### borderTopColor
1125
+
1126
+ Type: `string`
1127
+
1128
+ Change top border color.
1129
+ Accepts the same values as [`color`](#color) in `<Text>` component.
1130
+
1131
+ ```jsx
1132
+ <Box borderStyle="round" borderTopColor="green">
1133
+ <Text>Hello world</Text>
1134
+ </Box>
1135
+ ```
1136
+
1137
+ ##### borderRightColor
1138
+
1139
+ Type: `string`
1140
+
1141
+ Change the right border color.
1142
+ Accepts the same values as [`color`](#color) in `<Text>` component.
1143
+
1144
+ ```jsx
1145
+ <Box borderStyle="round" borderRightColor="green">
1146
+ <Text>Hello world</Text>
1147
+ </Box>
1148
+ ```
1149
+
1150
+ ##### borderBottomColor
1151
+
1152
+ Type: `string`
1153
+
1154
+ Change the bottom border color.
1155
+ Accepts the same values as [`color`](#color) in `<Text>` component.
1156
+
1157
+ ```jsx
1158
+ <Box borderStyle="round" borderBottomColor="green">
1159
+ <Text>Hello world</Text>
1160
+ </Box>
1161
+ ```
1162
+
1163
+ ##### borderLeftColor
1164
+
1165
+ Type: `string`
1166
+
1167
+ Change the left border color.
1168
+ Accepts the same values as [`color`](#color) in `<Text>` component.
1169
+
1170
+ ```jsx
1171
+ <Box borderStyle="round" borderLeftColor="green">
1172
+ <Text>Hello world</Text>
1173
+ </Box>
1174
+ ```
1175
+
1176
+ ##### borderDimColor
1177
+
1178
+ Type: `boolean`\
1179
+ Default: `false`
1180
+
1181
+ Dim the border color.
1182
+ A shorthand for setting `borderTopDimColor`, `borderBottomDimColor`, `borderLeftDimColor`, and `borderRightDimColor`.
1183
+
1184
+ ```jsx
1185
+ <Box borderStyle="round" borderDimColor>
1186
+ <Text>Hello world</Text>
1187
+ </Box>
1188
+ ```
1189
+
1190
+ ##### borderTopDimColor
1191
+
1192
+ Type: `boolean`\
1193
+ Default: `false`
1194
+
1195
+ Dim the top border color.
1196
+
1197
+ ```jsx
1198
+ <Box borderStyle="round" borderTopDimColor>
1199
+ <Text>Hello world</Text>
1200
+ </Box>
1201
+ ```
1202
+
1203
+ ##### borderBottomDimColor
1204
+
1205
+ Type: `boolean`\
1206
+ Default: `false`
1207
+
1208
+ Dim the bottom border color.
1209
+
1210
+ ```jsx
1211
+ <Box borderStyle="round" borderBottomDimColor>
1212
+ <Text>Hello world</Text>
1213
+ </Box>
1214
+ ```
1215
+
1216
+ ##### borderLeftDimColor
1217
+
1218
+ Type: `boolean`\
1219
+ Default: `false`
1220
+
1221
+ Dim the left border color.
1222
+
1223
+ ```jsx
1224
+ <Box borderStyle="round" borderLeftDimColor>
1225
+ <Text>Hello world</Text>
1226
+ </Box>
1227
+ ```
1228
+
1229
+ ##### borderRightDimColor
1230
+
1231
+ Type: `boolean`\
1232
+ Default: `false`
1233
+
1234
+ Dim the right border color.
1235
+
1236
+ ```jsx
1237
+ <Box borderStyle="round" borderRightDimColor>
1238
+ <Text>Hello world</Text>
1239
+ </Box>
1240
+ ```
1241
+
1242
+ ##### borderBackgroundColor
1243
+
1244
+ Type: `string`
1245
+
1246
+ Change border background color.
1247
+ Accepts the same values as [`backgroundColor`](#backgroundcolor) in `<Text>` component.
1248
+ A shorthand for setting `borderTopBackgroundColor`, `borderRightBackgroundColor`, `borderBottomBackgroundColor`, and `borderLeftBackgroundColor`.
1249
+
1250
+ ```jsx
1251
+ <Box borderStyle="round" borderColor="white" borderBackgroundColor="green">
1252
+ <Text>Hello world</Text>
1253
+ </Box>
1254
+ ```
1255
+
1256
+ ##### borderTopBackgroundColor
1257
+
1258
+ Type: `string`
1259
+
1260
+ Change top border background color.
1261
+ Accepts the same values as [`backgroundColor`](#backgroundcolor) in `<Text>` component.
1262
+ Falls back to `borderBackgroundColor` if not specified.
1263
+
1264
+ ```jsx
1265
+ <Box borderStyle="round" borderColor="white" borderTopBackgroundColor="green">
1266
+ <Text>Hello world</Text>
1267
+ </Box>
1268
+ ```
1269
+
1270
+ ##### borderBottomBackgroundColor
1271
+
1272
+ Type: `string`
1273
+
1274
+ Change bottom border background color.
1275
+ Accepts the same values as [`backgroundColor`](#backgroundcolor) in `<Text>` component.
1276
+ Falls back to `borderBackgroundColor` if not specified.
1277
+
1278
+ ```jsx
1279
+ <Box borderStyle="round" borderColor="white" borderBottomBackgroundColor="green">
1280
+ <Text>Hello world</Text>
1281
+ </Box>
1282
+ ```
1283
+
1284
+ ##### borderRightBackgroundColor
1285
+
1286
+ Type: `string`
1287
+
1288
+ Change right border background color.
1289
+ Accepts the same values as [`backgroundColor`](#backgroundcolor) in `<Text>` component.
1290
+ Falls back to `borderBackgroundColor` if not specified.
1291
+
1292
+ ```jsx
1293
+ <Box borderStyle="round" borderColor="white" borderRightBackgroundColor="green">
1294
+ <Text>Hello world</Text>
1295
+ </Box>
1296
+ ```
1297
+
1298
+ ##### borderLeftBackgroundColor
1299
+
1300
+ Type: `string`
1301
+
1302
+ Change left border background color.
1303
+ Accepts the same values as [`backgroundColor`](#backgroundcolor) in `<Text>` component.
1304
+ Falls back to `borderBackgroundColor` if not specified.
1305
+
1306
+ ```jsx
1307
+ <Box borderStyle="round" borderColor="white" borderLeftBackgroundColor="green">
1308
+ <Text>Hello world</Text>
1309
+ </Box>
1310
+ ```
1311
+
1312
+ ##### borderTop
1313
+
1314
+ Type: `boolean`\
1315
+ Default: `true`
1316
+
1317
+ Determines whether the top border is visible.
1318
+
1319
+ ##### borderRight
1320
+
1321
+ Type: `boolean`\
1322
+ Default: `true`
1323
+
1324
+ Determines whether the right border is visible.
1325
+
1326
+ ##### borderBottom
1327
+
1328
+ Type: `boolean`\
1329
+ Default: `true`
1330
+
1331
+ Determines whether the bottom border is visible.
1332
+
1333
+ ##### borderLeft
1334
+
1335
+ Type: `boolean`\
1336
+ Default: `true`
1337
+
1338
+ Determines whether the left border is visible.
1339
+
1340
+ #### Background
1341
+
1342
+ ##### backgroundColor
1343
+
1344
+ Type: `string`
1345
+
1346
+ Background color for the element.
1347
+
1348
+ Accepts the same values as [`color`](#color) in the `<Text>` component.
1349
+
1350
+ ```jsx
1351
+ <Box flexDirection="column">
1352
+ <Box backgroundColor="red" width={20} height={5} alignSelf="flex-start">
1353
+ <Text>Red background</Text>
1354
+ </Box>
1355
+
1356
+ <Box backgroundColor="#FF8800" width={20} height={3} marginTop={1} alignSelf="flex-start">
1357
+ <Text>Orange background</Text>
1358
+ </Box>
1359
+
1360
+ <Box backgroundColor="rgb(0, 255, 0)" width={20} height={3} marginTop={1} alignSelf="flex-start">
1361
+ <Text>Green background</Text>
1362
+ </Box>
1363
+ </Box>
1364
+ ```
1365
+
1366
+ The background color fills the entire `<Box>` area and is inherited by child `<Text>` components unless they specify their own `backgroundColor`.
1367
+
1368
+ ```jsx
1369
+ <Box backgroundColor="blue" alignSelf="flex-start">
1370
+ <Text>Blue inherited </Text>
1371
+ <Text backgroundColor="yellow">Yellow override </Text>
1372
+ <Text>Blue inherited again</Text>
1373
+ </Box>
1374
+ ```
1375
+
1376
+ Background colors work with borders and padding:
1377
+
1378
+ ```jsx
1379
+ <Box backgroundColor="cyan" borderStyle="round" padding={1} alignSelf="flex-start">
1380
+ <Text>Background with border and padding</Text>
1381
+ </Box>
1382
+ ```
1383
+
1384
+ See example in [examples/box-backgrounds](examples/box-backgrounds/box-backgrounds.tsx).
1385
+
1386
+ ### `<Newline>`
1387
+
1388
+ Adds one or more newline (`\n`) characters.
1389
+ Must be used within `<Text>` components.
1390
+
1391
+ #### count
1392
+
1393
+ Type: `number`\
1394
+ Default: `1`
1395
+
1396
+ Number of newlines to insert.
1397
+
1398
+ ```jsx
1399
+ import { render, Text, Newline } from "@alchemy.run/sigil";
1400
+
1401
+ const Example = () => (
1402
+ <Text>
1403
+ <Text color="green">Hello</Text>
1404
+ <Newline />
1405
+ <Text color="red">World</Text>
1406
+ </Text>
1407
+ );
1408
+
1409
+ render(<Example />);
1410
+ ```
1411
+
1412
+ Output:
1413
+
1414
+ ```
1415
+ Hello
1416
+ World
1417
+ ```
1418
+
1419
+ ### `<Spacer>`
1420
+
1421
+ A flexible space that expands along the major axis of its containing layout.
1422
+ It's useful as a shortcut for filling all the available space between elements.
1423
+
1424
+ For example, using `<Spacer>` in a `<Box>` with default flex direction (`row`) will position "Left" on the left side and will push "Right" to the right side.
1425
+
1426
+ ```jsx
1427
+ import { render, Box, Text, Spacer } from "@alchemy.run/sigil";
1428
+
1429
+ const Example = () => (
1430
+ <Box>
1431
+ <Text>Left</Text>
1432
+ <Spacer />
1433
+ <Text>Right</Text>
1434
+ </Box>
1435
+ );
1436
+
1437
+ render(<Example />);
1438
+ ```
1439
+
1440
+ In a vertical flex direction (`column`), it will position "Top" at the top of the container and push "Bottom" to the bottom.
1441
+ Note that the container needs to be tall enough to see this in effect.
1442
+
1443
+ ```jsx
1444
+ import { render, Box, Text, Spacer } from "@alchemy.run/sigil";
1445
+
1446
+ const Example = () => (
1447
+ <Box flexDirection="column" height={10}>
1448
+ <Text>Top</Text>
1449
+ <Spacer />
1450
+ <Text>Bottom</Text>
1451
+ </Box>
1452
+ );
1453
+
1454
+ render(<Example />);
1455
+ ```
1456
+
1457
+ ### `<Static>`
1458
+
1459
+ `<Static>` component permanently renders its output above everything else.
1460
+ It's useful for displaying activity like completed tasks or logs - things that
1461
+ don't change after they're rendered (hence the name "Static").
1462
+
1463
+ It's preferred to use `<Static>` for use cases like these when you can't know
1464
+ or control the number of items that need to be rendered.
1465
+
1466
+ For example, [Tap](https://github.com/tapjs/node-tap) uses `<Static>` to display
1467
+ a list of completed tests. [Gatsby](https://github.com/gatsbyjs/gatsby) uses it
1468
+ to display a list of generated pages while still displaying a live progress bar.
1469
+
1470
+ ```jsx
1471
+ import React, { useState, useEffect } from "react";
1472
+ import { render, Static, Box, Text } from "@alchemy.run/sigil";
1473
+
1474
+ const Example = () => {
1475
+ const [tests, setTests] = useState([]);
1476
+
1477
+ useEffect(() => {
1478
+ let completedTests = 0;
1479
+ let timer;
1480
+
1481
+ const run = () => {
1482
+ // Fake 10 completed tests
1483
+ if (completedTests++ < 10) {
1484
+ setTests((previousTests) => [
1485
+ ...previousTests,
1486
+ {
1487
+ id: previousTests.length,
1488
+ title: `Test #${previousTests.length + 1}`,
1489
+ },
1490
+ ]);
1491
+
1492
+ timer = setTimeout(run, 100);
1493
+ }
1494
+ };
1495
+
1496
+ run();
1497
+
1498
+ return () => {
1499
+ clearTimeout(timer);
1500
+ };
1501
+ }, []);
1502
+
1503
+ return (
1504
+ <>
1505
+ {/* This part will be rendered once to the terminal */}
1506
+ <Static items={tests}>
1507
+ {(test) => (
1508
+ <Box key={test.id}>
1509
+ <Text color="green">✔ {test.title}</Text>
1510
+ </Box>
1511
+ )}
1512
+ </Static>
1513
+
1514
+ {/* This part keeps updating as state changes */}
1515
+ <Box marginTop={1}>
1516
+ <Text dimColor>Completed tests: {tests.length}</Text>
1517
+ </Box>
1518
+ </>
1519
+ );
1520
+ };
1521
+
1522
+ render(<Example />);
1523
+ ```
1524
+
1525
+ > [!NOTE]
1526
+ > `<Static>` only renders new items in the `items` prop and ignores items that were previously rendered. This means that when you add new items to the `items` array, changes you make to previous items will not trigger a rerender.
1527
+
1528
+ See [examples/static](examples/static/static.tsx) for an example usage of `<Static>` component.
1529
+
1530
+ #### items
1531
+
1532
+ Type: `Array`
1533
+
1534
+ Array of items of any type to render using the function you pass as a component child.
1535
+
1536
+ #### style
1537
+
1538
+ Type: `object`
1539
+
1540
+ Styles to apply to a container of child elements.
1541
+ See [`<Box>`](#box) for supported properties.
1542
+
1543
+ ```jsx
1544
+ <Static items={...} style={{padding: 1}}>
1545
+ {...}
1546
+ </Static>
1547
+ ```
1548
+
1549
+ #### children(item)
1550
+
1551
+ Type: `Function`
1552
+
1553
+ Function that is called to render every item in the `items` array.
1554
+ The first argument is the item itself, and the second argument is the index of that item in the
1555
+ `items` array.
1556
+
1557
+ Note that a `key` must be assigned to the root component.
1558
+
1559
+ ```jsx
1560
+ <Static items={["a", "b", "c"]}>
1561
+ {(item, index) => {
1562
+ // This function is called for every item in ['a', 'b', 'c']
1563
+ // `item` is 'a', 'b', 'c'
1564
+ // `index` is 0, 1, 2
1565
+ return (
1566
+ <Box key={index}>
1567
+ <Text>Item: {item}</Text>
1568
+ </Box>
1569
+ );
1570
+ }}
1571
+ </Static>
1572
+ ```
1573
+
1574
+ ### `<Transform>`
1575
+
1576
+ Transform a string representation of React components before they're written to output.
1577
+ For example, you might want to apply a [gradient to text](https://github.com/sindresorhus/ink-gradient), [add a clickable link](https://github.com/sindresorhus/ink-link), or [create some text effects](https://github.com/sindresorhus/ink-big-text).
1578
+ These use cases can't accept React nodes as input; they expect a string.
1579
+ That's what the `<Transform>` component does: it gives you an output string of its child components and lets you transform it in any way.
1580
+
1581
+ > [!NOTE]
1582
+ > `<Transform>` must be applied only to `<Text>` children components and shouldn't change the dimensions of the output; otherwise, the layout will be incorrect.
1583
+
1584
+ > [!IMPORTANT]
1585
+ > When children use `<Text>` styling props (e.g. `color`, `bold`), the string passed to `transform` will contain [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code). If your transform manipulates whitespace or does string operations like `.trim()`, you may need to use ANSI-aware methods (e.g. from [`slice-ansi`](https://github.com/chalk/slice-ansi) or [`strip-ansi`](https://github.com/chalk/strip-ansi)).
1586
+
1587
+ ```jsx
1588
+ import { render, Transform } from "@alchemy.run/sigil";
1589
+
1590
+ const Example = () => (
1591
+ <Transform transform={(output) => output.toUpperCase()}>
1592
+ <Text>Hello World</Text>
1593
+ </Transform>
1594
+ );
1595
+
1596
+ render(<Example />);
1597
+ ```
1598
+
1599
+ Since the `transform` function converts all characters to uppercase, the final output rendered to the terminal will be "HELLO WORLD", not "Hello World".
1600
+
1601
+ When the output wraps to multiple lines, it can be helpful to know which line is being processed.
1602
+
1603
+ For example, to implement a hanging indent component, you can indent all the lines except for the first.
1604
+
1605
+ ```jsx
1606
+ import { render, Transform } from "@alchemy.run/sigil";
1607
+
1608
+ const HangingIndent = ({ indent = 4, children }) => (
1609
+ <Transform transform={(line, index) => (index === 0 ? line : " ".repeat(indent) + line)}>
1610
+ {children}
1611
+ </Transform>
1612
+ );
1613
+
1614
+ const text =
1615
+ "WHEN I WROTE the following pages, or rather the bulk of them, " +
1616
+ "I lived alone, in the woods, a mile from any neighbor, in a " +
1617
+ "house which I had built myself, on the shore of Walden Pond, " +
1618
+ "in Concord, Massachusetts, and earned my living by the labor " +
1619
+ "of my hands only. I lived there two years and two months. At " +
1620
+ "present I am a sojourner in civilized life again.";
1621
+
1622
+ render(<HangingIndent indent={4}>{text}</HangingIndent>);
1623
+ ```
1624
+
1625
+ #### transform(outputLine, index)
1626
+
1627
+ Type: `Function`
1628
+
1629
+ Function that transforms children output.
1630
+ It accepts children and must return transformed children as well.
1631
+
1632
+ ##### children
1633
+
1634
+ Type: `string`
1635
+
1636
+ Output of child components.
1637
+
1638
+ ##### index
1639
+
1640
+ Type: `number`
1641
+
1642
+ The zero-indexed line number of the line that's currently being transformed.
1643
+
1644
+ ## Hooks
1645
+
1646
+ ### useInput(inputHandler, options?)
1647
+
1648
+ A React hook that returns `void` and handles user input.
1649
+ It's a more convenient alternative to using `useStdin` and listening for `data` events.
1650
+ The callback you pass to `useInput` is called for each character when the user enters any input.
1651
+ However, if the user pastes text and it's more than one character, the callback will be called only once, and the whole string will be passed as `input`.
1652
+ You can find a full example of using `useInput` at [examples/use-input](examples/use-input/use-input.tsx).
1653
+
1654
+ ```jsx
1655
+ import {useInput} from '@alchemy.run/sigil';
1656
+
1657
+ const UserInput = () => {
1658
+ useInput((input, key) => {
1659
+ if (input === 'q') {
1660
+ // Exit program
1661
+ }
1662
+
1663
+ if (key.leftArrow) {
1664
+ // Left arrow key pressed
1665
+ }
1666
+ });
1667
+
1668
+ return …
1669
+ };
1670
+ ```
1671
+
1672
+ #### inputHandler(input, key)
1673
+
1674
+ Type: `Function`
1675
+
1676
+ The handler function that you pass to `useInput` receives two arguments:
1677
+
1678
+ ##### input
1679
+
1680
+ Type: `string`
1681
+
1682
+ The input that the program received.
1683
+
1684
+ ##### key
1685
+
1686
+ Type: `object`
1687
+
1688
+ Handy information about a key that was pressed.
1689
+
1690
+ ###### key.leftArrow
1691
+
1692
+ ###### key.rightArrow
1693
+
1694
+ ###### key.upArrow
1695
+
1696
+ ###### key.downArrow
1697
+
1698
+ Type: `boolean`\
1699
+ Default: `false`
1700
+
1701
+ If an arrow key was pressed, the corresponding property will be `true`.
1702
+ For example, if the user presses the left arrow key, `key.leftArrow` equals `true`.
1703
+
1704
+ ###### key.return
1705
+
1706
+ Type: `boolean`\
1707
+ Default: `false`
1708
+
1709
+ Return (Enter) key was pressed.
1710
+
1711
+ ###### key.escape
1712
+
1713
+ Type: `boolean`\
1714
+ Default: `false`
1715
+
1716
+ Escape key was pressed.
1717
+
1718
+ ###### key.ctrl
1719
+
1720
+ Type: `boolean`\
1721
+ Default: `false`
1722
+
1723
+ Ctrl key was pressed.
1724
+
1725
+ ###### key.shift
1726
+
1727
+ Type: `boolean`\
1728
+ Default: `false`
1729
+
1730
+ Shift key was pressed.
1731
+
1732
+ ###### key.tab
1733
+
1734
+ Type: `boolean`\
1735
+ Default: `false`
1736
+
1737
+ Tab key was pressed.
1738
+
1739
+ ###### key.backspace
1740
+
1741
+ Type: `boolean`\
1742
+ Default: `false`
1743
+
1744
+ Backspace key was pressed.
1745
+
1746
+ ###### key.delete
1747
+
1748
+ Type: `boolean`\
1749
+ Default: `false`
1750
+
1751
+ Delete key was pressed.
1752
+
1753
+ ###### key.pageDown
1754
+
1755
+ ###### key.pageUp
1756
+
1757
+ Type: `boolean`\
1758
+ Default: `false`
1759
+
1760
+ If the Page Up or Page Down key was pressed, the corresponding property will be `true`.
1761
+ For example, if the user presses Page Down, `key.pageDown` equals `true`.
1762
+
1763
+ ###### key.home
1764
+
1765
+ ###### key.end
1766
+
1767
+ Type: `boolean`\
1768
+ Default: `false`
1769
+
1770
+ If the Home or End key was pressed, the corresponding property will be `true`.
1771
+ For example, if the user presses End, `key.end` equals `true`.
1772
+
1773
+ ###### key.meta
1774
+
1775
+ Type: `boolean`\
1776
+ Default: `false`
1777
+
1778
+ [Meta key](https://en.wikipedia.org/wiki/Meta_key) was pressed.
1779
+
1780
+ ###### key.super
1781
+
1782
+ Type: `boolean`\
1783
+ Default: `false`
1784
+
1785
+ Super key (Cmd on macOS, Win on Windows) was pressed. Requires [kitty keyboard protocol](#kittykeyboard).
1786
+
1787
+ ###### key.hyper
1788
+
1789
+ Type: `boolean`\
1790
+ Default: `false`
1791
+
1792
+ Hyper key was pressed. Requires [kitty keyboard protocol](#kittykeyboard).
1793
+
1794
+ ###### key.capsLock
1795
+
1796
+ Type: `boolean`\
1797
+ Default: `false`
1798
+
1799
+ Caps Lock was active. Requires [kitty keyboard protocol](#kittykeyboard).
1800
+
1801
+ ###### key.numLock
1802
+
1803
+ Type: `boolean`\
1804
+ Default: `false`
1805
+
1806
+ Num Lock was active. Requires [kitty keyboard protocol](#kittykeyboard).
1807
+
1808
+ ###### key.eventType
1809
+
1810
+ Type: `'press' | 'repeat' | 'release'`\
1811
+ Default: `undefined`
1812
+
1813
+ The type of key event. Only available with [kitty keyboard protocol](#kittykeyboard). Without the protocol, this property is `undefined`.
1814
+
1815
+ #### options
1816
+
1817
+ Type: `object`
1818
+
1819
+ ##### isActive
1820
+
1821
+ Type: `boolean`\
1822
+ Default: `true`
1823
+
1824
+ Enable or disable capturing of user input.
1825
+ Useful when there are multiple `useInput` hooks used at once to avoid handling the same input several times.
1826
+
1827
+ ### usePaste(handler, options?)
1828
+
1829
+ A React hook that calls `handler` whenever the user pastes text. Bracketed paste mode (`\x1b[?2004h`) is automatically enabled while the hook is active, so pasted text arrives as a single string rather than being misinterpreted as individual key presses.
1830
+
1831
+ `usePaste` and `useInput` can be used together in the same component. They operate on separate event channels, so paste content is never forwarded to `useInput` handlers when `usePaste` is active.
1832
+
1833
+ ```jsx
1834
+ import {useInput, usePaste} from '@alchemy.run/sigil';
1835
+
1836
+ const MyInput = () => {
1837
+ useInput((input, key) => {
1838
+ // Only receives typed characters and key events, not pasted text.
1839
+ if (key.return) {
1840
+ // Submit
1841
+ }
1842
+ });
1843
+
1844
+ usePaste((text) => {
1845
+ // Receives the full pasted string, including newlines.
1846
+ console.log('Pasted:', text);
1847
+ });
1848
+
1849
+ return …
1850
+ };
1851
+ ```
1852
+
1853
+ #### handler(text)
1854
+
1855
+ Type: `Function`
1856
+
1857
+ Called with the full pasted string whenever the user pastes text. The string is delivered verbatim — newlines, escape sequences, and other special characters are preserved exactly as pasted.
1858
+
1859
+ ##### text
1860
+
1861
+ Type: `string`
1862
+
1863
+ The pasted text.
1864
+
1865
+ #### options
1866
+
1867
+ Type: `object`
1868
+
1869
+ ##### isActive
1870
+
1871
+ Type: `boolean`\
1872
+ Default: `true`
1873
+
1874
+ Enable or disable the paste handler. Useful when multiple components use `usePaste` and only one should be active at a time.
1875
+
1876
+ ### useApp()
1877
+
1878
+ A React hook that returns app lifecycle methods.
1879
+
1880
+ #### exit(errorOrResult?)
1881
+
1882
+ Type: `Function`
1883
+
1884
+ Exit (unmount) the whole Ink app.
1885
+
1886
+ ##### errorOrResult
1887
+
1888
+ Type: `Error | unknown`
1889
+
1890
+ Optional value that controls how [`waitUntilExit`](#waituntilexit) settles:
1891
+
1892
+ - `exit()` resolves with `undefined`.
1893
+ - `exit(error)` rejects when `error` is an `Error`.
1894
+ - `exit(value)` resolves with `value`.
1895
+
1896
+ ```js
1897
+ import {useEffect} from 'react';
1898
+ import {useApp} from '@alchemy.run/sigil';
1899
+
1900
+ const Example = () => {
1901
+ const {exit} = useApp();
1902
+
1903
+ // Exit the app after 5 seconds
1904
+ useEffect(() => {
1905
+ setTimeout(() => {
1906
+ exit();
1907
+ }, 5000);
1908
+ }, [exit]);
1909
+
1910
+ return …
1911
+ };
1912
+ ```
1913
+
1914
+ #### waitUntilRenderFlush()
1915
+
1916
+ Type: `Function`
1917
+
1918
+ Returns a promise that settles after pending render output is flushed to stdout.
1919
+
1920
+ ```js
1921
+ import {useEffect} from 'react';
1922
+ import {useApp} from '@alchemy.run/sigil';
1923
+
1924
+ const Example = () => {
1925
+ const {waitUntilRenderFlush} = useApp();
1926
+
1927
+ useEffect(() => {
1928
+ void (async () => {
1929
+ await waitUntilRenderFlush();
1930
+ runNextCommand();
1931
+ })();
1932
+ }, [waitUntilRenderFlush]);
1933
+
1934
+ return …;
1935
+ };
1936
+ ```
1937
+
1938
+ #### suspendTerminal(callback?)
1939
+
1940
+ Type: `Function`
1941
+
1942
+ Temporarily hands the terminal over to a child process (such as `$EDITOR`, `less`, or `fzf`), then restores Ink's terminal state and forces a full redraw.
1943
+
1944
+ While suspended, Ink stops writing output, stops consuming input, and restores the terminal modes the child expects (raw mode off, cursor visible, bracketed paste off, alternate screen exited, kitty keyboard protocol off). When the suspension ends, Ink reapplies its own terminal state and repaints from scratch.
1945
+
1946
+ ##### callback
1947
+
1948
+ Type: `Function`
1949
+
1950
+ When a callback is provided, Ink suspends, runs the callback, and restores the terminal once it settles, even if the callback throws.
1951
+
1952
+ ```js
1953
+ import { useApp } from "@alchemy.run/sigil";
1954
+
1955
+ const { suspendTerminal } = useApp();
1956
+
1957
+ await suspendTerminal(async () => {
1958
+ await runEditor();
1959
+ });
1960
+ ```
1961
+
1962
+ When called without a callback, it returns a suspension you resume yourself. `resume()` is async because restoring the terminal may need to wait for ordered writes and a full redraw.
1963
+
1964
+ ```js
1965
+ const suspension = await suspendTerminal();
1966
+
1967
+ try {
1968
+ await runEditor();
1969
+ } finally {
1970
+ await suspension.resume();
1971
+ }
1972
+ ```
1973
+
1974
+ The suspension is also a disposable, so it can be resumed automatically with `await using`:
1975
+
1976
+ ```js
1977
+ await using suspension = await suspendTerminal();
1978
+ await runEditor();
1979
+ ```
1980
+
1981
+ Suspending while a suspension is already active throws. This is supported only in interactive TTY mode; in non-interactive output the callback still runs but Ink performs no terminal handoff.
1982
+
1983
+ ### useStdin()
1984
+
1985
+ A React hook that returns the stdin stream and stdin-related utilities.
1986
+
1987
+ #### stdin
1988
+
1989
+ Type: `stream.Readable`\
1990
+ Default: `process.stdin`
1991
+
1992
+ The stdin stream passed to `render()` in `options.stdin`, or `process.stdin` by default.
1993
+ Useful if your app needs to handle user input.
1994
+
1995
+ ```js
1996
+ import {useStdin} from '@alchemy.run/sigil';
1997
+
1998
+ const Example = () => {
1999
+ const {stdin} = useStdin();
2000
+
2001
+ return …
2002
+ };
2003
+ ```
2004
+
2005
+ #### isRawModeSupported
2006
+
2007
+ Type: `boolean`
2008
+
2009
+ A boolean flag determining if the current `stdin` supports `setRawMode`.
2010
+ A component using `setRawMode` might want to use `isRawModeSupported` to nicely fall back in environments where raw mode is not supported.
2011
+
2012
+ ```jsx
2013
+ import { useStdin } from "@alchemy.run/sigil";
2014
+
2015
+ const Example = () => {
2016
+ const { isRawModeSupported } = useStdin();
2017
+
2018
+ return isRawModeSupported ? <MyInputComponent /> : <MyComponentThatDoesntUseInput />;
2019
+ };
2020
+ ```
2021
+
2022
+ #### setRawMode(isRawModeEnabled)
2023
+
2024
+ Type: `function`
2025
+
2026
+ ##### isRawModeEnabled
2027
+
2028
+ Type: `boolean`
2029
+
2030
+ See [`setRawMode`](https://nodejs.org/api/tty.html#tty_readstream_setrawmode_mode).
2031
+ Ink exposes this function to be able to handle <kbd>Ctrl</kbd>+<kbd>C</kbd>, that's why you should use Ink's `setRawMode` instead of `process.stdin.setRawMode`.
2032
+
2033
+ **Warning:** This function will throw unless the current `stdin` supports `setRawMode`. Use [`isRawModeSupported`](#israwmodesupported) to detect `setRawMode` support.
2034
+
2035
+ ```js
2036
+ import {useStdin} from '@alchemy.run/sigil';
2037
+
2038
+ const Example = () => {
2039
+ const {setRawMode} = useStdin();
2040
+
2041
+ useEffect(() => {
2042
+ setRawMode(true);
2043
+
2044
+ return () => {
2045
+ setRawMode(false);
2046
+ };
2047
+ });
2048
+
2049
+ return …
2050
+ };
2051
+ ```
2052
+
2053
+ ### useStdout()
2054
+
2055
+ A React hook that returns the stdout stream where Ink renders your app and stdout-related utilities.
2056
+
2057
+ #### stdout
2058
+
2059
+ Type: `stream.Writable`\
2060
+ Default: `process.stdout`
2061
+
2062
+ ```js
2063
+ import {useStdout} from '@alchemy.run/sigil';
2064
+
2065
+ const Example = () => {
2066
+ const {stdout} = useStdout();
2067
+
2068
+ return …
2069
+ };
2070
+ ```
2071
+
2072
+ #### write(data)
2073
+
2074
+ Write any string to stdout while preserving Ink's output.
2075
+ It's useful when you want to display external information outside of Ink's rendering and ensure there's no conflict between the two.
2076
+ It's similar to `<Static>`, except it can't accept components; it only works with strings.
2077
+
2078
+ ##### data
2079
+
2080
+ Type: `string`
2081
+
2082
+ Data to write to stdout.
2083
+
2084
+ ```js
2085
+ import {useStdout} from '@alchemy.run/sigil';
2086
+
2087
+ const Example = () => {
2088
+ const {write} = useStdout();
2089
+
2090
+ useEffect(() => {
2091
+ // Write a single message to stdout, above Ink's output
2092
+ write('Hello from Ink to stdout\n');
2093
+ }, []);
2094
+
2095
+ return …
2096
+ };
2097
+ ```
2098
+
2099
+ See additional usage example in [examples/use-stdout](examples/use-stdout/use-stdout.tsx).
2100
+
2101
+ ### useBoxMetrics(ref)
2102
+
2103
+ A React hook that returns the current layout metrics for a tracked box element.
2104
+ It updates when layout changes (for example terminal resize, sibling/content changes, or position changes).
2105
+
2106
+ Use `hasMeasured` to detect when the currently tracked element has been measured.
2107
+
2108
+ #### ref
2109
+
2110
+ Type: `React.RefObject<DOMElement | null>`
2111
+
2112
+ A ref to the `<Box>` element to track.
2113
+
2114
+ ```jsx
2115
+ import { useRef } from "react";
2116
+ import { Box, Text, useBoxMetrics } from "@alchemy.run/sigil";
2117
+
2118
+ const Example = () => {
2119
+ const ref = useRef(null);
2120
+ const { width, height, left, top, hasMeasured } = useBoxMetrics(ref);
2121
+
2122
+ return (
2123
+ <Box ref={ref}>
2124
+ <Text>{hasMeasured ? `${width}x${height} at ${left},${top}` : "Measuring..."}</Text>
2125
+ </Box>
2126
+ );
2127
+ };
2128
+ ```
2129
+
2130
+ #### width
2131
+
2132
+ Type: `number`
2133
+
2134
+ Element width.
2135
+
2136
+ #### height
2137
+
2138
+ Type: `number`
2139
+
2140
+ Element height.
2141
+
2142
+ #### left
2143
+
2144
+ Type: `number`
2145
+
2146
+ Distance from the left edge of the parent.
2147
+
2148
+ #### top
2149
+
2150
+ Type: `number`
2151
+
2152
+ Distance from the top edge of the parent.
2153
+
2154
+ #### hasMeasured
2155
+
2156
+ Type: `boolean`
2157
+
2158
+ Whether the currently tracked element has been measured.
2159
+
2160
+ > [!NOTE]
2161
+ > The hook returns `{width: 0, height: 0, left: 0, top: 0}` until the first layout pass completes. It also returns zeros when the tracked ref is detached.
2162
+
2163
+ ### useStderr()
2164
+
2165
+ A React hook that returns the stderr stream and stderr-related utilities.
2166
+
2167
+ #### stderr
2168
+
2169
+ Type: `stream.Writable`\
2170
+ Default: `process.stderr`
2171
+
2172
+ Stderr stream.
2173
+
2174
+ ```js
2175
+ import {useStderr} from '@alchemy.run/sigil';
2176
+
2177
+ const Example = () => {
2178
+ const {stderr} = useStderr();
2179
+
2180
+ return …
2181
+ };
2182
+ ```
2183
+
2184
+ #### write(data)
2185
+
2186
+ Write any string to stderr while preserving Ink's output.
2187
+
2188
+ It's useful when you want to display external information outside of Ink's rendering and ensure there's no conflict between the two.
2189
+ It's similar to `<Static>`, except it can't accept components; it only works with strings.
2190
+
2191
+ ##### data
2192
+
2193
+ Type: `string`
2194
+
2195
+ Data to write to stderr.
2196
+
2197
+ ```js
2198
+ import {useStderr} from '@alchemy.run/sigil';
2199
+
2200
+ const Example = () => {
2201
+ const {write} = useStderr();
2202
+
2203
+ useEffect(() => {
2204
+ // Write a single message to stderr, above Ink's output
2205
+ write('Hello from Ink to stderr\n');
2206
+ }, []);
2207
+
2208
+ return …
2209
+ };
2210
+ ```
2211
+
2212
+ ### useWindowSize()
2213
+
2214
+ A React hook that returns the current terminal dimensions and re-renders the component whenever the terminal is resized.
2215
+
2216
+ ```js
2217
+ import { Text, useWindowSize } from "@alchemy.run/sigil";
2218
+
2219
+ const Example = () => {
2220
+ const { columns, rows } = useWindowSize();
2221
+
2222
+ return (
2223
+ <Text>
2224
+ {columns}x{rows}
2225
+ </Text>
2226
+ );
2227
+ };
2228
+ ```
2229
+
2230
+ #### columns
2231
+
2232
+ Type: `number`
2233
+
2234
+ Number of columns (horizontal character cells).
2235
+
2236
+ #### rows
2237
+
2238
+ Type: `number`
2239
+
2240
+ Number of rows (vertical character cells).
2241
+
2242
+ > [!NOTE]
2243
+ > When the terminal is resized narrower, ghost lines may briefly appear depending on the terminal emulator's reflow behavior.
2244
+
2245
+ ### useFocus(options?)
2246
+
2247
+ A React hook that returns focus state and focus controls for the current component.
2248
+ A component that uses the `useFocus` hook becomes "focusable" to Ink, so when the user presses <kbd>Tab</kbd>, Ink will switch focus to this component.
2249
+ If there are multiple components that execute the `useFocus` hook, focus will be given to them in the order in which these components are rendered.
2250
+ This hook returns an object with an `isFocused` boolean property, which determines whether this component is focused.
2251
+
2252
+ #### options
2253
+
2254
+ ##### autoFocus
2255
+
2256
+ Type: `boolean`\
2257
+ Default: `false`
2258
+
2259
+ Auto-focus this component if there's no active (focused) component right now.
2260
+
2261
+ ##### isActive
2262
+
2263
+ Type: `boolean`\
2264
+ Default: `true`
2265
+
2266
+ Enable or disable this component's focus, while still maintaining its position in the list of focusable components.
2267
+ This is useful for inputs that are temporarily disabled.
2268
+
2269
+ ##### id
2270
+
2271
+ Type: `string`\
2272
+ Required: `false`
2273
+
2274
+ Set a component's focus ID, which can be used to programmatically focus the component. This is useful for large interfaces with many focusable elements to avoid having to cycle through all of them.
2275
+
2276
+ ```jsx
2277
+ import { render, useFocus, Text } from "@alchemy.run/sigil";
2278
+
2279
+ const Example = () => {
2280
+ const { isFocused } = useFocus();
2281
+
2282
+ return <Text>{isFocused ? "I am focused" : "I am not focused"}</Text>;
2283
+ };
2284
+
2285
+ render(<Example />);
2286
+ ```
2287
+
2288
+ See example in [examples/use-focus](examples/use-focus/use-focus.tsx) and [examples/use-focus-with-id](examples/use-focus-with-id/use-focus-with-id.tsx).
2289
+
2290
+ ### useFocusManager()
2291
+
2292
+ A React hook that returns methods to manage focus across focusable components.
2293
+
2294
+ #### enableFocus()
2295
+
2296
+ Enable focus management for all components.
2297
+
2298
+ > [!NOTE]
2299
+ > You don't need to call this method manually unless you've disabled focus management. Focus management is enabled by default.
2300
+
2301
+ ```js
2302
+ import {useFocusManager} from '@alchemy.run/sigil';
2303
+
2304
+ const Example = () => {
2305
+ const {enableFocus} = useFocusManager();
2306
+
2307
+ useEffect(() => {
2308
+ enableFocus();
2309
+ }, []);
2310
+
2311
+ return …
2312
+ };
2313
+ ```
2314
+
2315
+ #### disableFocus()
2316
+
2317
+ Disable focus management for all components.
2318
+ The currently active component (if there's one) will lose its focus.
2319
+
2320
+ ```js
2321
+ import {useFocusManager} from '@alchemy.run/sigil';
2322
+
2323
+ const Example = () => {
2324
+ const {disableFocus} = useFocusManager();
2325
+
2326
+ useEffect(() => {
2327
+ disableFocus();
2328
+ }, []);
2329
+
2330
+ return …
2331
+ };
2332
+ ```
2333
+
2334
+ #### focusNext()
2335
+
2336
+ Switch focus to the next focusable component.
2337
+ If there's no active component right now, focus will be given to the first focusable component.
2338
+ If the active component is the last in the list of focusable components, focus will be switched to the first focusable component.
2339
+
2340
+ > [!NOTE]
2341
+ > Ink calls this method when user presses <kbd>Tab</kbd>.
2342
+
2343
+ ```js
2344
+ import {useFocusManager} from '@alchemy.run/sigil';
2345
+
2346
+ const Example = () => {
2347
+ const {focusNext} = useFocusManager();
2348
+
2349
+ useEffect(() => {
2350
+ focusNext();
2351
+ }, []);
2352
+
2353
+ return …
2354
+ };
2355
+ ```
2356
+
2357
+ #### focusPrevious()
2358
+
2359
+ Switch focus to the previous focusable component.
2360
+ If there's no active component right now, focus will be given to the first focusable component.
2361
+ If the active component is the first in the list of focusable components, focus will be switched to the last focusable component.
2362
+
2363
+ > [!NOTE]
2364
+ > Ink calls this method when user presses <kbd>Shift</kbd>+<kbd>Tab</kbd>.
2365
+
2366
+ ```js
2367
+ import {useFocusManager} from '@alchemy.run/sigil';
2368
+
2369
+ const Example = () => {
2370
+ const {focusPrevious} = useFocusManager();
2371
+
2372
+ useEffect(() => {
2373
+ focusPrevious();
2374
+ }, []);
2375
+
2376
+ return …
2377
+ };
2378
+ ```
2379
+
2380
+ #### focus(id)
2381
+
2382
+ ##### id
2383
+
2384
+ Type: `string`
2385
+
2386
+ Switch focus to the component with the given [`id`](#id).
2387
+ If there's no component with that ID, focus is not changed.
2388
+
2389
+ ```js
2390
+ import {useFocusManager, useInput} from '@alchemy.run/sigil';
2391
+
2392
+ const Example = () => {
2393
+ const {focus} = useFocusManager();
2394
+
2395
+ useInput(input => {
2396
+ if (input === 's') {
2397
+ // Focus the component with focus ID 'someId'
2398
+ focus('someId');
2399
+ }
2400
+ });
2401
+
2402
+ return …
2403
+ };
2404
+ ```
2405
+
2406
+ #### activeId
2407
+
2408
+ Type: `string | undefined`
2409
+
2410
+ The ID of the currently focused component, or `undefined` if no component is focused.
2411
+
2412
+ ```js
2413
+ import { Text, useFocusManager } from "@alchemy.run/sigil";
2414
+
2415
+ const Example = () => {
2416
+ const { activeId } = useFocusManager();
2417
+
2418
+ return <Text>Focused: {activeId ?? "none"}</Text>;
2419
+ };
2420
+ ```
2421
+
2422
+ ### useCursor()
2423
+
2424
+ A React hook that returns methods to control the terminal cursor position after each render.
2425
+ This is essential for IME (Input Method Editor) support, where the composing character is displayed at the cursor location.
2426
+
2427
+ ```jsx
2428
+ import { useState } from "react";
2429
+ import { Box, Text, useCursor } from "@alchemy.run/sigil";
2430
+ import stringWidth from "string-width";
2431
+
2432
+ const TextInput = () => {
2433
+ const [text, setText] = useState("");
2434
+ const { setCursorPosition } = useCursor();
2435
+
2436
+ const prompt = "> ";
2437
+ setCursorPosition({ x: stringWidth(prompt + text), y: 1 });
2438
+
2439
+ return (
2440
+ <Box flexDirection="column">
2441
+ <Text>Type here:</Text>
2442
+ <Text>
2443
+ {prompt}
2444
+ {text}
2445
+ </Text>
2446
+ </Box>
2447
+ );
2448
+ };
2449
+ ```
2450
+
2451
+ #### setCursorPosition(position)
2452
+
2453
+ Set the cursor position relative to the Ink output. Pass `undefined` to hide the cursor.
2454
+
2455
+ ##### position
2456
+
2457
+ Type: `object | undefined`
2458
+
2459
+ Use [`string-width`](https://github.com/sindresorhus/string-width) to calculate `x` for strings containing wide characters (CJK, emoji).
2460
+
2461
+ See a full example at [examples/cursor-ime](examples/cursor-ime/cursor-ime.tsx).
2462
+
2463
+ ###### x
2464
+
2465
+ Type: `number`
2466
+
2467
+ Column position (0-based).
2468
+
2469
+ ###### y
2470
+
2471
+ Type: `number`
2472
+
2473
+ Row position from the top of the Ink output (0 = first line).
2474
+
2475
+ ### useIsScreenReaderEnabled()
2476
+
2477
+ A React hook that returns whether a screen reader is enabled.
2478
+ This is useful when you want to render different output for screen readers.
2479
+
2480
+ ```jsx
2481
+ import { useIsScreenReaderEnabled, Text } from "@alchemy.run/sigil";
2482
+
2483
+ const Example = () => {
2484
+ const isScreenReaderEnabled = useIsScreenReaderEnabled();
2485
+
2486
+ return (
2487
+ <Text>{isScreenReaderEnabled ? "Screen reader is enabled" : "Screen reader is disabled"}</Text>
2488
+ );
2489
+ };
2490
+ ```
2491
+
2492
+ ### useAnimation(options?)
2493
+
2494
+ A React hook that drives animations. Returns a frame counter, elapsed time, frame delta, and a reset function. All animations share a single timer internally, so multiple animated components consolidate into one render cycle.
2495
+
2496
+ ```jsx
2497
+ import { Text, useAnimation } from "@alchemy.run/sigil";
2498
+
2499
+ const Spinner = () => {
2500
+ const { frame } = useAnimation({ interval: 80 });
2501
+ const characters = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
2502
+
2503
+ return <Text>{characters[frame % characters.length]}</Text>;
2504
+ };
2505
+ ```
2506
+
2507
+ #### options
2508
+
2509
+ Type: `object`
2510
+
2511
+ ##### interval
2512
+
2513
+ Type: `number`\
2514
+ Default: `100`
2515
+
2516
+ Time between ticks in milliseconds.
2517
+
2518
+ ##### isActive
2519
+
2520
+ Type: `boolean`\
2521
+ Default: `true`
2522
+
2523
+ Whether the animation is running. When set to `false`, the animation stops. When toggled back to `true`, all values reset to `0`.
2524
+
2525
+ #### Return value
2526
+
2527
+ ##### frame
2528
+
2529
+ Type: `number`
2530
+
2531
+ Discrete counter that increments by 1 each interval. Useful for indexed sequences like spinner frames.
2532
+
2533
+ ##### time
2534
+
2535
+ Type: `number`
2536
+
2537
+ Total elapsed time in milliseconds since the animation started or was last reset. Useful for continuous math-based animations like sine waves: `Math.sin(time / 1000 * Math.PI * 2)`.
2538
+
2539
+ ##### delta
2540
+
2541
+ Type: `number`
2542
+
2543
+ Time in milliseconds since the previous rendered tick. Accounts for throttled renders. Useful for physics-based or velocity-driven motion: `position += speed * delta`.
2544
+
2545
+ ##### reset
2546
+
2547
+ Type: `() => void`
2548
+
2549
+ Resets `frame`, `time`, and `delta` to `0` and restarts timing from the current moment. Useful for one-shot animations triggered by events.
2550
+
2551
+ ## API
2552
+
2553
+ #### render(tree, options?)
2554
+
2555
+ Returns: [`Instance`](#instance)
2556
+
2557
+ Mount a component and render the output.
2558
+
2559
+ ##### tree
2560
+
2561
+ Type: `ReactNode`
2562
+
2563
+ ##### options
2564
+
2565
+ Type: `object`
2566
+
2567
+ ###### stdout
2568
+
2569
+ Type: `stream.Writable`\
2570
+ Default: `process.stdout`
2571
+
2572
+ Output stream where the app will be rendered.
2573
+
2574
+ ###### stdin
2575
+
2576
+ Type: `stream.Readable`\
2577
+ Default: `process.stdin`
2578
+
2579
+ Input stream where app will listen for input.
2580
+
2581
+ ###### stderr
2582
+
2583
+ Type: `stream.Writable`\
2584
+ Default: `process.stderr`
2585
+
2586
+ Error stream.
2587
+
2588
+ ###### exitOnCtrlC
2589
+
2590
+ Type: `boolean`\
2591
+ Default: `true`
2592
+
2593
+ Configure whether Ink should listen for Ctrl+C keyboard input and exit the app.
2594
+ This is needed in case `process.stdin` is in [raw mode](https://nodejs.org/api/tty.html#tty_readstream_setrawmode_mode), because then Ctrl+C is ignored by default and the process is expected to handle it manually.
2595
+
2596
+ ###### patchConsole
2597
+
2598
+ Type: `boolean | 'stdio'`\
2599
+ Default: `true`
2600
+
2601
+ Patch console methods to ensure console output doesn't mix with Ink's output.
2602
+ When any of the `console.*` methods are called (like `console.log()`), Ink intercepts their output, clears the main output, renders output from the console method, and then rerenders the main output again.
2603
+ That way, both are visible and don't overlap each other.
2604
+
2605
+ Pass `'stdio'` to additionally intercept direct `stdout.write()` / `stderr.write()` calls on the streams Ink renders to — output from dependencies, native warnings, or child tooling that bypasses `console.*`.
2606
+ Captured chunks are line-buffered (partial chunks such as progress-bar updates are held until their newline arrives, and flushed at unmount) and spliced above the live frame exactly like console output.
2607
+ Ink's own frame writes bypass the capture.
2608
+
2609
+ Once unmount starts, Ink restores the native console (and stream writes) before React cleanup runs. Teardown-time output then follows the normal behavior instead of being rerouted through Ink.
2610
+
2611
+ ###### onCapturedOutput
2612
+
2613
+ Type: `(stream: 'stdout' | 'stderr', data: string, source: 'console' | 'stdio') => boolean | void`\
2614
+ Default: `undefined`
2615
+
2616
+ Observe output captured by `patchConsole` before Ink displays it.
2617
+ The callback receives each captured chunk with its origin: `'console'` for patched `console.*` calls, `'stdio'` for direct stream writes (only emitted with `patchConsole: 'stdio'`).
2618
+
2619
+ Return `true` to take ownership of a chunk: Ink will not display it, letting the app render it itself — for example as rows in a [`<Static>`](#static) transcript, which commits the output to scrollback above every live view:
2620
+
2621
+ ```jsx
2622
+ const [transcript, setTranscript] = useState([]);
2623
+
2624
+ render(<App transcript={transcript} />, {
2625
+ patchConsole: "stdio",
2626
+ onCapturedOutput(stream, data) {
2627
+ setTranscript((previous) => [...previous, { stream, data }]);
2628
+ return true;
2629
+ },
2630
+ });
2631
+ ```
2632
+
2633
+ ###### onRender
2634
+
2635
+ Type: `({renderTime: number}) => void`\
2636
+ Default: `undefined`
2637
+
2638
+ Runs the given callback after each render and re-render with render metrics.
2639
+ This callback runs after Ink commits a frame, but it does not wait for `stdout`/`stderr` stream callbacks.
2640
+ To run code after output is flushed, use [`waitUntilRenderFlush()`](#waituntilrenderflush).
2641
+
2642
+ ###### isScreenReaderEnabled
2643
+
2644
+ Type: `boolean`\
2645
+ Default: `process.env['INK_SCREEN_READER'] === 'true'`
2646
+
2647
+ Enable screen reader support. See [Screen Reader Support](#screen-reader-support).
2648
+
2649
+ ###### debug
2650
+
2651
+ Type: `boolean`\
2652
+ Default: `false`
2653
+
2654
+ If `true`, each update will be rendered as separate output, without replacing the previous one.
2655
+
2656
+ ###### maxFps
2657
+
2658
+ Type: `number`\
2659
+ Default: `30`
2660
+
2661
+ Maximum frames per second for render updates.
2662
+ This controls how frequently the UI can update to prevent excessive re-rendering.
2663
+ Higher values allow more frequent updates but may impact performance.
2664
+ Setting it to a lower value may be useful for components that update very frequently, to reduce CPU usage.
2665
+
2666
+ ###### incrementalRendering
2667
+
2668
+ Type: `boolean`\
2669
+ Default: `false`
2670
+
2671
+ Enable incremental rendering mode which only updates changed lines instead of redrawing the entire output.
2672
+ This can reduce flickering and improve performance for frequently updating UIs.
2673
+
2674
+ ###### concurrent
2675
+
2676
+ Type: `boolean`\
2677
+ Default: `false`
2678
+
2679
+ Enable React Concurrent Rendering mode.
2680
+
2681
+ When enabled:
2682
+
2683
+ - Suspense boundaries work correctly with async data fetching
2684
+ - `useTransition` and `useDeferredValue` hooks are fully functional
2685
+ - Updates can be interrupted for higher priority work
2686
+
2687
+ ```jsx
2688
+ render(<MyApp />, { concurrent: true });
2689
+ ```
2690
+
2691
+ > [!NOTE]
2692
+ > Concurrent mode changes the timing of renders. Some tests may need to use `act()` to properly await updates. Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change the rendering mode or create a fresh instance.
2693
+
2694
+ ###### interactive
2695
+
2696
+ Type: `boolean`\
2697
+ Default: `true` (`false` if in CI (detected via [`is-in-ci`](https://github.com/sindresorhus/is-in-ci)) or `stdout.isTTY` is falsy)
2698
+
2699
+ Override automatic interactive mode detection.
2700
+
2701
+ By default, Ink detects whether the environment is interactive based on CI detection and `stdout.isTTY`. When non-interactive, Ink skips terminal-specific features like ANSI erase sequences, cursor manipulation, synchronized output, resize handling, and kitty keyboard auto-detection. Only the final frame of non-static output is written at unmount.
2702
+
2703
+ Most users should not need to set this option. Use it when you have your own "interactive" detection logic that differs from the built-in behavior.
2704
+
2705
+ > [!NOTE]
2706
+ > Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change this option or create a fresh instance.
2707
+
2708
+ ```jsx
2709
+ // Use your own detection logic
2710
+ const isInteractive = myCustomDetection();
2711
+ render(<MyApp />, { interactive: isInteractive });
2712
+ ```
2713
+
2714
+ ###### alternateScreen
2715
+
2716
+ Type: `boolean`\
2717
+ Default: `false`
2718
+
2719
+ Render the app in the terminal's alternate screen buffer. When enabled, the app renders on a separate screen, and the original terminal content is restored when the app exits. This is the same mechanism used by programs like vim, htop, and less.
2720
+
2721
+ Note: The terminal's scrollback buffer is not available while in the alternate screen. This is standard terminal behavior; programs like vim use the alternate screen specifically to avoid polluting the user's scrollback history.
2722
+
2723
+ Ink intentionally treats alternate-screen teardown output as disposable. It does not preserve or replay teardown-time frames, hook writes, or `console.*` output after restoring the primary screen.
2724
+
2725
+ Only works in interactive mode. Ignored when `interactive` is `false` or in a non-interactive environment (CI, piped stdout).
2726
+
2727
+ > [!NOTE]
2728
+ > Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change this option or create a fresh instance.
2729
+
2730
+ ```jsx
2731
+ render(<MyApp />, { alternateScreen: true });
2732
+ ```
2733
+
2734
+ ###### kittyKeyboard
2735
+
2736
+ Type: `object`\
2737
+ Default: `undefined`
2738
+
2739
+ Enable the [kitty keyboard protocol](https://sw.kovidgoyal.net/kitty/keyboard-protocol/) for enhanced keyboard input handling. When enabled, terminals that support the protocol will report additional key information including `super`, `hyper`, `capsLock`, `numLock` modifiers and `eventType` (press/repeat/release).
2740
+
2741
+ ```jsx
2742
+ import { render } from "@alchemy.run/sigil";
2743
+
2744
+ render(<MyApp />, { kittyKeyboard: { mode: "auto" } });
2745
+ ```
2746
+
2747
+ ```jsx
2748
+ import { render } from "@alchemy.run/sigil";
2749
+
2750
+ render(<MyApp />, {
2751
+ kittyKeyboard: {
2752
+ mode: "enabled",
2753
+ flags: ["disambiguateEscapeCodes", "reportEventTypes"],
2754
+ },
2755
+ });
2756
+ ```
2757
+
2758
+ **kittyKeyboard.mode**
2759
+
2760
+ Type: `'auto' | 'enabled' | 'disabled'`\
2761
+ Default: `'auto'`
2762
+
2763
+ - `'auto'`: Detect terminal support using a heuristic precheck (known terminals like kitty, WezTerm, Ghostty) followed by a protocol query confirmation (`CSI ? u`). The protocol is only enabled if the terminal responds to the query within a short timeout.
2764
+ - `'enabled'`: Force enable the protocol. Both stdin and stdout must be TTYs.
2765
+ - `'disabled'`: Never enable the protocol.
2766
+
2767
+ **kittyKeyboard.flags**
2768
+
2769
+ Type: `string[]`\
2770
+ Default: `['disambiguateEscapeCodes']`
2771
+
2772
+ Protocol flags to request from the terminal. Pass an array of flag name strings.
2773
+
2774
+ Available flags:
2775
+
2776
+ - `'disambiguateEscapeCodes'` - Disambiguate escape codes
2777
+ - `'reportEventTypes'` - Report key press, repeat, and release events
2778
+ - `'reportAlternateKeys'` - Report alternate key encodings
2779
+ - `'reportAllKeysAsEscapeCodes'` - Report all keys as escape codes
2780
+ - `'reportAssociatedText'` - Report associated text with key events
2781
+
2782
+ **Behavior notes**
2783
+
2784
+ When the kitty keyboard protocol is enabled, input handling changes in several ways:
2785
+
2786
+ - **Non-printable keys produce empty input.** Keys like function keys (F1-F35), modifier-only keys (Shift, Control, Super), media keys, Caps Lock, Print Screen, and similar keys will not produce any text in the `input` parameter of `useInput`. They can still be detected via the `key` object properties.
2787
+ - **Ctrl+letter shortcuts work as expected.** When the terminal sends `Ctrl+letter` as codepoint 1-26 (the kitty CSI-u alternate form), `input` is set to the letter name (e.g. `'c'` for `Ctrl+C`) and `key.ctrl` is `true`. This ensures `exitOnCtrlC` and custom `Ctrl+letter` handlers continue to work regardless of which codepoint form the terminal uses.
2788
+ - **Key disambiguation.** The protocol allows the terminal to distinguish between keys that normally produce the same escape sequence. For example:
2789
+ - `Ctrl+I` vs `Tab` - without the protocol, both produce the same byte (`\x09`). With the protocol, they are reported as distinct keys.
2790
+ - `Shift+Enter` vs `Enter` - the shift modifier is correctly reported.
2791
+ - `Escape` key vs `Ctrl+[` - these are disambiguated.
2792
+ - **Event types.** With the `reportEventTypes` flag, key press, repeat, and release events are distinguished via `key.eventType`.
2793
+
2794
+ #### renderToString(tree, options?)
2795
+
2796
+ Returns: `string`
2797
+
2798
+ Render a React element to a string synchronously. Unlike `render()`, this function does not write to stdout, does not set up any terminal event listeners, and returns the rendered output as a string.
2799
+
2800
+ Useful for generating documentation, writing output to files, testing, or any scenario where you need the rendered output as a string without starting a persistent terminal application.
2801
+
2802
+ ```jsx
2803
+ import { renderToString, Text, Box } from "@alchemy.run/sigil";
2804
+
2805
+ const output = renderToString(
2806
+ <Box padding={1}>
2807
+ <Text color="green">Hello World</Text>
2808
+ </Box>,
2809
+ );
2810
+
2811
+ console.log(output);
2812
+ ```
2813
+
2814
+ **Notes:**
2815
+
2816
+ - Terminal-specific hooks (`useInput`, `useStdin`, `useStdout`, `useStderr`, `useWindowSize`, `useApp`, `useFocus`, `useFocusManager`) return default no-op values since there is no terminal session. They will not throw, but they will not function as in a live terminal.
2817
+ - `useEffect` callbacks will execute during rendering (due to synchronous rendering mode), but state updates they trigger will not affect the returned output, which reflects the initial render.
2818
+ - `useLayoutEffect` callbacks fire synchronously during commit, so state updates they trigger **will** be reflected in the output.
2819
+ - The `<Static>` component is supported — its output is prepended to the dynamic output.
2820
+ - If a component throws during rendering, the error is propagated to the caller after cleanup.
2821
+
2822
+ ##### tree
2823
+
2824
+ Type: `ReactNode`
2825
+
2826
+ ##### options
2827
+
2828
+ Type: `object`
2829
+
2830
+ ###### columns
2831
+
2832
+ Type: `number`\
2833
+ Default: `80`
2834
+
2835
+ Width of the virtual terminal in columns. Controls where text wrapping occurs.
2836
+
2837
+ ```jsx
2838
+ const output = renderToString(<Text>{"A".repeat(100)}</Text>, {
2839
+ columns: 40,
2840
+ });
2841
+ // Text wraps at 40 columns
2842
+ ```
2843
+
2844
+ #### Instance
2845
+
2846
+ This is the object that `render()` returns.
2847
+
2848
+ ##### rerender(tree)
2849
+
2850
+ Replace the previous root node with a new one or update the props of the current root node.
2851
+
2852
+ ###### tree
2853
+
2854
+ Type: `ReactNode`
2855
+
2856
+ ```jsx
2857
+ // Update props of the root node
2858
+ const { rerender } = render(<Counter count={1} />);
2859
+ rerender(<Counter count={2} />);
2860
+
2861
+ // Replace root node
2862
+ const { rerender } = render(<OldCounter />);
2863
+ rerender(<NewCounter />);
2864
+ ```
2865
+
2866
+ ##### unmount()
2867
+
2868
+ Manually unmount the whole Ink app.
2869
+
2870
+ ```jsx
2871
+ const { unmount } = render(<MyApp />);
2872
+ unmount();
2873
+ ```
2874
+
2875
+ ##### waitUntilExit()
2876
+
2877
+ Returns a promise that settles when the app is unmounted.
2878
+
2879
+ It resolves with the value passed to `exit(value)` and rejects with the error passed to `exit(error)`.
2880
+ When `unmount()` is called manually, it settles after unmount-related stdout writes complete.
2881
+
2882
+ ```jsx
2883
+ const { unmount, waitUntilExit } = render(<MyApp />);
2884
+
2885
+ setTimeout(unmount, 1000);
2886
+
2887
+ await waitUntilExit(); // resolves after `unmount()` is called
2888
+ ```
2889
+
2890
+ ##### waitUntilRenderFlush()
2891
+
2892
+ Returns a promise that settles after pending render output is flushed to stdout.
2893
+
2894
+ Useful when you need to run code only after a frame is written:
2895
+
2896
+ ```jsx
2897
+ const { rerender, waitUntilRenderFlush } = render(<MyApp step="loading" />);
2898
+
2899
+ rerender(<MyApp step="ready" />);
2900
+ await waitUntilRenderFlush(); // output for "ready" is flushed
2901
+
2902
+ runNextCommand();
2903
+ ```
2904
+
2905
+ ##### cleanup()
2906
+
2907
+ Unmount the current app and delete the internal Ink instance associated with the current `stdout`.
2908
+ This is mostly useful for advanced cases (for example, tests) where you need `render()` to create a fresh instance for the same stream.
2909
+ Unlike deleting the internal instance directly, this also tears down terminal state such as the alternate screen.
2910
+
2911
+ ##### clear()
2912
+
2913
+ Clear output.
2914
+
2915
+ ```jsx
2916
+ const { clear } = render(<MyApp />);
2917
+ clear();
2918
+ ```
2919
+
2920
+ #### measureElement(ref)
2921
+
2922
+ Measure the layout metrics of a particular `<Box>` element.
2923
+ Returns an object with `x`, `y`, `width`, and `height` properties.
2924
+
2925
+ `x` and `y` are the element's position within the live layout region, computed by walking up the layout tree. These are layout-tree coordinates, not terminal viewport coordinates. To compare them with mouse events, convert the event coordinates using the live region's viewport position. This is necessary even in alternate-screen mode when output, such as `<Static>` content, appears above the live region.
2926
+
2927
+ > [!NOTE]
2928
+ > `measureElement()` returns `{x: 0, y: 0, width: 0, height: 0}` when called during render (before layout is calculated). Call it from post-render code, such as `useEffect`, `useLayoutEffect`, input handlers, or timer callbacks. When content changes, pass the relevant dependency to your effect so it re-measures after each update.
2929
+
2930
+ ##### ref
2931
+
2932
+ Type: `MutableRef`
2933
+
2934
+ A reference to a `<Box>` element captured with the `ref` property.
2935
+ See [Refs](https://reactjs.org/docs/refs-and-the-dom.html) for more information on how to capture references.
2936
+
2937
+ ```jsx
2938
+ import { render, measureElement, Box, Text } from "@alchemy.run/sigil";
2939
+
2940
+ const Example = () => {
2941
+ const ref = useRef();
2942
+
2943
+ useEffect(() => {
2944
+ const { x, y, width, height } = measureElement(ref.current);
2945
+ // x = 0, y = 0, width = 100, height = 1
2946
+ }, []);
2947
+
2948
+ return (
2949
+ <Box width={100}>
2950
+ <Box ref={ref}>
2951
+ <Text>This box will stretch to 100 width</Text>
2952
+ </Box>
2953
+ </Box>
2954
+ );
2955
+ };
2956
+
2957
+ render(<Example />);
2958
+ ```
2959
+
2960
+ ## Testing
2961
+
2962
+ Ink components are simple to test with [ink-testing-library](https://github.com/vadimdemedes/ink-testing-library).
2963
+ Here's a simple example that checks how the component is rendered:
2964
+
2965
+ ```jsx
2966
+ import React from "react";
2967
+ import { Text } from "@alchemy.run/sigil";
2968
+ import { render } from "ink-testing-library";
2969
+
2970
+ const Test = () => <Text>Hello World</Text>;
2971
+ const { lastFrame } = render(<Test />);
2972
+
2973
+ lastFrame() === "Hello World"; //=> true
2974
+ ```
2975
+
2976
+ Check out [ink-testing-library](https://github.com/vadimdemedes/ink-testing-library) for more examples and full documentation.
2977
+
2978
+ ## Using React Devtools
2979
+
2980
+ ![](media/devtools.jpg)
2981
+
2982
+ Ink supports [React Devtools](https://github.com/facebook/react/tree/master/packages/react-devtools) out of the box. To enable integration with React Devtools in your Ink-based CLI, first ensure you have installed the optional `react-devtools-core` dependency, and then run your app with the `DEV=true` environment variable:
2983
+
2984
+ ```sh
2985
+ DEV=true my-cli
2986
+ ```
2987
+
2988
+ Then, start React Devtools itself:
2989
+
2990
+ ```sh
2991
+ npx react-devtools
2992
+ ```
2993
+
2994
+ After it starts, you should see the component tree of your CLI.
2995
+ You can even inspect and change the props of components, and see the results immediately in the CLI, without restarting it.
2996
+
2997
+ > [!NOTE]
2998
+ > You must manually quit your CLI via <kbd>Ctrl</kbd>+<kbd>C</kbd> after you're done testing.
2999
+
3000
+ ## Screen Reader Support
3001
+
3002
+ Ink has basic support for screen readers.
3003
+
3004
+ To enable it, you can either pass the `isScreenReaderEnabled` option to the `render` function or set the `INK_SCREEN_READER` environment variable to `true`.
3005
+
3006
+ Ink implements a small subset of functionality from the [ARIA specification](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA).
3007
+
3008
+ ```jsx
3009
+ render(<MyApp />, { isScreenReaderEnabled: true });
3010
+ ```
3011
+
3012
+ When screen reader support is enabled, Ink will try its best to generate a screen-reader-friendly output.
3013
+
3014
+ For example, for this code:
3015
+
3016
+ ```jsx
3017
+ <Box aria-role="checkbox" aria-state={{ checked: true }}>
3018
+ <Text>Accept terms and conditions</Text>
3019
+ </Box>
3020
+ ```
3021
+
3022
+ Ink will generate the following output for screen readers:
3023
+
3024
+ ```
3025
+ (checked) checkbox: Accept terms and conditions
3026
+ ```
3027
+
3028
+ You can also provide a custom label for screen readers if you want to render something different for them.
3029
+
3030
+ For example, if you are building a progress bar, you can use `aria-label` to provide a more descriptive label for screen readers.
3031
+
3032
+ ```jsx
3033
+ <Box>
3034
+ <Box width="50%" height={1} backgroundColor="green" />
3035
+ <Text aria-label="Progress: 50%">50%</Text>
3036
+ </Box>
3037
+ ```
3038
+
3039
+ In the example above, the screen reader will read "Progress: 50%" instead of "50%".
3040
+
3041
+ ### `aria-label`
3042
+
3043
+ Type: `string`
3044
+
3045
+ A label for the element for screen readers.
3046
+
3047
+ ### `aria-hidden`
3048
+
3049
+ Type: `boolean`\
3050
+ Default: `false`
3051
+
3052
+ Hide the element from screen readers.
3053
+
3054
+ ### `aria-role`
3055
+
3056
+ Type: `string`
3057
+
3058
+ The role of the element.
3059
+
3060
+ Supported values:
3061
+
3062
+ - `button`
3063
+ - `checkbox`
3064
+ - `combobox`
3065
+ - `list`
3066
+ - `listbox`
3067
+ - `listitem`
3068
+ - `menu`
3069
+ - `menuitem`
3070
+ - `option`
3071
+ - `progressbar`
3072
+ - `radio`
3073
+ - `radiogroup`
3074
+ - `tab`
3075
+ - `tablist`
3076
+ - `table`
3077
+ - `textbox`
3078
+ - `timer`
3079
+ - `toolbar`
3080
+
3081
+ ### `aria-state`
3082
+
3083
+ Type: `object`
3084
+
3085
+ The state of the element.
3086
+
3087
+ Supported values:
3088
+
3089
+ - `busy` (boolean)
3090
+ - `checked` (boolean)
3091
+ - `disabled` (boolean)
3092
+ - `expanded` (boolean)
3093
+ - `multiline` (boolean)
3094
+ - `multiselectable` (boolean)
3095
+ - `readonly` (boolean)
3096
+ - `required` (boolean)
3097
+ - `selected` (boolean)
3098
+
3099
+ ## Creating Components
3100
+
3101
+ When building custom components, it's important to keep accessibility in mind. While Ink provides the building blocks, ensuring your components are accessible will make your CLIs usable by a wider audience.
3102
+
3103
+ ### General Principles
3104
+
3105
+ - **Provide screen reader-friendly output:** Use the `useIsScreenReaderEnabled` hook to detect if a screen reader is active. You can then render more descriptive output for screen reader users.
3106
+ - **Leverage ARIA props:** For components that have a specific role (e.g., a checkbox or button), use the `aria-role`, `aria-state`, and `aria-label` props on `<Box>` and `<Text>` to provide semantic meaning to screen readers.
3107
+
3108
+ For a practical example of building an accessible component, see the [ARIA example](/examples/aria/aria.tsx).
3109
+
3110
+ ## Useful Components
3111
+
3112
+ - [ink-text-input](https://github.com/vadimdemedes/ink-text-input) - Text input.
3113
+ - [ink-spinner](https://github.com/vadimdemedes/ink-spinner) - Spinner.
3114
+ - [ink-select-input](https://github.com/vadimdemedes/ink-select-input) - Select (dropdown) input.
3115
+ - [ink-link](https://github.com/sindresorhus/ink-link) - Link.
3116
+ - [ink-gradient](https://github.com/sindresorhus/ink-gradient) - Gradient color.
3117
+ - [ink-big-text](https://github.com/sindresorhus/ink-big-text) - Awesome text.
3118
+ - [ink-picture](https://github.com/endernoke/ink-picture) - Display images.
3119
+ - [ink-tab](https://github.com/jdeniau/ink-tab) - Tab.
3120
+ - [ink-color-pipe](https://github.com/LitoMore/ink-color-pipe) - Create color text with simpler style strings.
3121
+ - [ink-multi-select](https://github.com/karaggeorge/ink-multi-select) - Select one or more values from a list
3122
+ - [ink-divider](https://github.com/JureSotosek/ink-divider) - A divider.
3123
+ - [ink-progress-bar](https://github.com/brigand/ink-progress-bar) - Progress bar.
3124
+ - [ink-table](https://github.com/maticzav/ink-table) - Table.
3125
+ - [ink-ascii](https://github.com/hexrcs/ink-ascii) - Awesome text component with more font choices, based on Figlet.
3126
+ - [ink-markdown](https://github.com/cameronhunter/ink-markdown) - Render syntax highlighted Markdown.
3127
+ - [ink-quicksearch-input](https://github.com/Eximchain/ink-quicksearch-input) - Select component with fast, quicksearch-like navigation.
3128
+ - [ink-confirm-input](https://github.com/kevva/ink-confirm-input) - Yes/No confirmation input.
3129
+ - [ink-syntax-highlight](https://github.com/vsashyn/ink-syntax-highlight) - Code syntax highlighting.
3130
+ - [ink-form](https://github.com/lukasbach/ink-form) - Form.
3131
+ - [ink-task-list](https://github.com/privatenumber/ink-task-list) - Task list.
3132
+ - [ink-spawn](https://github.com/kraenhansen/ink-spawn) - Spawn child processes.
3133
+ - [ink-titled-box](https://github.com/mishieck/ink-titled-box) - Box with a title.
3134
+ - [ink-chart](https://github.com/pppp606/ink-chart) - Sparkline and bar chart.
3135
+ - [ink-scroll-view](https://github.com/ByteLandTechnology/ink-scroll-view) - Scroll container.
3136
+ - [ink-scroll-list](https://github.com/ByteLandTechnology/ink-scroll-list) - Scrollable list.
3137
+ - [ink-stepper](https://github.com/archcorsair/ink-stepper) - Step-by-step wizard.
3138
+ - [ink-virtual-list](https://github.com/archcorsair/ink-virtual-list) - Virtualized list that renders only visible items for performance.
3139
+ - [ink-color-picker](https://github.com/sina-byn/ink-color-picker) - Color picker.
3140
+
3141
+ ## Useful Hooks
3142
+
3143
+ - [ink-use-stdout-dimensions](https://github.com/cameronhunter/ink-monorepo/tree/master/packages/ink-use-stdout-dimensions) - Subscribe to stdout dimensions.
3144
+
3145
+ ## Recipes
3146
+
3147
+ - [Routing with React Router](recipes/routing.md) - Navigate between routes using `MemoryRouter`.
3148
+
3149
+ ## Examples
3150
+
3151
+ The [`examples`](/examples) directory contains a set of real examples. You can run them with:
3152
+
3153
+ ```bash
3154
+ npm run example examples/[example name]
3155
+ # e.g. npm run example examples/borders
3156
+ ```
3157
+
3158
+ - [Jest](examples/jest/jest.tsx) - Implementation of basic Jest UI.
3159
+ - [Counter](examples/counter/counter.tsx) - A simple counter that increments every 100ms.
3160
+ - [Form with validation](https://github.com/final-form/rff-cli-example) - Manage form state using [Final Form](https://github.com/final-form/final-form#-final-form).
3161
+ - [Borders](examples/borders/borders.tsx) - Add borders to the `<Box>` component.
3162
+ - [Suspense](examples/suspense/suspense.tsx) - Use React Suspense.
3163
+ - [Table](examples/table/table.tsx) - Renders a table with multiple columns and rows.
3164
+ - [Focus management](examples/use-focus/use-focus.tsx) - Use the `useFocus` hook to manage focus between components.
3165
+ - [User input](examples/use-input/use-input.tsx) - Listen for user input.
3166
+ - [Write to stdout](examples/use-stdout/use-stdout.tsx) - Write to stdout, bypassing main Ink output.
3167
+ - [Write to stderr](examples/use-stderr/use-stderr.tsx) - Write to stderr, bypassing main Ink output.
3168
+ - [Static](examples/static/static.tsx) - Use the `<Static>` component to render permanent output.
3169
+ - [Child process](examples/subprocess-output) - Renders output from a child process.
3170
+ - [Router](examples/router/router.tsx) - Navigate between routes using React Router's `MemoryRouter`.
3171
+
3172
+ ## Continuous Integration
3173
+
3174
+ When running on CI (detected via the `CI` environment variable), Ink adapts its rendering:
3175
+
3176
+ - Only the last frame is rendered on exit, instead of continuously updating the terminal. This is because most CI environments don't support the ANSI escape sequences used to overwrite previous output.
3177
+ - Terminal resize events are not listened to.
3178
+
3179
+ If your CI environment supports full terminal rendering and you want to opt out of this behavior, set `CI=false`:
3180
+
3181
+ ```sh
3182
+ CI=false node my-cli.js
3183
+ ```
3184
+
3185
+ ## Maintainers
3186
+
3187
+ - [BlankParticle](https://github.com/BlankParticle) ([Functionless Corp.](https://alchemy.run))
3188
+
3189
+ ### Original Ink maintainers
3190
+
3191
+ - [Vadim Demedes](https://github.com/vadimdemedes)
3192
+ - [Sindre Sorhus](https://github.com/sindresorhus)