{"name":"ink","version":"5.2.0","description":"React for CLI","license":"MIT","repository":{"type":"git","url":"git+https://github.com/vadimdemedes/ink.git"},"author":{"name":"Vadim Demedes","email":"vadimdemedes@hey.com","url":"https://github.com/vadimdemedes"},"type":"module","exports":{"types":"./build/index.d.ts","default":"./build/index.js"},"engines":{"node":">=18"},"scripts":{"dev":"tsc --watch","build":"tsc","prepare":"npm run build","test":"tsc --noEmit && xo && FORCE_COLOR=true ava","example":"NODE_NO_WARNINGS=1 node --loader ts-node/esm","benchmark":"NODE_NO_WARNINGS=1 node --loader ts-node/esm"},"keywords":["react","cli","jsx","stdout","components","command-line","preact","redux","print","render","colors","text"],"dependencies":{"@alcalzone/ansi-tokenize":"^0.1.3","ansi-escapes":"^7.0.0","ansi-styles":"^6.2.1","auto-bind":"^5.0.1","chalk":"^5.3.0","cli-boxes":"^3.0.0","cli-cursor":"^4.0.0","cli-truncate":"^4.0.0","code-excerpt":"^4.0.0","es-toolkit":"^1.22.0","indent-string":"^5.0.0","is-in-ci":"^1.0.0","patch-console":"^2.0.0","react-reconciler":"^0.29.0","scheduler":"^0.23.0","signal-exit":"^3.0.7","slice-ansi":"^7.1.0","stack-utils":"^2.0.6","string-width":"^7.2.0","type-fest":"^4.27.0","widest-line":"^5.0.0","wrap-ansi":"^9.0.0","ws":"^8.18.0","yoga-layout":"~3.2.1"},"devDependencies":{"@faker-js/faker":"^9.2.0","@sindresorhus/tsconfig":"^6.0.0","@types/benchmark":"^2.1.2","@types/ms":"^0.7.31","@types/node":"^22.9.0","@types/react":"^18.3.12","@types/react-reconciler":"^0.28.2","@types/scheduler":"^0.23.0","@types/signal-exit":"^3.0.0","@types/sinon":"^17.0.3","@types/stack-utils":"^2.0.2","@types/ws":"^8.5.13","@vdemedes/prettier-config":"^2.0.1","ava":"^5.1.1","boxen":"^8.0.1","delay":"^6.0.0","eslint-config-xo-react":"0.27.0","eslint-plugin-react":"^7.37.2","eslint-plugin-react-hooks":"^5.0.0","ms":"^2.1.3","node-pty":"^1.0.0","p-queue":"^8.0.0","prettier":"^3.3.3","react":"^18.0.0","react-devtools-core":"^5.0.0","sinon":"^19.0.2","strip-ansi":"^7.1.0","ts-node":"^10.9.2","typescript":"^5.6.3","xo":"^0.59.3"},"peerDependencies":{"@types/react":">=18.0.0","react":">=18.0.0","react-devtools-core":"^4.19.1"},"peerDependenciesMeta":{"@types/react":{"optional":true},"react-devtools-core":{"optional":true}},"ava":{"workerThreads":false,"files":["test/**/*","!test/helpers/**/*","!test/fixtures/**/*"],"extensions":{"ts":"module","tsx":"module"},"nodeArguments":["--loader=ts-node/esm"]},"xo":{"extends":["xo-react"],"plugins":["react"],"prettier":true,"rules":{"react/no-unescaped-entities":"off","react/state-in-constructor":"off","react/jsx-indent":"off","react/prop-types":"off","unicorn/import-index":"off","import/no-useless-path-segments":"off","react-hooks/exhaustive-deps":"off","complexity":"off"},"ignores":["src/parse-keypress.ts"],"overrides":[{"files":["src/**/*.{ts,tsx}","test/**/*.{ts,tsx}"],"rules":{"no-unused-expressions":"off","camelcase":["error",{"allow":["^unstable__","^internal_"]}],"unicorn/filename-case":"off","react/default-props-match-prop-types":"off","unicorn/prevent-abbreviations":"off","react/require-default-props":"off","react/jsx-curly-brace-presence":"off","@typescript-eslint/no-empty-function":"off","@typescript-eslint/promise-function-async":"warn","@typescript-eslint/explicit-function-return":"off","@typescript-eslint/explicit-function-return-type":"off","dot-notation":"off","react/boolean-prop-naming":"off","unicorn/prefer-dom-node-remove":"off","unicorn/prefer-event-target":"off"}},{"files":["examples/**/*.{ts,tsx}","benchmark/**/*.{ts,tsx}"],"rules":{"import/no-unassigned-import":"off"}}]},"prettier":"@vdemedes/prettier-config","_id":"ink@5.2.0","gitHead":"30d225f4697d8341fd7f06d5aba7c79443c5e09b","bugs":{"url":"https://github.com/vadimdemedes/ink/issues"},"homepage":"https://github.com/vadimdemedes/ink#readme","_nodeVersion":"23.6.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-gHzSBBvsh/1ZYuGi+aKzU7RwnYIr6PSz56or9T90i4DDS99euhN7nYKOMR3OTev0dKIB6Zod3vSapYzqoilQcg==","shasum":"b0c948e51cdda0afbba22747ffa6fbf9c99c6b8b","tarball":"http://registry-npm.ywwl.com/ink/download/ink-5.2.0.tgz","fileCount":137,"unpackedSize":299514,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDQcZXl7G3KX+djS7hzNBcplEufdDad5G1OT4gHaA545QIhAOX4yAbT5a0soExqVFEaPss90UA1AZi1bFqvyzdEgj2l"}],"size":70783,"noattachment":false,"key":"/ink/-/ink-5.2.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ink_5.2.0_1741515280161_0.4781590573151546"},"_hasShrinkwrap":false,"readme":"[![](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)\n\n---\n\n<div align=\"center\">\n\t<br>\n\t<br>\n\t<img width=\"240\" alt=\"Ink\" src=\"media/logo.png\">\n\t<br>\n\t<br>\n\t<br>\n</div>\n\n> React for CLIs. Build and test your CLI output using components.\n\n[![Build Status](https://github.com/vadimdemedes/ink/workflows/test/badge.svg)](https://github.com/vadimdemedes/ink/actions)\n[![npm](https://img.shields.io/npm/dm/ink?logo=npm)](https://npmjs.com/package/ink)\n\nInk provides the same component-based UI building experience that React offers in the browser, but for command-line apps.\nIt uses [Yoga](https://github.com/facebook/yoga) to build Flexbox layouts in the terminal, so most CSS-like props are available in Ink as well.\nIf you are already familiar with React, you already know Ink.\n\nSince Ink is a React renderer, it means that all features of React are supported.\nHead over to [React](https://reactjs.org) website for documentation on how to use it.\nOnly Ink's methods will be documented in this readme.\n\n**Note:** This is documentation for Ink 4 and 5. If you're looking for docs on Ink 3, check out [this release](https://github.com/vadimdemedes/ink/tree/v3.2.0).\n\n---\n\n<div align=\"center\">\n\t<p>\n\t\t<p>\n\t\t\t<sup>\n\t\t\t\t<a href=\"https://opencollective.com/vadimdemedes\">My open source work is supported by the community ❤️</a>\n\t\t\t</sup>\n\t\t</p>\n\t</p>\n</div>\n\n## Install\n\n```sh\nnpm install ink react\n```\n\n## Usage\n\n```jsx\nimport React, {useState, useEffect} from 'react';\nimport {render, Text} from 'ink';\n\nconst Counter = () => {\n\tconst [counter, setCounter] = useState(0);\n\n\tuseEffect(() => {\n\t\tconst timer = setInterval(() => {\n\t\t\tsetCounter(previousCounter => previousCounter + 1);\n\t\t}, 100);\n\n\t\treturn () => {\n\t\t\tclearInterval(timer);\n\t\t};\n\t}, []);\n\n\treturn <Text color=\"green\">{counter} tests passed</Text>;\n};\n\nrender(<Counter />);\n```\n\n<img src=\"media/demo.svg\" width=\"600\">\n\nYou can also check it out live on [repl.it sandbox](https://ink-counter-demo.vadimdemedes.repl.run/).\nFeel free to play around with the code and fork this repl at [https://repl.it/@vadimdemedes/ink-counter-demo](https://repl.it/@vadimdemedes/ink-counter-demo).\n\n## Who's Using Ink?\n\n- [GitHub Copilot for CLI](https://githubnext.com/projects/copilot-cli) - Just say what you want the shell to do.\n- [Cloudflare's Wrangler](https://github.com/cloudflare/wrangler2) - The CLI for Cloudflare Workers.\n- [Linear](https://linear.app) - Linear built an internal CLI for managing deployments, configs and other housekeeping tasks.\n- [Gatsby](https://www.gatsbyjs.org) - Gatsby is a modern web framework for blazing fast websites.\n- [tap](https://node-tap.org) - A Test-Anything-Protocol library for JavaScript.\n- [Terraform CDK](https://github.com/hashicorp/terraform-cdk) - CDK (Cloud Development Kit) for HashiCorp Terraform.\n- [Specify CLI](https://specifyapp.com) - Automate the distribution of your design tokens.\n- [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).\n- [Typewriter](https://github.com/segmentio/typewriter) - Generates strongly-typed [Segment](https://segment.com) analytics clients from arbitrary JSON Schema.\n- [Prisma](https://www.prisma.io) - The unified data layer for modern applications.\n- [Blitz](https://blitzjs.com) - The Fullstack React Framework.\n- [New York Times](https://github.com/nytimes/kyt) - NYT uses Ink `kyt` - a toolkit that encapsulates and manages the configuration for web apps.\n- [tink](https://github.com/npm/tink) - Next-generation runtime and package manager.\n- [Inkle](https://github.com/jrr/inkle) - Wordle game.\n- [loki](https://github.com/oblador/loki) - Visual regression testing for Storybook.\n- [Bit](https://github.com/teambit/bit) - Build, distribute and collaborate on components.\n- [Remirror](https://github.com/remirror/remirror) - Your friendly, world-class editor toolkit.\n- [Prime](https://github.com/birkir/prime) - Open source GraphQL CMS.\n- [emoj](https://github.com/sindresorhus/emoj) - Find relevant emojis.\n- [emma](https://github.com/maticzav/emma-cli) - Find and install npm packages.\n- [npm-check-extras](https://github.com/akgondber/npm-check-extras) - Check for outdated and unused dependencies, and run update/delete action over selected ones.\n- [swiff](https://github.com/simple-integrated-marketing/swiff) - Multi-environment command line tools for time-saving web developers.\n- [share](https://github.com/marionebl/share-cli) - Quickly share files.\n- [Kubelive](https://github.com/ameerthehacker/kubelive) - CLI for Kubernetes to provide live data about the cluster and its resources.\n- [changelog-view](https://github.com/jdeniau/changelog-view) - View changelogs.\n- [cfpush](https://github.com/mamachanko/cfpush) - An interactive Cloud Foundry tutorial.\n- [startd](https://github.com/mgrip/startd) - Turn your React component into a web app.\n- [wiki-cli](https://github.com/hexrcs/wiki-cli) - Search Wikipedia and read summaries.\n- [garson](https://github.com/goliney/garson) - Build interactive config-based command-line interfaces.\n- [git-contrib-calendar](https://github.com/giannisp/git-contrib-calendar) - Display a contributions calendar for any git repository.\n- [gitgud](https://github.com/GitGud-org/GitGud) - An interactive command-line GUI for Git.\n- [Autarky](https://github.com/pranshuchittora/autarky) - Find and delete old `node_modules` directories in order to free up disk space.\n- [fast-cli](https://github.com/sindresorhus/fast-cli) - Test your download and upload speed.\n- [tasuku](https://github.com/privatenumber/tasuku) - Minimal task runner.\n- [mnswpr](https://github.com/mordv/mnswpr) - Minesweeper game.\n- [lrn](https://github.com/krychu/lrn) - Learning by repetition.\n- [turdle](https://github.com/mynameisankit/turdle) - Wordle game.\n- [Shopify CLI](https://github.com/Shopify/cli) - Build apps, themes, and storefronts for Shopify.\n- [ToDesktop CLI](https://www.todesktop.com/electron) - An all-in-one platform for building Electron apps.\n- [Walle](https://github.com/Pobepto/walle) - Full-featured crypto wallet for EVM networks.\n- [Sudoku](https://github.com/mrozio13pl/sudoku-in-terminal) - Sudoku game.\n- [Sea Trader](https://github.com/zyishai/sea-trader) - Taipan! inspired trading simulator game.\n\n## Contents\n\n- [Getting Started](#getting-started)\n- [Components](#components)\n  - [`<Text>`](#text)\n  - [`<Box>`](#box)\n  - [`<Newline>`](#newline)\n  - [`<Spacer>`](#spacer)\n  - [`<Static>`](#static)\n  - [`<Transform>`](#transform)\n- [Hooks](#hooks)\n  - [`useInput`](#useinputinputhandler-options)\n  - [`useApp`](#useapp)\n  - [`useStdin`](#usestdin)\n  - [`useStdout`](#usestdout)\n  - [`useStderr`](#usestderr)\n  - [`useFocus`](#usefocusoptions)\n  - [`useFocusManager`](#usefocusmanager)\n- [API](#api)\n- [Testing](#testing)\n- [Using React Devtools](#using-react-devtools)\n- [Useful Components](#useful-components)\n- [Useful Hooks](#useful-hooks)\n- [Examples](#examples)\n\n## Getting Started\n\nUse [create-ink-app](https://github.com/vadimdemedes/create-ink-app) to quickly scaffold a new Ink-based CLI.\n\n```sh\nnpx create-ink-app my-ink-cli\n```\n\nAlternatively, create a TypeScript project:\n\n```sh\nnpx create-ink-app --typescript my-ink-cli\n```\n\n<details><summary>Manual JavaScript setup</summary>\n<p>\nInk requires the same Babel setup as you would do for regular React-based apps in the browser.\n\nSet up Babel with a React preset to ensure all examples in this readme work as expected.\nAfter [installing Babel](https://babeljs.io/docs/en/usage), install `@babel/preset-react` and insert the following configuration in `babel.config.json`:\n\n```sh\nnpm install --save-dev @babel/preset-react\n```\n\n```json\n{\n\t\"presets\": [\"@babel/preset-react\"]\n}\n```\n\nNext, create a file `source.js`, where you'll type code that uses Ink:\n\n```jsx\nimport React from 'react';\nimport {render, Text} from 'ink';\n\nconst Demo = () => <Text>Hello World</Text>;\n\nrender(<Demo />);\n```\n\nThen, transpile this file with Babel:\n\n```sh\nnpx babel source.js -o cli.js\n```\n\nNow you can run `cli.js` with Node.js:\n\n```sh\nnode cli\n```\n\nIf 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.\n\n</p>\n</details>\n\nInk uses [Yoga](https://github.com/facebook/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.\nIt's important to remember that each element is a Flexbox container.\nThink of it as if each `<div>` in the browser had `display: flex`.\nSee [`<Box>`](#box) built-in component below for documentation on how to use Flexbox layouts in Ink.\nNote that all text must be wrapped in a [`<Text>`](#text) component.\n\n## Components\n\n### `<Text>`\n\nThis component can display text, and change its style to make it bold, underline, italic or strikethrough.\n\n```jsx\nimport {render, Text} from 'ink';\n\nconst Example = () => (\n\t<>\n\t\t<Text color=\"green\">I am green</Text>\n\t\t<Text color=\"black\" backgroundColor=\"white\">\n\t\t\tI am black on white\n\t\t</Text>\n\t\t<Text color=\"#ffffff\">I am white</Text>\n\t\t<Text bold>I am bold</Text>\n\t\t<Text italic>I am italic</Text>\n\t\t<Text underline>I am underline</Text>\n\t\t<Text strikethrough>I am strikethrough</Text>\n\t\t<Text inverse>I am inversed</Text>\n\t</>\n);\n\nrender(<Example />);\n```\n\n**Note:** `<Text>` allows only text nodes and nested `<Text>` components inside of it. For example, `<Box>` component can't be used inside `<Text>`.\n\n#### color\n\nType: `string`\n\nChange text color.\nInk uses [chalk](https://github.com/chalk/chalk) under the hood, so all its functionality is supported.\n\n```jsx\n<Text color=\"green\">Green</Text>\n<Text color=\"#005cc5\">Blue</Text>\n<Text color=\"rgb(232, 131, 136)\">Red</Text>\n```\n\n<img src=\"media/text-color.jpg\" width=\"247\">\n\n#### backgroundColor\n\nType: `string`\n\nSame as `color` above, but for background.\n\n```jsx\n<Text backgroundColor=\"green\" color=\"white\">Green</Text>\n<Text backgroundColor=\"#005cc5\" color=\"white\">Blue</Text>\n<Text backgroundColor=\"rgb(232, 131, 136)\" color=\"white\">Red</Text>\n```\n\n<img src=\"media/text-backgroundColor.jpg\" width=\"226\">\n\n#### dimColor\n\nType: `boolean`\\\nDefault: `false`\n\nDim the color (emit a small amount of light).\n\n```jsx\n<Text color=\"red\" dimColor>\n\tDimmed Red\n</Text>\n```\n\n<img src=\"media/text-dimColor.jpg\" width=\"138\">\n\n#### bold\n\nType: `boolean`\\\nDefault: `false`\n\nMake the text bold.\n\n#### italic\n\nType: `boolean`\\\nDefault: `false`\n\nMake the text italic.\n\n#### underline\n\nType: `boolean`\\\nDefault: `false`\n\nMake the text underlined.\n\n#### strikethrough\n\nType: `boolean`\\\nDefault: `false`\n\nMake the text crossed with a line.\n\n#### inverse\n\nType: `boolean`\\\nDefault: `false`\n\nInverse background and foreground colors.\n\n```jsx\n<Text inverse color=\"yellow\">\n\tInversed Yellow\n</Text>\n```\n\n<img src=\"media/text-inverse.jpg\" width=\"138\">\n\n#### wrap\n\nType: `string`\\\nAllowed values: `wrap` `truncate` `truncate-start` `truncate-middle` `truncate-end`\\\nDefault: `wrap`\n\nThis property tells Ink to wrap or truncate text if its width is larger than container.\nIf `wrap` is passed (by default), Ink will wrap text and split it into multiple lines.\nIf `truncate-*` is passed, Ink will truncate text instead, which will result in one line of text with the rest cut off.\n\n```jsx\n<Box width={7}>\n\t<Text>Hello World</Text>\n</Box>\n//=> 'Hello\\nWorld'\n\n// `truncate` is an alias to `truncate-end`\n<Box width={7}>\n\t<Text wrap=\"truncate\">Hello World</Text>\n</Box>\n//=> 'Hello…'\n\n<Box width={7}>\n\t<Text wrap=\"truncate-middle\">Hello World</Text>\n</Box>\n//=> 'He…ld'\n\n<Box width={7}>\n\t<Text wrap=\"truncate-start\">Hello World</Text>\n</Box>\n//=> '…World'\n```\n\n### `<Box>`\n\n`<Box>` is an essential Ink component to build your layout.\nIt's like `<div style=\"display: flex\">` in the browser.\n\n```jsx\nimport {render, Box, Text} from 'ink';\n\nconst Example = () => (\n\t<Box margin={2}>\n\t\t<Text>This is a box with margin</Text>\n\t</Box>\n);\n\nrender(<Example />);\n```\n\n#### Dimensions\n\n##### width\n\nType: `number` `string`\n\nWidth of the element in spaces.\nYou can also set it in percent, which will calculate the width based on the width of parent element.\n\n```jsx\n<Box width={4}>\n\t<Text>X</Text>\n</Box>\n//=> 'X   '\n```\n\n```jsx\n<Box width={10}>\n\t<Box width=\"50%\">\n\t\t<Text>X</Text>\n\t</Box>\n\t<Text>Y</Text>\n</Box>\n//=> 'X    Y'\n```\n\n##### height\n\nType: `number` `string`\n\nHeight of the element in lines (rows).\nYou can also set it in percent, which will calculate the height based on the height of parent element.\n\n```jsx\n<Box height={4}>\n\t<Text>X</Text>\n</Box>\n//=> 'X\\n\\n\\n'\n```\n\n```jsx\n<Box height={6} flexDirection=\"column\">\n\t<Box height=\"50%\">\n\t\t<Text>X</Text>\n\t</Box>\n\t<Text>Y</Text>\n</Box>\n//=> 'X\\n\\n\\nY\\n\\n'\n```\n\n##### minWidth\n\nType: `number`\n\nSets a minimum width of the element.\nPercentages aren't supported yet, see https://github.com/facebook/yoga/issues/872.\n\n##### minHeight\n\nType: `number`\n\nSets a minimum height of the element.\nPercentages aren't supported yet, see https://github.com/facebook/yoga/issues/872.\n\n#### Padding\n\n##### paddingTop\n\nType: `number`\\\nDefault: `0`\n\nTop padding.\n\n##### paddingBottom\n\nType: `number`\\\nDefault: `0`\n\nBottom padding.\n\n##### paddingLeft\n\nType: `number`\\\nDefault: `0`\n\nLeft padding.\n\n##### paddingRight\n\nType: `number`\\\nDefault: `0`\n\nRight padding.\n\n##### paddingX\n\nType: `number`\\\nDefault: `0`\n\nHorizontal padding. Equivalent to setting `paddingLeft` and `paddingRight`.\n\n##### paddingY\n\nType: `number`\\\nDefault: `0`\n\nVertical padding. Equivalent to setting `paddingTop` and `paddingBottom`.\n\n##### padding\n\nType: `number`\\\nDefault: `0`\n\nPadding on all sides. Equivalent to setting `paddingTop`, `paddingBottom`, `paddingLeft` and `paddingRight`.\n\n```jsx\n<Box paddingTop={2}>Top</Box>\n<Box paddingBottom={2}>Bottom</Box>\n<Box paddingLeft={2}>Left</Box>\n<Box paddingRight={2}>Right</Box>\n<Box paddingX={2}>Left and right</Box>\n<Box paddingY={2}>Top and bottom</Box>\n<Box padding={2}>Top, bottom, left and right</Box>\n```\n\n#### Margin\n\n##### marginTop\n\nType: `number`\\\nDefault: `0`\n\nTop margin.\n\n##### marginBottom\n\nType: `number`\\\nDefault: `0`\n\nBottom margin.\n\n##### marginLeft\n\nType: `number`\\\nDefault: `0`\n\nLeft margin.\n\n##### marginRight\n\nType: `number`\\\nDefault: `0`\n\nRight margin.\n\n##### marginX\n\nType: `number`\\\nDefault: `0`\n\nHorizontal margin. Equivalent to setting `marginLeft` and `marginRight`.\n\n##### marginY\n\nType: `number`\\\nDefault: `0`\n\nVertical margin. Equivalent to setting `marginTop` and `marginBottom`.\n\n##### margin\n\nType: `number`\\\nDefault: `0`\n\nMargin on all sides. Equivalent to setting `marginTop`, `marginBottom`, `marginLeft` and `marginRight`.\n\n```jsx\n<Box marginTop={2}>Top</Box>\n<Box marginBottom={2}>Bottom</Box>\n<Box marginLeft={2}>Left</Box>\n<Box marginRight={2}>Right</Box>\n<Box marginX={2}>Left and right</Box>\n<Box marginY={2}>Top and bottom</Box>\n<Box margin={2}>Top, bottom, left and right</Box>\n```\n\n#### Gap\n\n#### gap\n\nType: `number`\\\nDefault: `0`\n\nSize of the gap between an element's columns and rows. Shorthand for `columnGap` and `rowGap`.\n\n```jsx\n<Box gap={1} width={3} flexWrap=\"wrap\">\n\t<Text>A</Text>\n\t<Text>B</Text>\n\t<Text>C</Text>\n</Box>\n// A B\n//\n// C\n```\n\n#### columnGap\n\nType: `number`\\\nDefault: `0`\n\nSize of the gap between an element's columns.\n\n```jsx\n<Box columnGap={1}>\n\t<Text>A</Text>\n\t<Text>B</Text>\n</Box>\n// A B\n```\n\n#### rowGap\n\nType: `number`\\\nDefault: `0`\n\nSize of the gap between element's rows.\n\n```jsx\n<Box flexDirection=\"column\" rowGap={1}>\n\t<Text>A</Text>\n\t<Text>B</Text>\n</Box>\n// A\n//\n// B\n```\n\n#### Flex\n\n##### flexGrow\n\nType: `number`\\\nDefault: `0`\n\nSee [flex-grow](https://css-tricks.com/almanac/properties/f/flex-grow/).\n\n```jsx\n<Box>\n\t<Text>Label:</Text>\n\t<Box flexGrow={1}>\n\t\t<Text>Fills all remaining space</Text>\n\t</Box>\n</Box>\n```\n\n##### flexShrink\n\nType: `number`\\\nDefault: `1`\n\nSee [flex-shrink](https://css-tricks.com/almanac/properties/f/flex-shrink/).\n\n```jsx\n<Box width={20}>\n\t<Box flexShrink={2} width={10}>\n\t\t<Text>Will be 1/4</Text>\n\t</Box>\n\t<Box width={10}>\n\t\t<Text>Will be 3/4</Text>\n\t</Box>\n</Box>\n```\n\n##### flexBasis\n\nType: `number` `string`\n\nSee [flex-basis](https://css-tricks.com/almanac/properties/f/flex-basis/).\n\n```jsx\n<Box width={6}>\n\t<Box flexBasis={3}>\n\t\t<Text>X</Text>\n\t</Box>\n\t<Text>Y</Text>\n</Box>\n//=> 'X  Y'\n```\n\n```jsx\n<Box width={6}>\n\t<Box flexBasis=\"50%\">\n\t\t<Text>X</Text>\n\t</Box>\n\t<Text>Y</Text>\n</Box>\n//=> 'X  Y'\n```\n\n##### flexDirection\n\nType: `string`\\\nAllowed values: `row` `row-reverse` `column` `column-reverse`\n\nSee [flex-direction](https://css-tricks.com/almanac/properties/f/flex-direction/).\n\n```jsx\n<Box>\n\t<Box marginRight={1}>\n\t\t<Text>X</Text>\n\t</Box>\n\t<Text>Y</Text>\n</Box>\n// X Y\n\n<Box flexDirection=\"row-reverse\">\n\t<Text>X</Text>\n\t<Box marginRight={1}>\n\t\t<Text>Y</Text>\n\t</Box>\n</Box>\n// Y X\n\n<Box flexDirection=\"column\">\n\t<Text>X</Text>\n\t<Text>Y</Text>\n</Box>\n// X\n// Y\n\n<Box flexDirection=\"column-reverse\">\n\t<Text>X</Text>\n\t<Text>Y</Text>\n</Box>\n// Y\n// X\n```\n\n##### flexWrap\n\nType: `string`\\\nAllowed values: `nowrap` `wrap` `wrap-reverse`\n\nSee [flex-wrap](https://css-tricks.com/almanac/properties/f/flex-wrap/).\n\n```jsx\n<Box width={2} flexWrap=\"wrap\">\n\t<Text>A</Text>\n\t<Text>BC</Text>\n</Box>\n// A\n// B C\n```\n\n```jsx\n<Box flexDirection=\"column\" height={2} flexWrap=\"wrap\">\n\t<Text>A</Text>\n\t<Text>B</Text>\n\t<Text>C</Text>\n</Box>\n// A C\n// B\n```\n\n##### alignItems\n\nType: `string`\\\nAllowed values: `flex-start` `center` `flex-end`\n\nSee [align-items](https://css-tricks.com/almanac/properties/a/align-items/).\n\n```jsx\n<Box alignItems=\"flex-start\">\n\t<Box marginRight={1}>\n\t\t<Text>X</Text>\n\t</Box>\n\t<Text>\n\t\tA\n\t\t<Newline/>\n\t\tB\n\t\t<Newline/>\n\t\tC\n\t</Text>\n</Box>\n// X A\n//   B\n//   C\n\n<Box alignItems=\"center\">\n\t<Box marginRight={1}>\n\t\t<Text>X</Text>\n\t</Box>\n\t<Text>\n\t\tA\n\t\t<Newline/>\n\t\tB\n\t\t<Newline/>\n\t\tC\n\t</Text>\n</Box>\n//   A\n// X B\n//   C\n\n<Box alignItems=\"flex-end\">\n\t<Box marginRight={1}>\n\t\t<Text>X</Text>\n\t</Box>\n\t<Text>\n\t\tA\n\t\t<Newline/>\n\t\tB\n\t\t<Newline/>\n\t\tC\n\t</Text>\n</Box>\n//   A\n//   B\n// X C\n```\n\n##### alignSelf\n\nType: `string`\\\nDefault: `auto`\\\nAllowed values: `auto` `flex-start` `center` `flex-end`\n\nSee [align-self](https://css-tricks.com/almanac/properties/a/align-self/).\n\n```jsx\n<Box height={3}>\n\t<Box alignSelf=\"flex-start\">\n\t\t<Text>X</Text>\n\t</Box>\n</Box>\n// X\n//\n//\n\n<Box height={3}>\n\t<Box alignSelf=\"center\">\n\t\t<Text>X</Text>\n\t</Box>\n</Box>\n//\n// X\n//\n\n<Box height={3}>\n\t<Box alignSelf=\"flex-end\">\n\t\t<Text>X</Text>\n\t</Box>\n</Box>\n//\n//\n// X\n```\n\n##### justifyContent\n\nType: `string`\\\nAllowed values: `flex-start` `center` `flex-end` `space-between` `space-around` `space-evenly`\n\nSee [justify-content](https://css-tricks.com/almanac/properties/j/justify-content/).\n\n```jsx\n<Box justifyContent=\"flex-start\">\n\t<Text>X</Text>\n</Box>\n// [X      ]\n\n<Box justifyContent=\"center\">\n\t<Text>X</Text>\n</Box>\n// [   X   ]\n\n<Box justifyContent=\"flex-end\">\n\t<Text>X</Text>\n</Box>\n// [      X]\n\n<Box justifyContent=\"space-between\">\n\t<Text>X</Text>\n\t<Text>Y</Text>\n</Box>\n// [X      Y]\n\n<Box justifyContent=\"space-around\">\n\t<Text>X</Text>\n\t<Text>Y</Text>\n</Box>\n// [  X   Y  ]\n\n<Box justifyContent=\"space-evenly\">\n\t<Text>X</Text>\n\t<Text>Y</Text>\n</Box>\n// [   X   Y   ]\n```\n\n#### Visibility\n\n##### display\n\nType: `string`\\\nAllowed values: `flex` `none`\\\nDefault: `flex`\n\nSet this property to `none` to hide the element.\n\n##### overflowX\n\nType: `string`\\\nAllowed values: `visible` `hidden`\\\nDefault: `visible`\n\nBehavior for an element's overflow in horizontal direction.\n\n##### overflowY\n\nType: `string`\\\nAllowed values: `visible` `hidden`\\\nDefault: `visible`\n\nBehavior for an element's overflow in vertical direction.\n\n##### overflow\n\nType: `string`\\\nAllowed values: `visible` `hidden`\\\nDefault: `visible`\n\nShortcut for setting `overflowX` and `overflowY` at the same time.\n\n#### Borders\n\n##### borderStyle\n\nType: `string`\\\nAllowed values: `single` `double` `round` `bold` `singleDouble` `doubleSingle` `classic` | `BoxStyle`\n\nAdd a border with a specified style.\nIf `borderStyle` is `undefined` (which it is by default), no border will be added.\nInk uses border styles from [`cli-boxes`](https://github.com/sindresorhus/cli-boxes) module.\n\n```jsx\n<Box flexDirection=\"column\">\n\t<Box>\n\t\t<Box borderStyle=\"single\" marginRight={2}>\n\t\t\t<Text>single</Text>\n\t\t</Box>\n\n\t\t<Box borderStyle=\"double\" marginRight={2}>\n\t\t\t<Text>double</Text>\n\t\t</Box>\n\n\t\t<Box borderStyle=\"round\" marginRight={2}>\n\t\t\t<Text>round</Text>\n\t\t</Box>\n\n\t\t<Box borderStyle=\"bold\">\n\t\t\t<Text>bold</Text>\n\t\t</Box>\n\t</Box>\n\n\t<Box marginTop={1}>\n\t\t<Box borderStyle=\"singleDouble\" marginRight={2}>\n\t\t\t<Text>singleDouble</Text>\n\t\t</Box>\n\n\t\t<Box borderStyle=\"doubleSingle\" marginRight={2}>\n\t\t\t<Text>doubleSingle</Text>\n\t\t</Box>\n\n\t\t<Box borderStyle=\"classic\">\n\t\t\t<Text>classic</Text>\n\t\t</Box>\n\t</Box>\n</Box>\n```\n\n<img src=\"media/box-borderStyle.jpg\" width=\"521\">\n\nAlternatively, pass a custom border style like so:\n\n```jsx\n<Box\n\tborderStyle={{\n\t\ttopLeft: '↘',\n\t\ttop: '↓',\n\t\ttopRight: '↙',\n\t\tleft: '→',\n\t\tbottomLeft: '↗',\n\t\tbottom: '↑',\n\t\tbottomRight: '↖',\n\t\tright: '←'\n\t}}\n>\n\t<Text>Custom</Text>\n</Box>\n```\n\nSee example in [examples/borders](examples/borders/borders.tsx).\n\n##### borderColor\n\nType: `string`\n\nChange border color.\nShorthand for setting `borderTopColor`, `borderRightColor`, `borderBottomColor` and `borderLeftColor`.\n\n```jsx\n<Box borderStyle=\"round\" borderColor=\"green\">\n\t<Text>Green Rounded Box</Text>\n</Box>\n```\n\n<img src=\"media/box-borderColor.jpg\" width=\"228\">\n\n##### borderTopColor\n\nType: `string`\n\nChange top border color.\nAccepts the same values as [`color`](#color) in `<Text>` component.\n\n```jsx\n<Box borderStyle=\"round\" borderTopColor=\"green\">\n\t<Text>Hello world</Text>\n</Box>\n```\n\n##### borderRightColor\n\nType: `string`\n\nChange right border color.\nAccepts the same values as [`color`](#color) in `<Text>` component.\n\n```jsx\n<Box borderStyle=\"round\" borderRightColor=\"green\">\n\t<Text>Hello world</Text>\n</Box>\n```\n\n##### borderRightColor\n\nType: `string`\n\nChange right border color.\nAccepts the same values as [`color`](#color) in `<Text>` component.\n\n```jsx\n<Box borderStyle=\"round\" borderRightColor=\"green\">\n\t<Text>Hello world</Text>\n</Box>\n```\n\n##### borderBottomColor\n\nType: `string`\n\nChange bottom border color.\nAccepts the same values as [`color`](#color) in `<Text>` component.\n\n```jsx\n<Box borderStyle=\"round\" borderBottomColor=\"green\">\n\t<Text>Hello world</Text>\n</Box>\n```\n\n##### borderLeftColor\n\nType: `string`\n\nChange left border color.\nAccepts the same values as [`color`](#color) in `<Text>` component.\n\n```jsx\n<Box borderStyle=\"round\" borderLeftColor=\"green\">\n\t<Text>Hello world</Text>\n</Box>\n```\n\n##### borderDimColor\n\nType: `boolean`\\\nDefault: `false`\n\nDim the border color.\nShorthand for setting `borderTopDimColor`, `borderBottomDimColor`, `borderLeftDimColor` and `borderRightDimColor`.\n\n```jsx\n<Box borderStyle=\"round\" borderDimColor>\n\t<Text>Hello world</Text>\n</Box>\n```\n\n##### borderTopDimColor\n\nType: `boolean`\\\nDefault: `false`\n\nDim the top border color.\n\n```jsx\n<Box borderStyle=\"round\" borderTopDimColor>\n\t<Text>Hello world</Text>\n</Box>\n```\n\n##### borderBottomDimColor\n\nType: `boolean`\\\nDefault: `false`\n\nDim the bottom border color.\n\n```jsx\n<Box borderStyle=\"round\" borderBottomDimColor>\n\t<Text>Hello world</Text>\n</Box>\n```\n\n##### borderLeftDimColor\n\nType: `boolean`\\\nDefault: `false`\n\nDim the left border color.\n\n```jsx\n<Box borderStyle=\"round\" borderLeftDimColor>\n\t<Text>Hello world</Text>\n</Box>\n```\n\n##### borderRightDimColor\n\nType: `boolean`\\\nDefault: `false`\n\nDim the right border color.\n\n```jsx\n<Box borderStyle=\"round\" borderRightDimColor>\n\t<Text>Hello world</Text>\n</Box>\n```\n\n##### borderTop\n\nType: `boolean`\\\nDefault: `true`\n\nDetermines whether top border is visible.\n\n##### borderRight\n\nType: `boolean`\\\nDefault: `true`\n\nDetermines whether right border is visible.\n\n##### borderBottom\n\nType: `boolean`\\\nDefault: `true`\n\nDetermines whether bottom border is visible.\n\n##### borderLeft\n\nType: `boolean`\\\nDefault: `true`\n\nDetermines whether left border is visible.\n\n### `<Newline>`\n\nAdds one or more newline (`\\n`) characters.\nMust be used within `<Text>` components.\n\n#### count\n\nType: `number`\\\nDefault: `1`\n\nNumber of newlines to insert.\n\n```jsx\nimport {render, Text, Newline} from 'ink';\n\nconst Example = () => (\n\t<Text>\n\t\t<Text color=\"green\">Hello</Text>\n\t\t<Newline />\n\t\t<Text color=\"red\">World</Text>\n\t</Text>\n);\n\nrender(<Example />);\n```\n\nOutput:\n\n```\nHello\nWorld\n```\n\n### `<Spacer>`\n\nA flexible space that expands along the major axis of its containing layout.\nIt's useful as a shortcut for filling all the available spaces between elements.\n\nFor 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.\n\n```jsx\nimport {render, Box, Text, Spacer} from 'ink';\n\nconst Example = () => (\n\t<Box>\n\t\t<Text>Left</Text>\n\t\t<Spacer />\n\t\t<Text>Right</Text>\n\t</Box>\n);\n\nrender(<Example />);\n```\n\nIn a vertical flex direction (`column`), it will position \"Top\" to the top of the container and push \"Bottom\" to the bottom of it.\nNote, that container needs to be tall to enough to see this in effect.\n\n```jsx\nimport {render, Box, Text, Spacer} from 'ink';\n\nconst Example = () => (\n\t<Box flexDirection=\"column\" height={10}>\n\t\t<Text>Top</Text>\n\t\t<Spacer />\n\t\t<Text>Bottom</Text>\n\t</Box>\n);\n\nrender(<Example />);\n```\n\n### `<Static>`\n\n`<Static>` component permanently renders its output above everything else.\nIt's useful for displaying activity like completed tasks or logs - things that\nare not changing after they're rendered (hence the name \"Static\").\n\nIt's preferred to use `<Static>` for use cases like these, when you can't know\nor control the amount of items that need to be rendered.\n\nFor example, [Tap](https://github.com/tapjs/node-tap) uses `<Static>` to display\na list of completed tests. [Gatsby](https://github.com/gatsbyjs/gatsby) uses it\nto display a list of generated pages, while still displaying a live progress bar.\n\n```jsx\nimport React, {useState, useEffect} from 'react';\nimport {render, Static, Box, Text} from 'ink';\n\nconst Example = () => {\n\tconst [tests, setTests] = useState([]);\n\n\tuseEffect(() => {\n\t\tlet completedTests = 0;\n\t\tlet timer;\n\n\t\tconst run = () => {\n\t\t\t// Fake 10 completed tests\n\t\t\tif (completedTests++ < 10) {\n\t\t\t\tsetTests(previousTests => [\n\t\t\t\t\t...previousTests,\n\t\t\t\t\t{\n\t\t\t\t\t\tid: previousTests.length,\n\t\t\t\t\t\ttitle: `Test #${previousTests.length + 1}`\n\t\t\t\t\t}\n\t\t\t\t]);\n\n\t\t\t\ttimer = setTimeout(run, 100);\n\t\t\t}\n\t\t};\n\n\t\trun();\n\n\t\treturn () => {\n\t\t\tclearTimeout(timer);\n\t\t};\n\t}, []);\n\n\treturn (\n\t\t<>\n\t\t\t{/* This part will be rendered once to the terminal */}\n\t\t\t<Static items={tests}>\n\t\t\t\t{test => (\n\t\t\t\t\t<Box key={test.id}>\n\t\t\t\t\t\t<Text color=\"green\">✔ {test.title}</Text>\n\t\t\t\t\t</Box>\n\t\t\t\t)}\n\t\t\t</Static>\n\n\t\t\t{/* This part keeps updating as state changes */}\n\t\t\t<Box marginTop={1}>\n\t\t\t\t<Text dimColor>Completed tests: {tests.length}</Text>\n\t\t\t</Box>\n\t\t</>\n\t);\n};\n\nrender(<Example />);\n```\n\n**Note:** `<Static>` only renders new items in `items` prop and ignores items\nthat were previously rendered. This means that when you add new items to `items`\narray, changes you make to previous items will not trigger a rerender.\n\nSee [examples/static](examples/static/static.tsx) for an example usage of `<Static>` component.\n\n#### items\n\nType: `Array`\n\nArray of items of any type to render using a function you pass as a component child.\n\n#### style\n\nType: `object`\n\nStyles to apply to a container of child elements.\nSee [`<Box>`](#box) for supported properties.\n\n```jsx\n<Static items={...} style={{padding: 1}}>\n\t{...}\n</Static>\n```\n\n#### children(item)\n\nType: `Function`\n\nFunction that is called to render every item in `items` array.\nFirst argument is an item itself and second argument is index of that item in\n`items` array.\n\nNote that `key` must be assigned to the root component.\n\n```jsx\n<Static items={['a', 'b', 'c']}>\n\t{(item, index) => {\n\t\t// This function is called for every item in ['a', 'b', 'c']\n\t\t// `item` is 'a', 'b', 'c'\n\t\t// `index` is 0, 1, 2\n\t\treturn (\n\t\t\t<Box key={index}>\n\t\t\t\t<Text>Item: {item}</Text>\n\t\t\t</Box>\n\t\t);\n\t}}\n</Static>\n```\n\n### `<Transform>`\n\nTransform a string representation of React components before they are written to output.\nFor 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).\nThese use cases can't accept React nodes as input, they are expecting a string.\nThat's what `<Transform>` component does, it gives you an output string of its child components and lets you transform it in any way.\n\n**Note:** `<Transform>` must be applied only to `<Text>` children components and shouldn't change the dimensions of the output, otherwise layout will be incorrect.\n\n```jsx\nimport {render, Transform} from 'ink';\n\nconst Example = () => (\n\t<Transform transform={output => output.toUpperCase()}>\n\t\t<Text>Hello World</Text>\n\t</Transform>\n);\n\nrender(<Example />);\n```\n\nSince `transform` function converts all characters to upper case, final output that's rendered to the terminal will be \"HELLO WORLD\", not \"Hello World\".\n\nWhen the output wraps to multiple lines, it can be helpful to know which line is being processed.\n\nFor example, to implement a hanging indent component, you can indent all the lines except for the first.\n\n```jsx\nimport {render, Transform} from 'ink';\n\nconst HangingIndent = ({content, indent = 4, children, ...props}) => (\n\t<Transform\n\t\ttransform={(line, index) =>\n\t\t\tindex === 0 ? line : ' '.repeat(indent) + line\n\t\t}\n\t\t{...props}\n\t>\n\t\t{children}\n\t</Transform>\n);\n\nconst text =\n\t'WHEN I WROTE the following pages, or rather the bulk of them, ' +\n\t'I lived alone, in the woods, a mile from any neighbor, in a ' +\n\t'house which I had built myself, on the shore of Walden Pond, ' +\n\t'in Concord, Massachusetts, and earned my living by the labor ' +\n\t'of my hands only. I lived there two years and two months. At ' +\n\t'present I am a sojourner in civilized life again.';\n\n// Other text properties are allowed as well\nrender(\n\t<HangingIndent bold dimColor indent={4}>\n\t\t{text}\n\t</HangingIndent>\n);\n```\n\n#### transform(outputLine, index)\n\nType: `Function`\n\nFunction which transforms children output.\nIt accepts children and must return transformed children too.\n\n##### children\n\nType: `string`\n\nOutput of child components.\n\n##### index\n\nType: `number`\n\nThe zero-indexed line number of the line currently being transformed.\n\n## Hooks\n\n### useInput(inputHandler, options?)\n\nThis hook is used for handling user input.\nIt's a more convenient alternative to using `useStdin` and listening to `data` events.\nThe callback you pass to `useInput` is called for each character when user enters any input.\nHowever, if 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`.\nYou can find a full example of using `useInput` at [examples/use-input](examples/use-input/use-input.tsx).\n\n```jsx\nimport {useInput} from 'ink';\n\nconst UserInput = () => {\n\tuseInput((input, key) => {\n\t\tif (input === 'q') {\n\t\t\t// Exit program\n\t\t}\n\n\t\tif (key.leftArrow) {\n\t\t\t// Left arrow key pressed\n\t\t}\n\t});\n\n\treturn …\n};\n```\n\n#### inputHandler(input, key)\n\nType: `Function`\n\nThe handler function that you pass to `useInput` receives two arguments:\n\n##### input\n\nType: `string`\n\nThe input that the program received.\n\n##### key\n\nType: `object`\n\nHandy information about a key that was pressed.\n\n###### key.leftArrow\n\n###### key.rightArrow\n\n###### key.upArrow\n\n###### key.downArrow\n\nType: `boolean`\\\nDefault: `false`\n\nIf an arrow key was pressed, the corresponding property will be `true`.\nFor example, if user presses left arrow key, `key.leftArrow` equals `true`.\n\n###### key.return\n\nType: `boolean`\\\nDefault: `false`\n\nReturn (Enter) key was pressed.\n\n###### key.escape\n\nType: `boolean`\\\nDefault: `false`\n\nEscape key was pressed.\n\n###### key.ctrl\n\nType: `boolean`\\\nDefault: `false`\n\nCtrl key was pressed.\n\n###### key.shift\n\nType: `boolean`\\\nDefault: `false`\n\nShift key was pressed.\n\n###### key.tab\n\nType: `boolean`\\\nDefault: `false`\n\nTab key was pressed.\n\n###### key.backspace\n\nType: `boolean`\\\nDefault: `false`\n\nBackspace key was pressed.\n\n###### key.delete\n\nType: `boolean`\\\nDefault: `false`\n\nDelete key was pressed.\n\n###### key.pageDown\n\n###### key.pageUp\n\nType: `boolean`\\\nDefault: `false`\n\nIf Page Up or Page Down key was pressed, the corresponding property will be `true`.\nFor example, if user presses Page Down, `key.pageDown` equals `true`.\n\n###### key.meta\n\nType: `boolean`\\\nDefault: `false`\n\n[Meta key](https://en.wikipedia.org/wiki/Meta_key) was pressed.\n\n#### options\n\nType: `object`\n\n##### isActive\n\nType: `boolean`\\\nDefault: `true`\n\nEnable or disable capturing of user input.\nUseful when there are multiple `useInput` hooks used at once to avoid handling the same input several times.\n\n### useApp()\n\n`useApp` is a React hook, which exposes a method to manually exit the app (unmount).\n\n#### exit(error?)\n\nType: `Function`\n\nExit (unmount) the whole Ink app.\n\n##### error\n\nType: `Error`\n\nOptional error. If passed, [`waitUntilExit`](waituntilexit) will reject with that error.\n\n```js\nimport {useApp} from 'ink';\n\nconst Example = () => {\n\tconst {exit} = useApp();\n\n\t// Exit the app after 5 seconds\n\tuseEffect(() => {\n\t\tsetTimeout(() => {\n\t\t\texit();\n\t\t}, 5000);\n\t}, []);\n\n\treturn …\n};\n```\n\n### useStdin()\n\n`useStdin` is a React hook, which exposes stdin stream.\n\n#### stdin\n\nType: `stream.Readable`\\\nDefault: `process.stdin`\n\nStdin stream passed to `render()` in `options.stdin` or `process.stdin` by default.\nUseful if your app needs to handle user input.\n\n```js\nimport {useStdin} from 'ink';\n\nconst Example = () => {\n\tconst {stdin} = useStdin();\n\n\treturn …\n};\n```\n\n#### isRawModeSupported\n\nType: `boolean`\n\nA boolean flag determining if the current `stdin` supports `setRawMode`.\nA component using `setRawMode` might want to use `isRawModeSupported` to nicely fall back in environments where raw mode is not supported.\n\n```jsx\nimport {useStdin} from 'ink';\n\nconst Example = () => {\n\tconst {isRawModeSupported} = useStdin();\n\n\treturn isRawModeSupported ? (\n\t\t<MyInputComponent />\n\t) : (\n\t\t<MyComponentThatDoesntUseInput />\n\t);\n};\n```\n\n#### setRawMode(isRawModeEnabled)\n\nType: `function`\n\n##### isRawModeEnabled\n\nType: `boolean`\n\nSee [`setRawMode`](https://nodejs.org/api/tty.html#tty_readstream_setrawmode_mode).\nInk 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`.\n\n**Warning:** This function will throw unless the current `stdin` supports `setRawMode`. Use [`isRawModeSupported`](#israwmodesupported) to detect `setRawMode` support.\n\n```js\nimport {useStdin} from 'ink';\n\nconst Example = () => {\n\tconst {setRawMode} = useStdin();\n\n\tuseEffect(() => {\n\t\tsetRawMode(true);\n\n\t\treturn () => {\n\t\t\tsetRawMode(false);\n\t\t};\n\t});\n\n\treturn …\n};\n```\n\n### useStdout()\n\n`useStdout` is a React hook, which exposes stdout stream, where Ink renders your app.\n\n#### stdout\n\nType: `stream.Writable`\\\nDefault: `process.stdout`\n\n```js\nimport {useStdout} from 'ink';\n\nconst Example = () => {\n\tconst {stdout} = useStdout();\n\n\treturn …\n};\n```\n\n#### write(data)\n\nWrite any string to stdout, while preserving Ink's output.\nIt's useful when you want to display some external information outside of Ink's rendering and ensure there's no conflict between the two.\nIt's similar to `<Static>`, except it can't accept components, it only works with strings.\n\n##### data\n\nType: `string`\n\nData to write to stdout.\n\n```js\nimport {useStdout} from 'ink';\n\nconst Example = () => {\n\tconst {write} = useStdout();\n\n\tuseEffect(() => {\n\t\t// Write a single message to stdout, above Ink's output\n\t\twrite('Hello from Ink to stdout\\n');\n\t}, []);\n\n\treturn …\n};\n```\n\nSee additional usage example in [examples/use-stdout](examples/use-stdout/use-stdout.tsx).\n\n### useStderr()\n\n`useStderr` is a React hook, which exposes stderr stream.\n\n#### stderr\n\nType: `stream.Writable`\\\nDefault: `process.stderr`\n\nStderr stream.\n\n```js\nimport {useStderr} from 'ink';\n\nconst Example = () => {\n\tconst {stderr} = useStderr();\n\n\treturn …\n};\n```\n\n#### write(data)\n\nWrite any string to stderr, while preserving Ink's output.\n\nIt's useful when you want to display some external information outside of Ink's rendering and ensure there's no conflict between the two.\nIt's similar to `<Static>`, except it can't accept components, it only works with strings.\n\n##### data\n\nType: `string`\n\nData to write to stderr.\n\n```js\nimport {useStderr} from 'ink';\n\nconst Example = () => {\n\tconst {write} = useStderr();\n\n\tuseEffect(() => {\n\t\t// Write a single message to stderr, above Ink's output\n\t\twrite('Hello from Ink to stderr\\n');\n\t}, []);\n\n\treturn …\n};\n```\n\n### useFocus(options?)\n\nComponent that uses `useFocus` hook becomes \"focusable\" to Ink, so when user presses <kbd>Tab</kbd>, Ink will switch focus to this component.\nIf there are multiple components that execute `useFocus` hook, focus will be given to them in the order that these components are rendered in.\nThis hook returns an object with `isFocused` boolean property, which determines if this component is focused or not.\n\n#### options\n\n##### autoFocus\n\nType: `boolean`\\\nDefault: `false`\n\nAuto focus this component, if there's no active (focused) component right now.\n\n##### isActive\n\nType: `boolean`\\\nDefault: `true`\n\nEnable or disable this component's focus, while still maintaining its position in the list of focusable components.\nThis is useful for inputs that are temporarily disabled.\n\n##### id\n\nType: `string`\\\nRequired: `false`\n\nSet 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.\n\n```jsx\nimport {render, useFocus, Text} from 'ink';\n\nconst Example = () => {\n\tconst {isFocused} = useFocus();\n\n\treturn <Text>{isFocused ? 'I am focused' : 'I am not focused'}</Text>;\n};\n\nrender(<Example />);\n```\n\nSee 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).\n\n### useFocusManager()\n\nThis hook exposes methods to enable or disable focus management for all components or manually switch focus to next or previous components.\n\n#### enableFocus()\n\nEnable focus management for all components.\n\n**Note:** You don't need to call this method manually, unless you've disabled focus management. Focus management is enabled by default.\n\n```js\nimport {useFocusManager} from 'ink';\n\nconst Example = () => {\n\tconst {enableFocus} = useFocusManager();\n\n\tuseEffect(() => {\n\t\tenableFocus();\n\t}, []);\n\n\treturn …\n};\n```\n\n#### disableFocus()\n\nDisable focus management for all components.\nCurrently active component (if there's one) will lose its focus.\n\n```js\nimport {useFocusManager} from 'ink';\n\nconst Example = () => {\n\tconst {disableFocus} = useFocusManager();\n\n\tuseEffect(() => {\n\t\tdisableFocus();\n\t}, []);\n\n\treturn …\n};\n```\n\n#### focusNext()\n\nSwitch focus to the next focusable component.\nIf there's no active component right now, focus will be given to the first focusable component.\nIf active component is the last in the list of focusable components, focus will be switched to the first active component.\n\n**Note:** Ink calls this method when user presses <kbd>Tab</kbd>.\n\n```js\nimport {useFocusManager} from 'ink';\n\nconst Example = () => {\n\tconst {focusNext} = useFocusManager();\n\n\tuseEffect(() => {\n\t\tfocusNext();\n\t}, []);\n\n\treturn …\n};\n```\n\n#### focusPrevious()\n\nSwitch focus to the previous focusable component.\nIf there's no active component right now, focus will be given to the first focusable component.\nIf active component is the first in the list of focusable components, focus will be switched to the last component.\n\n**Note:** Ink calls this method when user presses <kbd>Shift</kbd>+<kbd>Tab</kbd>.\n\n```js\nimport {useFocusManager} from 'ink';\n\nconst Example = () => {\n\tconst {focusPrevious} = useFocusManager();\n\n\tuseEffect(() => {\n\t\tfocusPrevious();\n\t}, []);\n\n\treturn …\n};\n```\n\n#### focus(id)\n\n##### id\n\nType: `string`\n\nSwitch focus to the component with the given [`id`](#id).\nIf there's no component with that ID, focus will be given to the next focusable component.\n\n```js\nimport {useFocusManager, useInput} from 'ink';\n\nconst Example = () => {\n\tconst {focus} = useFocusManager();\n\n\tuseInput(input => {\n\t\tif (input === 's') {\n\t\t\t// Focus the component with focus ID 'someId'\n\t\t\tfocus('someId');\n\t\t}\n\t});\n\n\treturn …\n};\n```\n\n## API\n\n#### render(tree, options?)\n\nReturns: [`Instance`](#instance)\n\nMount a component and render the output.\n\n##### tree\n\nType: `ReactElement`\n\n##### options\n\nType: `object`\n\n###### stdout\n\nType: `stream.Writable`\\\nDefault: `process.stdout`\n\nOutput stream where app will be rendered.\n\n###### stdin\n\nType: `stream.Readable`\\\nDefault: `process.stdin`\n\nInput stream where app will listen for input.\n\n###### exitOnCtrlC\n\nType: `boolean`\\\nDefault: `true`\n\nConfigure whether Ink should listen to Ctrl+C keyboard input and exit the app.\nThis 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 process is expected to handle it manually.\n\n###### patchConsole\n\nType: `boolean`\\\nDefault: `true`\n\nPatch console methods to ensure console output doesn't mix with Ink output.\nWhen any of `console.*` methods are called (like `console.log()`), Ink intercepts their output, clears main output, renders output from the console method and then rerenders main output again.\nThat way both are visible and are not overlapping each other.\n\nThis functionality is powered by [patch-console](https://github.com/vadimdemedes/patch-console), so if you need to disable Ink's interception of output but want to build something custom, you can use it.\n\n###### debug\n\nType: `boolean`\\\nDefault: `false`\n\nIf `true`, each update will be rendered as a separate output, without replacing the previous one.\n\n#### Instance\n\nThis is the object that `render()` returns.\n\n##### rerender(tree)\n\nReplace previous root node with a new one or update props of the current root node.\n\n###### tree\n\nType: `ReactElement`\n\n```jsx\n// Update props of the root node\nconst {rerender} = render(<Counter count={1} />);\nrerender(<Counter count={2} />);\n\n// Replace root node\nconst {rerender} = render(<OldCounter />);\nrerender(<NewCounter />);\n```\n\n##### unmount()\n\nManually unmount the whole Ink app.\n\n```jsx\nconst {unmount} = render(<MyApp />);\nunmount();\n```\n\n##### waitUntilExit()\n\nReturns a promise, which resolves when app is unmounted.\n\n```jsx\nconst {unmount, waitUntilExit} = render(<MyApp />);\n\nsetTimeout(unmount, 1000);\n\nawait waitUntilExit(); // resolves after `unmount()` is called\n```\n\n##### clear()\n\nClear output.\n\n```jsx\nconst {clear} = render(<MyApp />);\nclear();\n```\n\n#### measureElement(ref)\n\nMeasure the dimensions of a particular `<Box>` element.\nIt returns an object with `width` and `height` properties.\nThis function is useful when your component needs to know the amount of available space it has. You could use it when you need to change the layout based on the length of its content.\n\n**Note:** `measureElement()` returns correct results only after the initial render, when layout has been calculated. Until then, `width` and `height` equal to zero. It's recommended to call `measureElement()` in a `useEffect` hook, which fires after the component has rendered.\n\n##### ref\n\nType: `MutableRef`\n\nA reference to a `<Box>` element captured with a `ref` property.\nSee [Refs](https://reactjs.org/docs/refs-and-the-dom.html) for more information on how to capture references.\n\n```jsx\nimport {render, measureElement, Box, Text} from 'ink';\n\nconst Example = () => {\n\tconst ref = useRef();\n\n\tuseEffect(() => {\n\t\tconst {width, height} = measureElement(ref.current);\n\t\t// width = 100, height = 1\n\t}, []);\n\n\treturn (\n\t\t<Box width={100}>\n\t\t\t<Box ref={ref}>\n\t\t\t\t<Text>This box will stretch to 100 width</Text>\n\t\t\t</Box>\n\t\t</Box>\n\t);\n};\n\nrender(<Example />);\n```\n\n## Testing\n\nInk components are simple to test with [ink-testing-library](https://github.com/vadimdemedes/ink-testing-library).\nHere's a simple example that checks how component is rendered:\n\n```jsx\nimport React from 'react';\nimport {Text} from 'ink';\nimport {render} from 'ink-testing-library';\n\nconst Test = () => <Text>Hello World</Text>;\nconst {lastFrame} = render(<Test />);\n\nlastFrame() === 'Hello World'; //=> true\n```\n\nCheck out [ink-testing-library](https://github.com/vadimdemedes/ink-testing-library) for more examples and full documentation.\n\n## Using React Devtools\n\n![](media/devtools.jpg)\n\nInk 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 `DEV=true` environment variable:\n\n```sh\nDEV=true my-cli\n```\n\nThen, start React Devtools itself:\n\n```sh\nnpx react-devtools\n```\n\nAfter it starts up, you should see the component tree of your CLI.\nYou can even inspect and change the props of components, and see the results immediatelly in the CLI, without restarting it.\n\n**Note**: You must manually quit your CLI via <kbd>Ctrl</kbd>+<kbd>C</kbd> after you're done testing.\n\n## Useful Components\n\n- [ink-text-input](https://github.com/vadimdemedes/ink-text-input) - Text input.\n- [ink-spinner](https://github.com/vadimdemedes/ink-spinner) - Spinner.\n- [ink-select-input](https://github.com/vadimdemedes/ink-select-input) - Select (dropdown) input.\n- [ink-link](https://github.com/sindresorhus/ink-link) - Link.\n- [ink-gradient](https://github.com/sindresorhus/ink-gradient) - Gradient color.\n- [ink-big-text](https://github.com/sindresorhus/ink-big-text) - Awesome text.\n- [ink-image](https://github.com/kevva/ink-image) - Display images inside the terminal.\n- [ink-tab](https://github.com/jdeniau/ink-tab) - Tab.\n- [ink-color-pipe](https://github.com/LitoMore/ink-color-pipe) - Create color text with simpler style strings.\n- [ink-multi-select](https://github.com/karaggeorge/ink-multi-select) - Select one or more values from a list\n- [ink-divider](https://github.com/JureSotosek/ink-divider) - A divider.\n- [ink-progress-bar](https://github.com/brigand/ink-progress-bar) - Progress bar.\n- [ink-table](https://github.com/maticzav/ink-table) - Table.\n- [ink-ascii](https://github.com/hexrcs/ink-ascii) - Awesome text component with more font choices, based on Figlet.\n- [ink-markdown](https://github.com/cameronhunter/ink-markdown) - Render syntax highlighted Markdown.\n- [ink-quicksearch-input](https://github.com/Eximchain/ink-quicksearch-input) - Select component with fast quicksearch-like navigation.\n- [ink-confirm-input](https://github.com/kevva/ink-confirm-input) - Yes/No confirmation input.\n- [ink-syntax-highlight](https://github.com/vsashyn/ink-syntax-highlight) - Code syntax highlighting.\n- [ink-form](https://github.com/lukasbach/ink-form) - Form.\n- [ink-task-list](https://github.com/privatenumber/ink-task-list) - Task list.\n- [ink-spawn](https://github.com/kraenhansen/ink-spawn) - Spawn child processes.\n\n## Useful Hooks\n\n- [ink-use-stdout-dimensions](https://github.com/cameronhunter/ink-monorepo/tree/master/packages/ink-use-stdout-dimensions) - Subscribe to stdout dimensions.\n\n## Examples\n\nThe [`examples`](/examples) directory contains a set of real examples. You can run them with:\n\n```bash\nnpm run example examples/[example name]\n# e.g. npm run example examples/borders\n```\n\n- [Jest](examples/jest/jest.tsx) - Implementation of basic Jest UI [(live demo)](https://ink-jest-demo.vadimdemedes.repl.run/).\n- [Counter](examples/counter/counter.tsx) - Simple counter that increments every 100ms [(live demo)](https://ink-counter-demo.vadimdemedes.repl.run/).\n- [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).\n- [Borders](examples/borders/borders.tsx) - Add borders to `<Box>` component.\n- [Suspense](examples/suspense/suspense.tsx) - Use React Suspense.\n- [Table](examples/table/table.tsx) - Render a table with multiple columns and rows.\n- [Focus management](examples/use-focus/use-focus.tsx) - Use `useFocus` hook to manage focus between components.\n- [User input](examples/use-input/use-input.tsx) - Listen to user input.\n- [Write to stdout](examples/use-stdout/use-stdout.tsx) - Write to stdout bypassing main Ink output.\n- [Write to stderr](examples/use-stderr/use-stderr.tsx) - Write to stderr bypassing main Ink output.\n- [Static](examples/static/static.tsx) - Use `<Static>` to render permanent output.\n- [Child process](examples/subprocess-output) - Render output from a child process.\n\n## Maintainers\n\n- [Vadim Demedes](https://github.com/vadimdemedes)\n- [Sindre Sorhus](https://github.com/sindresorhus)\n","publish_time":1741515280357,"maintainers":[{"name":"vdemedes","email":"vadimdemedes@hey.com"},{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_cnpm_publish_time":1741515280357,"dist-tags":{"latest":"8.0.0","next":"3.0.0-7"}}