ink
Type Aliases
AppProps
AppProps:
object
Type declaration
Name | Type | Description |
---|---|---|
|
( |
Exit (unmount) the whole Ink app. |
BoxProps
BoxProps:
Except
<Styles
,"textWrap"
>
DOMElement
DOMElement:
object
&InkNode
Type declaration
Name | Type |
---|---|
|
|
|
|
|
|
|
|
|
|
|
() => |
|
() => |
|
() => |
|
Instance
Instance:
object
Type declaration
Name | Type | Description |
---|---|---|
|
() => |
‐ |
|
() => |
Clear output. |
|
|
Replace previous root node with a new one or update props of the current root node. |
|
|
Manually unmount the whole Ink app. |
|
|
Returns a promise, which resolves when app is unmounted. |
Key
Key:
object
Handy information about a key that was pressed.
Type declaration
Name | Type | Description |
---|---|---|
|
|
Backspace key was pressed. |
|
|
Ctrl key was pressed. |
|
|
Delete key was pressed. |
|
|
Down arrow key was pressed. |
|
|
Escape key was pressed. |
|
|
Left arrow key was pressed. |
|
|
Meta key was pressed. |
|
|
Page Down key was pressed. |
|
|
Page Up key was pressed. |
|
|
Return (Enter) key was pressed. |
|
|
Right arrow key was pressed. |
|
|
Shift key was pressed. |
|
|
Tab key was pressed. |
|
|
Up arrow key was pressed. |
NewlineProps
NewlineProps:
object
Type declaration
Name | Type | Description |
---|---|---|
|
|
Number of newlines to insert. Default
|
RenderOptions
RenderOptions:
object
Type declaration
Name | Type | Description |
---|---|---|
|
|
If true, each update will be rendered as a separate output, without replacing the previous one. Default
|
|
|
Configure whether Ink should listen to Ctrl+C keyboard input and exit the app. This is needed in case Default
|
|
|
Patch console methods to ensure console output doesn't mix with Ink output. Default
|
|
|
Error stream. Default
|
|
|
Input stream where app will listen for input. Default
|
|
|
Output stream where app will be rendered. Default
|
StaticProps<T>
StaticProps<
T
>:object
Type Parameters
Type Parameter |
---|
|
Type declaration
Name | Type | Description |
---|---|---|
|
( |
Function that is called to render every item in |
|
|
Array of items of any type to render using a function you pass as a component child. |
|
|
Styles to apply to a container of child elements. See |
StderrProps
StderrProps:
object
Type declaration
Name | Type | Description |
---|---|---|
|
|
Stderr stream passed to |
|
( |
Write any string to stderr, while preserving Ink's output.
It's useful when you want to display some external information outside of Ink's rendering and ensure there's no conflict between the two.
It's similar to |
StdinProps
StdinProps:
object
Type declaration
Name | Type | Description |
---|---|---|
|
|
‐ |
|
|
‐ |
|
|
A boolean flag determining if the current |
|
( |
Ink exposes this function via own |
|
|
Stdin stream passed to |
StdoutProps
StdoutProps:
object
Type declaration
Name | Type | Description |
---|---|---|
|
|
Stdout stream passed to |
|
( |
Write any string to stdout, while preserving Ink's output.
It's useful when you want to display some external information outside of Ink's rendering and ensure there's no conflict between the two.
It's similar to |
TextProps
TextProps:
object
Type declaration
Name | Type | Description |
---|---|---|
|
|
Same as |
|
|
Make the text bold. |
|
|
‐ |
|
|
Change text color. Ink uses chalk under the hood, so all its functionality is supported. |
|
|
Dim the color (emit a small amount of light). |
|
|
Inverse background and foreground colors. |
|
|
Make the text italic. |
|
|
Make the text crossed with a line. |
|
|
Make the text underlined. |
|
|
This property tells Ink to wrap or truncate text if its width is larger than container.
If |
TransformProps
TransformProps:
object
Type declaration
Name | Type | Description |
---|---|---|
|
( |
Function which transforms children output. It accepts children and must return transformed children too. |
|
|
‐ |
Functions
Box()
Box(
props
):ReactNode
<Box>
is an essential Ink component to build your layout. It's like <div style="display: flex">
in the browser.
Parameters
Parameter | Type |
---|---|
|
|
Returns
ReactNode
measureElement()
measureElement(
node
):Output
Measure the dimensions of a particular <Box>
element.
Parameters
Parameter | Type |
---|---|
|
Returns
Output
Newline()
Newline(
__namedParameters
):React.JSX.Element
Adds one or more newline (\n) characters. Must be used within
Parameters
Parameter | Type |
---|---|
|
Returns
React.JSX.Element
render()
render(
node
,options
?):Instance
Mount a component and render the output.
Parameters
Parameter | Type |
---|---|
|
|
|
|
Returns
Spacer()
Spacer():
React.JSX.Element
A flexible space that expands along the major axis of its containing layout. It's useful as a shortcut for filling all the available spaces between elements.
Returns
React.JSX.Element
Static()
Static<
T
>(props
):React.JSX.Element
<Static>
component permanently renders its output above everything else.
It's useful for displaying activity like completed tasks or logs - things that
are not changing after they're rendered (hence the name "Static").
It's preferred to use <Static>
for use cases like these, when you can't know
or control the amount of items that need to be rendered.
For example, Tap uses <Static>
to display
a list of completed tests. Gatsby uses it
to display a list of generated pages, while still displaying a live progress bar.
Type Parameters
Type Parameter |
---|
|
Parameters
Parameter | Type |
---|---|
|
|
Returns
React.JSX.Element
Text()
Text(
__namedParameters
):React.JSX.Element
|null
This component can display text, and change its style to make it colorful, bold, underline, italic or strikethrough.
Parameters
Parameter | Type |
---|---|
|
Returns
React.JSX.Element
| null
Transform()
Transform(
__namedParameters
):React.JSX.Element
|null
Transform a string representation of React components before they are written to output.
For example, you might want to apply a gradient to text, add a clickable link or create some text effects.
These use cases can't accept React nodes as input, they are expecting a string.
That's what
Parameters
Parameter | Type |
---|---|
|
Returns
React.JSX.Element
| null
useApp()
useApp():
AppProps
useApp
is a React hook, which exposes a method to manually exit the app (unmount).
Returns
useFocus()
useFocus(
__namedParameters
?):Output
Component that uses useFocus
hook becomes "focusable" to Ink,
so when user presses Tab, Ink will switch focus to this component.
If there are multiple components that execute useFocus
hook, focus will be
given to them in the order that these components are rendered in.
This hook returns an object with isFocused
boolean property, which
determines if this component is focused or not.
Parameters
Parameter | Type |
---|---|
|
|
Returns
Output
useFocusManager()
useFocusManager():
Output
This hook exposes methods to enable or disable focus management for all components or manually switch focus to next or previous components.
Returns
Output
useInput()
useInput(
inputHandler
,options
?):void
This hook is used for handling user input.
It's a more convenient alternative to using StdinContext
and listening to data
events.
The callback you pass to useInput
is called for each character when user enters any input.
However, 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
.
import {useInput} from 'ink';
const UserInput = () => {
useInput((input, key) => {
if (input === 'q') {
// Exit program
}
if (key.leftArrow) {
// Left arrow key pressed
}
});
return …
};
Parameters
Parameter | Type |
---|---|
|
|
|
|
Returns
void
useStderr()
useStderr():
StderrProps
useStderr
is a React hook, which exposes stderr stream.
Returns
useStdin()
useStdin():
StdinProps
useStdin
is a React hook, which exposes stdin stream.
Returns
useStdout()
useStdout():
StdoutProps
useStdout
is a React hook, which exposes stdout stream.