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 props are available in Ink as well. If you are already familiar with React, you already know Ink.
Since Ink is a React renderer, it means that all features of React are supported. Head over to React website for documentation on how to use it. Only Ink's methods will be documented in this readme.
Note: This is documentation for Ink 4 and 5. If you're looking for docs on Ink 3, check out this release.
npm install ink react
<img src="media/demo.svg" width="600">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 />);
You can also check it out live on repl.it sandbox. Feel free to play around with the code and fork this repl at https://repl.it/@vadimdemedes/ink-counter-demo.
kyt - a toolkit that encapsulates and manages the configuration for web apps.node_modules directories in order to free up disk space.Use create-ink-app to quickly scaffold a new Ink-based CLI.
npx create-ink-app my-ink-cli
Alternatively, create a TypeScript project:
<details><summary>Manual JavaScript setup</summary> <p> Ink requires the same Babel setup as you would do for regular React-based apps in the browser.npx create-ink-app --typescript my-ink-cli
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 props 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 each <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.
<Text>This component can display text, and change its style to make it bold, underline, 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.
<img src="media/text-color.jpg" width="247"><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.
<img src="media/text-backgroundColor.jpg" width="226"><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 (emit a small amount of light).
<img src="media/text-dimColor.jpg" width="138"><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
Inverse background and foreground colors.
<img src="media/text-inverse.jpg" width="138"><Text inverse color="yellow"> Inversed Yellow </Text>
Type: string
Allowed values: wrap truncate truncate-start truncate-middle truncate-end
Default: wrap
This property tells Ink to wrap or truncate text if its width is larger than container.
If wrap is passed (by default), Ink will wrap text and split it into multiple lines.
If truncate-* is passed, Ink will truncate text instead, which will result in one line of text with the rest cut off.
<Box width={7}> <Text>Hello World</Text> </Box> //=> 'Hello\nWorld' // `truncate` is an alias to `truncate-end` <Box width={7}> <Text wrap="truncate">Hello World</Text> </Box> //=> 'Hello…' <Box width={7}> <Text wrap="truncate-middle">Hello World</Text> </Box> //=> 'He…ld' <Box width={7}> <Text wrap="truncate-start">Hello World</Text> </Box> //=> '…World'
<Box><Box> is an essential Ink component to build your layout.
It's like <div style="display: flex"> in the browser.
import {render, Box, Text} from 'ink'; const Example = () => ( <Box margin={2}> <Text>This is a box with margin</Text> </Box> ); render(<Example />);
Type: number string
Width of the element in spaces. You can also set it in percent, which will calculate the width based on the width of parent element.
<Box width={4}> <Text>X</Text> </Box> //=> 'X '
<Box width={10}> <Box width="50%"> <Text>X</Text> </Box> <Text>Y</Text> </Box> //=> 'X Y'
Type: number string
Height of the element in lines (rows). You can also set it in percent, which will calculate the height based on the height of parent element.
<Box height={4}> <Text>X</Text> </Box> //=> 'X\n\n\n'
<Box height={6} flexDirection="column"> <Box height="50%"> <Text>X</Text> </Box> <Text>Y</Text> </Box> //=> 'X\n\n\nY\n\n'
Type: number
Sets a minimum width of the element. Percentages aren't supported yet, see https://github.com/facebook/yoga/issues/872.
Type: number
Sets a minimum height of the element. Percentages aren't supported yet, see https://github.com/facebook/yoga/issues/872.
Type: number
Default: 0
Top padding.
Type: number
Default: 0
Bottom padding.
Type: number
Default: 0
Left padding.
Type: number
Default: 0
Right padding.
Type: number
Default: 0
Horizontal padding. Equivalent to setting paddingLeft and paddingRight.
Type: number
Default: 0
Vertical padding. Equivalent to setting paddingTop and paddingBottom.
Type: number
Default: 0
Padding on all sides. Equivalent to setting paddingTop, paddingBottom, paddingLeft and paddingRight.
<Box paddingTop={2}>Top</Box> <Box paddingBottom={2}>Bottom</Box> <Box paddingLeft={2}>Left</Box> <Box paddingRight={2}>Right</Box> <Box paddingX={2}>Left and right</Box> <Box paddingY={2}>Top and bottom</Box> <Box padding={2}>Top, bottom, left and right</Box>
Type: number
Default: 0
Top margin.
Type: number
Default: 0
Bottom margin.
Type: number
Default: 0
Left margin.
Type: number
Default: 0
Right margin.
Type: number
Default:


GPT充值
支持 ChatGPT Plus / Pro 充值服务,支付便捷,自动发货,售后可查。


AI 图片生成平台
GPT Image 2 是面向用户的 AI 图片生成平台,支持文生图、图生图及多模型创意工作流。


你的AI Agent团队
Vecbase 是专为 AI 团队打造的智能工作空间,将数据管理、模型协作与知识沉淀整合于一处。算法、产品与业务在同一平台无缝协同,让从数据到 AI 应用的落地更快一步。


全球首个AI音乐社区
音述AI是全球首个AI音乐社区,致力让每个人都能用音乐表达自我。音述AI提供零门槛AI创作工具,独创GETI法则帮助用户精准定义音乐风格,AI润色功能支持自动优化作品质感。音述AI支持交流讨论、二次创作与价值变现。针对中文用户的语言习惯与文化背景进行专门优化,支持国风融合、C-pop等本土音乐标签,让技术更好地承载人文表达。


阿里Qoder团队推出的桌面端AI智能体
QoderWork 是阿里推出的本地优先桌面 AI 智能体,适配 macOS14+/Windows10+,以自然语言交互实现文件管理、数据分析、AI 视觉生成、浏览器自动化等办公任务,自主拆解执行复杂工作流,数据本地运行零上传,技能市场可无限扩展,是高效的 Agentic 生产力办公助手。


一站式搞定所有学习需求
不再被海量信息淹没,开始真正理解知识。Lynote 可摘要 YouTube 视频、PDF、文章等内容。即时创建笔记,检测 AI 内容并下载资料,将您的学习效率提升 10 倍。


为AI短剧协作而生
专为AI短剧协作而生的AniShort正式发布,深度重构AI短剧全流程生产模式,整合创意策划、制作执行、实时协作、在线审片、资产复用等全链路功能,独创无限画布、双轨并行工业化工作流与Ani智能体助手,集成多款主流AI大模型,破解素材零散、版本混乱、沟通低效等行业痛点,助力3人团队效率提升800%,打造标准化、可追溯的AI短剧量产体系,是AI短剧团队协同创作、提升制作效率的核心工具。


能听懂你表达的视频模型
Seedance two是基于seedance2.0的中国大模型,支持图像、视频、音频、文本四种模态输入,表达方式更丰富,生成也更可控。


国内直接访问,限时3折
输入简单文字,生成想要的图片,纳米香蕉中文站基于 Google 模型的 AI 图片生成网站,支持文字生图、图生图。官网价格限时3折活动


职场AI,就用扣子
AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!
最新AI工具、AI资讯
独家AI资源、AI项目落地

微信扫一扫关注公众号