mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-28 11:41:04 +00:00
Some checks are pending
Qwen Code CI / Lint (GitHub Actions) (push) Waiting to run
Qwen Code CI / Lint (Javascript) (push) Waiting to run
Qwen Code CI / Lint (Shell) (push) Waiting to run
Qwen Code CI / Lint (YAML) (push) Waiting to run
Qwen Code CI / Lint (push) Blocked by required conditions
Qwen Code CI / Test (push) Blocked by required conditions
Qwen Code CI / Post Coverage Comment (push) Blocked by required conditions
Qwen Code CI / CodeQL (push) Waiting to run
E2E Tests / E2E Test (Linux) - sandbox:docker (push) Waiting to run
E2E Tests / E2E Test (Linux) - sandbox:none (push) Waiting to run
E2E Tests / E2E Test - macOS (push) Waiting to run
36 lines
943 B
TypeScript
36 lines
943 B
TypeScript
/**
|
|
* @license
|
|
* Copyright 2025 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import { useEffect } from 'react';
|
|
import type { KeypressHandler, Key } from '../contexts/KeypressContext.js';
|
|
import { useKeypressContext } from '../contexts/KeypressContext.js';
|
|
|
|
export type { Key };
|
|
|
|
/**
|
|
* A hook that listens for keypress events from stdin.
|
|
*
|
|
* @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: KeypressHandler,
|
|
{ isActive }: { isActive: boolean },
|
|
) {
|
|
const { subscribe, unsubscribe } = useKeypressContext();
|
|
|
|
useEffect(() => {
|
|
if (!isActive) {
|
|
return;
|
|
}
|
|
|
|
subscribe(onKeypress);
|
|
return () => {
|
|
unsubscribe(onKeypress);
|
|
};
|
|
}, [isActive, onKeypress, subscribe, unsubscribe]);
|
|
}
|