/// import EventEmitter from "events"; import React, { FC } from "react"; import { Pair } from "../lang-utils/core"; import { Option } from "../lang-utils/rust-lang-utils"; import { IsActive } from "../tui-core"; import { Keypress } from "./keypress"; /** Ink has a hook that is supposed to be used to get user input from the keyboard called `useInput`, which comes from the `ink` package. `TextInput` is built on top of this hook. `TextInput` comes from the npm package `ink-text-input`. 1. [useInput sets raw mode to false](https://github.com/vadimdemedes/ink/blob/master/src/hooks/use-input.ts#L126) 2. [TextInput uses useInput](https://github.com/vadimdemedes/ink-text-input/blob/master/source/index.tsx#L117) The `useKeyboard` hook makes some assumptions. 1. It will set raw mode to true when used. 2. It will turn raw mode to false when unmounted. The problem w/ `TextInput` using `useInput` and then turning raw mode to off when focus changes on `TextInput` simply causes the Node.js process to exit, since there are no active listeners attached to it 🤯. To mitigate this problem is really simple - just make sure to call `useInput(noop)` somewhere in the component that includes `TextInput`! ⚠ However, this does not get rid of the default "ctrl+c" handling, which is to exit the app (this is how useInput behaves by default). You can override it by wrapping your Ink components in a Provider, like so: ``` ``` or simply: ``` ``` */ export declare const UseKeyboardWrapper: FC<{ children?: React.ReactNode; }>; /** @deprecated Please use UseKeyboardWrapper instead. */ export declare const usePreventUseInputFromSettingRawModeToFalseAndExiting: () => void; export declare type KeyboardInputHandlerFn = (input: KeypressOption) => void; export declare const createNewShortcutToActionMap: () => ShortcutToActionMap; export declare class UseKeyboardReturnValue { readonly keyPress: KeypressOption; readonly inRawMode: boolean; constructor(keyPress: KeypressOption, inRawMode: boolean); toArray(): Pair; } export declare type ActionFn = () => void; export declare type Shortcut = string; export declare type ShortcutToActionMap = Map; export declare type NodeKeypressTesting = { /** Replaces Node.js process.stdin keypress source. */ emitter: EventEmitter; /** Choice of event name representing keypress, to fire and listen for. */ eventName: string; }; declare type Common = { type: "fun"; matchKeypressFn: KeyboardInputHandlerFn; options: IsActive; } | { type: "map"; map: ShortcutToActionMap; options: IsActive; } | { type: "map-cached"; createShortcutsFn: () => ShortcutToActionMap; options: IsActive; }; interface UseKeyboardConfigInkCompat { type: "ink-compat"; args: Common; } interface UseKeyboardConfigNodeKeypress { type: "node-keypress"; args: Common; testing?: NodeKeypressTesting; } export declare type UseKeyboardConfig = UseKeyboardConfigInkCompat | UseKeyboardConfigNodeKeypress; export declare const useKeyboardBuilder: (config: UseKeyboardConfig) => UseKeyboardReturnValue; export declare type KeypressOption = Option>; /** * @return [keyPress, inRawMode] - inRawMode is false means keyboard input is disabled in * terminal. keyPress is the key that the user pressed (eg: "ctrl+k", "backspace", "shift+A"). */ export declare const useKeyboard: (processKeypressFn: KeyboardInputHandlerFn, options?: IsActive, testing?: NodeKeypressTesting | undefined) => UseKeyboardReturnValue; /** * @return [keyPress, inRawMode] - inRawMode is false means keyboard input is disabled in * terminal. keyPress is the key that the user pressed (eg: "ctrl+k", "backspace", "shift+A"). */ export declare const useKeyboardWithMap: (map: ShortcutToActionMap, options?: IsActive, testing?: NodeKeypressTesting | undefined) => UseKeyboardReturnValue; /** * @return [keyPress, inRawMode] - inRawMode is false means keyboard input is disabled in * terminal. keyPress is the key that the user pressed (eg: "ctrl+k", "backspace", "shift+A"). */ export declare const useKeyboardWithMapCached: (createMapFn: () => ShortcutToActionMap, options?: IsActive, testing?: NodeKeypressTesting | undefined) => UseKeyboardReturnValue; /** * @return [keyPress, inRawMode] - inRawMode is false means keyboard input is disabled in * terminal. keyPress is the key that the user pressed (eg: "ctrl+k", "backspace", "shift+A"). */ export declare const useKeyboardCompatInk: (processKeypressFn: KeyboardInputHandlerFn, options?: IsActive) => UseKeyboardReturnValue; /** * @return [keyPress, inRawMode] - inRawMode is false means keyboard input is disabled in * terminal. keyPress is the key that the user pressed (eg: "ctrl+k", "backspace", "shift+A"). */ export declare const useKeyboardCompatInkWithMap: (map: ShortcutToActionMap, options?: IsActive) => UseKeyboardReturnValue; /** * @return [keyPress, inRawMode] - inRawMode is false means keyboard input is disabled in * terminal. keyPress is the key that the user pressed (eg: "ctrl+k", "backspace", "shift+A"). */ export declare const useKeyboardCompatInkWithMapCached: (createMapFn: () => ShortcutToActionMap, options?: IsActive) => UseKeyboardReturnValue; export {};