<img width="240" alt="Ink" src="https://github.com/vadimdemedes/ink/raw/v7.1.0/media/logo.png">
React for CLIs. Build and test your CLI output using components.
Ink provides the same component-based UI building experience that React offers in the browser, but for command-line apps. It uses Yoga to build Flexbox layouts in the terminal, so most CSS-like properties are available in Ink as well. If you are already familiar with React, you already know Ink.
Since Ink is a React renderer, all features of React are supported. Head over to the React website for documentation on how to use it. Only Ink's methods are documented in this readme.
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.
<sup>
<a href="https://opencollective.com/vadimdemedes">My open source work is supported by the community ❤️</a>
</sup>
npm install ink react
[!NOTE] This readme documents the upcoming version of Ink. For the latest stable release, see Ink on npm.
import React, {useState, useEffect} from 'react';
import {render, Text} from 'ink';
const Counter = () => {
const [counter, setCounter] = useState(0);
useEffect(() => {
const timer = setInterval(() => {
setCounter(previousCounter => previousCounter + 1);
}, 100);
return () => {
clearInterval(timer);
};
}, []);
return <Text color="green">{counter} tests passed</Text>;
};
render(<Counter />);
kyt - a toolkit that encapsulates and manages the configuration for web apps.node_modules directories to free up disk space.(PRs welcome. Append new entries at the end. Repos must have 100+ stars and showcase Ink beyond a basic list picker.)
<Text><Box><Newline><Spacer><Static><Transform>useInputusePasteuseAppuseStdinuseStdoutuseBoxMetricsuseStderruseWindowSizeuseFocususeFocusManageruseCursoruseAnimationUse create-ink-app to quickly scaffold a new Ink-based CLI.
npx create-ink-app my-ink-cli
Alternatively, create a TypeScript project:
npx create-ink-app --typescript my-ink-cli
Manual JavaScript setup
Ink requires the same Babel setup as you would do for regular React-based apps in the browser.
Set up Babel with a React preset to ensure all examples in this readme work as expected.
After installing Babel, install @babel/preset-react and insert the following configuration in babel.config.json:
npm install --save-dev @babel/preset-react
{
"presets": ["@babel/preset-react"]
}
Next, create a file source.js, where you'll type code that uses Ink:
import React from 'react';
import {render, Text} from 'ink';
const Demo = () => <Text>Hello World</Text>;
render(<Demo />);
Then, transpile this file with Babel:
npx babel source.js -o cli.js
Now you can run cli.js with Node.js:
node cli
If you don't like transpiling files during development, you can use import-jsx or @esbuild-kit/esm-loader to import a JSX file and transpile it on the fly.
Ink uses 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. It's important to remember that each element is a Flexbox container. Think of it as if every `
in the browser haddisplay: flex.
See [](#box) built-in component below for documentation on how to use Flexbox layouts in Ink.
Note that all text must be wrapped in a [
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 listening on stdin, etc.). If your component tree has no async work, the app will render once and exit immediately.
To exit the app, press Ctrl+C (enabled by default via exitOnCtrlC), call exit() from useApp inside a component, or call unmount() on the object returned by render().
Use waitUntilExit() to run code after the app is unmounted:
const {waitUntilExit} = render(<MyApp />);
await waitUntilExit();
console.log('App exited');
<Text>This component can display text and change its style to make it bold, underlined, italic, or strikethrough.
import {render, Text} from 'ink';
const Example = () => (
<>
<Text color="green">I am green</Text>
<Text color="black" backgroundColor="white">
I am black on white
</Text>
<Text color="#ffffff">I am white</Text>
<Text bold>I am bold</Text>
<Text italic>I am italic</Text>
<Text underline>I am underline</Text>
<Text strikethrough>I am strikethrough</Text>
<Text inverse>I am inversed</Text>
</>
);
render(<Example />);
[!NOTE]
<Text>allows only text nodes and nested<Text>components inside of it. For example,<Box>component can't be used inside<Text>.
Type: string
Change text color. Ink uses chalk under the hood, so all its functionality is supported.
<Text color="green">Green</Text>
<Text color="#005cc5">Blue</Text>
<Text color="rgb(232, 131, 136)">Red</Text>

Type: string
Same as color above, but for background.
<Text backgroundColor="green" color="white">Green</Text>
<Text backgroundColor="#005cc5" color="white">Blue</Text>
<Text backgroundColor="rgb(232, 131, 136)" color="white">Red</Text>

Type: boolean\
Default: false
Dim the color (make it less bright).
<Text color="red" dimColor>
Dimmed Red
</Text>

Type: boolean\
Default: false
Make the text bold.
Type: boolean\
Default: false
Make the text italic.
Type: boolean\
Default: false
Make the text underlined.
Type: boolean\
Default: false
Make the text crossed with a line.
Type: boolean\
Default: false
Invert background and foreground colors.
<Text inverse color="yellow">
Inversed Yellow
</Text>

Type: string\
Allowed values: wrap hard truncate truncate-start truncate-middle truncate-end\
Default: wrap
This property tells Ink to wrap or truncate text if its width is larger than the container.
If wrap is passed (the default), Ink will wrap text