"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useKeypress = useKeypress;
const ink_1 = require("ink");
const react_1 = require("react");
function useKeypress({ active }, cb, deps) {
    const { stdin } = (0, ink_1.useStdin)();
    const handler = (0, react_1.useCallback)((ch, key) => {
        return cb(ch, key);
    }, deps);
    (0, react_1.useEffect)(() => {
        if (!active || !stdin)
            return undefined;
        stdin.on(`keypress`, handler);
        return () => {
            stdin.off(`keypress`, handler);
        };
    }, [
        active,
        handler,
        stdin,
    ]);
}
