Download projects/gemini-cli/packages/cli/src/ui/hooks/useKeypress.ts from LevelUp2x/adaptai: direct link, hf CLI and curl.
- Browser
- Download file 943 Bytes
-
https://huggingface.co/datasets/LevelUp2x/adaptai/resolve/2147bc06c2ccf123b96f98eace2e6bf6486e7f0e/projects/gemini-cli/packages/cli/src/ui/hooks/useKeypress.ts
- Command line
-
hf download hf://datasets/LevelUp2x/adaptai@2147bc06c2ccf123b96f98eace2e6bf6486e7f0e/projects/gemini-cli/packages/cli/src/ui/hooks/useKeypress.ts
-
curl -L -o useKeypress.ts https://huggingface.co/datasets/LevelUp2x/adaptai/resolve/2147bc06c2ccf123b96f98eace2e6bf6486e7f0e/projects/gemini-cli/packages/cli/src/ui/hooks/useKeypress.ts
943 Bytes
| /** | |
| * @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]); | |
| } | |