cc5a02919d62ea8f0a7eff460ad5128cff568f25.svn-base
8.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
import * as React from 'react';
export interface RenderOptions {
/**
* Output stream where app will be rendered.
*
* @default process.stdout
*/
readonly stdout?: NodeJS.WriteStream;
/**
* Input stream where app will listen for input.
*
* @default process.stdin
*/
readonly stdin?: NodeJS.ReadStream;
/**
* Configure whether Ink should listen to Ctrl+C keyboard input and exit the app. This is needed in case `process.stdin` is in raw mode, because then Ctrl+C is ignored by default and process is expected to handle it manually.
*
* @default true
*/
readonly exitOnCtrlC?: boolean;
/**
* If true, each update will be rendered as a separate output, without replacing the previous one.
*
* @default false
*/
readonly debug?: boolean;
/**
* Enable experimental mode and use a new and faster reconciler and renderer.
* There should be no changes to the output. If there are, please report it.
*
* @default false
*/
readonly experimental?: boolean;
}
export type Instance = {
/**
* Replace previous root node with a new one or update props of the current root node.
*/
rerender: <Props>(tree: React.ReactElement<Props>) => void;
/**
* Manually unmount the whole Ink app.
*/
unmount: Unmount;
/**
* Returns a promise, which resolves when app is unmounted.
*/
waitUntilExit: () => Promise<void>;
};
export type Unmount = () => void;
/**
* This hook is used for handling user input.
* It's a more convienient 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 …
* };
* ```
*/
export function useInput(
inputHandler: (input: string, key: Key) => void
): void;
export interface Key {
upArrow: boolean
downArrow: boolean
leftArrow: boolean
rightArrow: boolean
return: boolean
escape: boolean
ctrl: boolean
shift: boolean
meta: boolean
}
/**
* Mount a component and render the output.
*/
export function render<Props>(
tree: React.ReactElement<Props>,
options?: NodeJS.WriteStream | RenderOptions
): Instance;
export interface ColorProps {
readonly hex?: string;
readonly hsl?: [number, number, number];
readonly hsv?: [number, number, number];
readonly hwb?: [number, number, number];
readonly rgb?: [number, number, number];
readonly keyword?: string;
readonly bgHex?: string;
readonly bgHsl?: [number, number, number];
readonly bgHsv?: [number, number, number];
readonly bgHwb?: [number, number, number];
readonly bgRgb?: [number, number, number];
readonly bgKeyword?: string;
readonly reset?: boolean;
readonly bold?: boolean;
readonly dim?: boolean;
readonly italic?: boolean;
readonly underline?: boolean;
readonly inverse?: boolean;
readonly hidden?: boolean;
readonly strikethrough?: boolean;
readonly visible?: boolean;
readonly black?: boolean;
readonly red?: boolean;
readonly green?: boolean;
readonly yellow?: boolean;
readonly blue?: boolean;
readonly magenta?: boolean;
readonly cyan?: boolean;
readonly white?: boolean;
readonly gray?: boolean;
readonly grey?: boolean;
readonly blackBright?: boolean;
readonly redBright?: boolean;
readonly greenBright?: boolean;
readonly yellowBright?: boolean;
readonly blueBright?: boolean;
readonly magentaBright?: boolean;
readonly cyanBright?: boolean;
readonly whiteBright?: boolean;
readonly bgBlack?: boolean;
readonly bgRed?: boolean;
readonly bgGreen?: boolean;
readonly bgYellow?: boolean;
readonly bgBlue?: boolean;
readonly bgMagenta?: boolean;
readonly bgCyan?: boolean;
readonly bgWhite?: boolean;
readonly bgBlackBright?: boolean;
readonly bgRedBright?: boolean;
readonly bgGreenBright?: boolean;
readonly bgYellowBright?: boolean;
readonly bgBlueBright?: boolean;
readonly bgMagentaBright?: boolean;
readonly bgCyanBright?: boolean;
readonly bgWhiteBright?: boolean;
}
/**
* The `<Color>` compoment is a simple wrapper around the `chalk` API. It supports all of the `chalk`'s methods as `props`.
*/
export const Color: React.FC<ColorProps>;
export interface BoxProps {
readonly width?: number | string;
readonly height?: number | string;
readonly minWidth?: number;
readonly minHeight?: number;
readonly paddingTop?: number;
readonly paddingBottom?: number;
readonly paddingLeft?: number;
readonly paddingRight?: number;
readonly paddingX?: number;
readonly paddingY?: number;
readonly padding?: number;
readonly marginTop?: number;
readonly marginBottom?: number;
readonly marginLeft?: number;
readonly marginRight?: number;
readonly marginX?: number;
readonly marginY?: number;
readonly margin?: number;
readonly flexGrow?: number;
readonly flexShrink?: number;
readonly flexDirection?: 'row' | 'row-reverse' | 'column' | 'column-reverse';
readonly flexBasis?: string | number;
readonly alignItems?: 'flex-start' | 'center' | 'flex-end';
readonly justifyContent?:
| 'flex-start'
| 'center'
| 'flex-end'
| 'space-between'
| 'space-around';
readonly textWrap?:
| 'wrap'
| 'truncate'
| 'truncate-start'
| 'truncate-middle'
| 'truncate-end';
}
/**
* `<Box>` it's an essential Ink component to build your layout. It's like a `<div style="display: flex">` in a browser.
*/
export const Box: React.ComponentClass<BoxProps>;
export interface TextProps {
readonly bold?: boolean;
readonly italic?: boolean;
readonly underline?: boolean;
readonly strikethrough?: boolean;
}
/**
* This component can change the style of the text, make it bold, underline, italic or strikethrough.
*/
export const Text: React.FC<TextProps>;
/**
* `<Static>` component allows permanently rendering output to stdout and preserving it across renders. Components passed to `<Static>` as children will be written to stdout only once and will never be rerendered. `<Static>` output comes first, before any other output from your components, no matter where it is in the tree. In order for this mechanism to work properly, at most one `<Static>` component must be present in your node tree and components that were rendered must never update their output. Ink will detect new children appended to `<Static>` and render them to stdout.
*
* __Note__: `<Static>` accepts only an array of children and each of them must have a unique key.
*/
export const Static: React.FC<{children: React.ReactNodeArray}>;
interface AppProps {
/**
* Exit (unmount) the whole Ink app.
*/
readonly exit: (error?: Error) => void;
}
/**
* `AppContext` is a React context, which exposes a method to manually exit the app (unmount).
*/
export const AppContext: React.Context<AppProps>;
/**
* `useApp` is a React hook, which exposes props of `AppContext`.
* ```js
* import {useApp} from 'ink';
*
* const MyApp = () => {
* const {exit} = useApp();
* };
* ```
*
* It's equivalent to consuming `AppContext` props via `AppContext.Consumer`:
*
* ```jsx
* <AppContext.Consumer>
* {({exit}) => {
* // …
* }}
* </AppContext.Consumer>
* ```
*/
export function useApp(): AppProps;
interface StdinProps {
/**
* Stdin stream passed to `render()` in `options.stdin` or `process.stdin` by default. Useful if your app needs to handle user input.
*/
readonly stdin: NodeJS.ReadStream;
/**
* A boolean flag determining if the current `stdin` supports `setRawMode`. A component using `setRawMode` might want to use `isRawModeSupported` to nicely fall back in environments where raw mode is not supported.
*/
readonly isRawModeSupported: boolean;
/**
* Ink exposes this function via own `<StdinContext>` to be able to handle Ctrl+C, that's why you should use Ink's `setRawMode` instead of `process.stdin.setRawMode`.
* If the `stdin` stream passed to Ink does not support setRawMode, this function does nothing.
*/
readonly setRawMode: NodeJS.ReadStream['setRawMode'];
}
/**
* `StdinContext` is a React context, which exposes input stream.
*/
export const StdinContext: React.Context<StdinProps>;
/**
* `useStdin` is a React hook, which exposes props of `StdinContext`.
* Similar to `useApp`, it's equivalent to consuming `StdinContext` directly.
*/
export function useStdin(): StdinProps;
interface StdoutProps {
/**
* Stdout stream passed to `render()` in `options.stdout` or `process.stdout` by default.
*/
readonly stdout: NodeJS.WriteStream;
}
/**
* `StdoutContext` is a React context, which exposes stdout stream, where Ink renders your app.
*/
export const StdoutContext: React.Context<StdoutProps>;
/**
* `useStdout` is a React hook, which exposes props of `StdoutContext`.
* Similar to `useStdout`, it's equivalent to consuming `StdoutContext` directly.
*/
export function useStdout(): StdoutProps;