Repository URL to install this package:
|
Version:
0.6.45 ▾
|
/**
* Hook for handling keyboard input
*/
import { useInput } from "ink";
export interface Key {
upArrow: boolean;
downArrow: boolean;
leftArrow: boolean;
rightArrow: boolean;
pageDown: boolean;
pageUp: boolean;
return: boolean;
escape: boolean;
ctrl: boolean;
shift: boolean;
tab: boolean;
backspace: boolean;
delete: boolean;
meta: boolean;
name?: string;
}
/**
* A hook that listens for keypress events.
*
* @param onKeypress - The callback function to execute on each keypress.
* @param options - Options to control the hook's behavior.
* @param options.isActive - Whether the hook should be actively listening for input.
*/
export function useKeypress(
onKeypress: (key: Key) => void,
{ isActive }: { isActive: boolean },
) {
useInput(
(_input, key) => {
onKeypress(key as Key);
},
{ isActive },
);
}