1 | /**
|
2 | * Handy information about a key that was pressed.
|
3 | */
|
4 | export interface Key {
|
5 | /**
|
6 | * Up arrow key was pressed.
|
7 | */
|
8 | upArrow: boolean;
|
9 | /**
|
10 | * Down arrow key was pressed.
|
11 | */
|
12 | downArrow: boolean;
|
13 | /**
|
14 | * Left arrow key was pressed.
|
15 | */
|
16 | leftArrow: boolean;
|
17 | /**
|
18 | * Right arrow key was pressed.
|
19 | */
|
20 | rightArrow: boolean;
|
21 | /**
|
22 | * Page Down key was pressed.
|
23 | */
|
24 | pageDown: boolean;
|
25 | /**
|
26 | * Page Up key was pressed.
|
27 | */
|
28 | pageUp: boolean;
|
29 | /**
|
30 | * Return (Enter) key was pressed.
|
31 | */
|
32 | return: boolean;
|
33 | /**
|
34 | * Escape key was pressed.
|
35 | */
|
36 | escape: boolean;
|
37 | /**
|
38 | * Ctrl key was pressed.
|
39 | */
|
40 | ctrl: boolean;
|
41 | /**
|
42 | * Shift key was pressed.
|
43 | */
|
44 | shift: boolean;
|
45 | /**
|
46 | * Tab key was pressed.
|
47 | */
|
48 | tab: boolean;
|
49 | /**
|
50 | * Backspace key was pressed.
|
51 | */
|
52 | backspace: boolean;
|
53 | /**
|
54 | * Delete key was pressed.
|
55 | */
|
56 | delete: boolean;
|
57 | /**
|
58 | * [Meta key](https://en.wikipedia.org/wiki/Meta_key) was pressed.
|
59 | */
|
60 | meta: boolean;
|
61 | }
|
62 | declare type Handler = (input: string, key: Key) => void;
|
63 | interface Options {
|
64 | /**
|
65 | * Enable or disable capturing of user input.
|
66 | * Useful when there are multiple useInput hooks used at once to avoid handling the same input several times.
|
67 | *
|
68 | * @default true
|
69 | */
|
70 | isActive?: boolean;
|
71 | }
|
72 | /**
|
73 | * This hook is used for handling user input.
|
74 | * It's a more convenient alternative to using `StdinContext` and listening to `data` events.
|
75 | * The callback you pass to `useInput` is called for each character when user enters any input.
|
76 | * 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`.
|
77 | *
|
78 | * ```
|
79 | * import {useInput} from 'ink';
|
80 | *
|
81 | * const UserInput = () => {
|
82 | * useInput((input, key) => {
|
83 | * if (input === 'q') {
|
84 | * // Exit program
|
85 | * }
|
86 | *
|
87 | * if (key.leftArrow) {
|
88 | * // Left arrow key pressed
|
89 | * }
|
90 | * });
|
91 | *
|
92 | * return …
|
93 | * };
|
94 | * ```
|
95 | */
|
96 | declare const useInput: (inputHandler: Handler, options?: Options) => void;
|
97 | export default useInput;
|