🌈 React for interactive command-line apps
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.
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.)
Use create-ink-app to quickly scaffold a new Ink-based CLI.
npx create-ink-app my-ink-cliAlternatively, create a TypeScript project:
npx create-ink-app --typescript my-ink-cliInk 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.jsNow you can run cli.js with Node.js:
node cliIf 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 <div> in the browser had display: 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 <Text> component.
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.
`
useCursor position is lost after a sibling-only re-render
Support column-level incremental updates to avoid rewriting unchanged regions
Output caches are rebuilt on every render, so each frame re-tokenizes and re-measures the whole screen
`minWidth` and `maxWidth` accept percentages the docs say are unsupported
Incremental rendering does not repaint when a terminal height shrink makes the frame fill the viewport
Suggestion: Removing create-ink-app from README
Small browser/custom host entry
Input Lag, Characters Drop and Cursor position issue in languages using IME(CJK)
Native (external) memory leak on repeated render/unmount of a component using useStdin().setRawMode()
multiline simple text editor