/** * Handy information about a key that was pressed. */ export interface Key { /** * Up arrow key was pressed. */ upArrow: boolean; /** * Down arrow key was pressed. */ downArrow: boolean; /** * Left arrow key was pressed. */ leftArrow: boolean; /** * Right arrow key was pressed. */ rightArrow: boolean; /** * Page Down key was pressed. */ pageDown: boolean; /** * Page Up key was pressed. */ pageUp: boolean; /** * Home key was pressed. */ home: boolean; /** * End key was pressed. */ end: boolean; /** * Return (Enter) key was pressed. */ return: boolean; /** * Escape key was pressed. */ escape: boolean; /** * Ctrl key was pressed. */ ctrl: boolean; /** * Shift key was pressed. */ shift: boolean; /** * Tab key was pressed. */ tab: boolean; /** * Backspace key was pressed. */ backspace: boolean; /** * Delete key was pressed. */ delete: boolean; /** * [Meta key](https://en.wikipedia.org/wiki/Meta_key) was pressed. */ meta: boolean; } /** * Handler function for input events. */ export type InputHandler = (input: string, key: Key) => void; /** * Options for useInput hook. */ export interface InputOptions { /** * Enable or disable capturing of user input. Useful when there are * multiple `useInput` hooks used at once to avoid handling same input. * * @defaultValue true */ isActive?: boolean; } /** * This hook is used for handling user input. It's a more convenient * alternative to using `StdinContext` and listening for `data` events. * The callback you pass to `useInput` is called for each character when the * user enters any input. If the user pastes text, callback is called once * with the whole string passed as `input`. * * @example * ```tsx * import {render, useInput} from 'tinky'; * * const UserInput = () => { * useInput((input, key) => { * if (input === 'q') { * // Exit program * } * * if (key.leftArrow) { * // Left arrow key pressed * } * }); * * return null; * }; * * render(); * ``` * * @param inputHandler - The function to call when input is received. * @param options - Configuration options. */ export declare const useInput: (inputHandler: InputHandler, options?: InputOptions) => void;