Download packages/cli/src/ui/hooks/useFlickerDetector.ts from SaylorTwift/gemini-cli: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/SaylorTwift/gemini-cli/resolve/main/packages/cli/src/ui/hooks/useFlickerDetector.ts
- Command line
-
hf download hf://SaylorTwift/gemini-cli/packages/cli/src/ui/hooks/useFlickerDetector.ts
-
curl -L -o useFlickerDetector.ts https://huggingface.co/SaylorTwift/gemini-cli/resolve/main/packages/cli/src/ui/hooks/useFlickerDetector.ts
1.29 kB
| /** | |
| * @license | |
| * Copyright 2025 Google LLC | |
| * SPDX-License-Identifier: Apache-2.0 | |
| */ | |
| import { type DOMElement, measureElement } from 'ink'; | |
| import { useEffect } from 'react'; | |
| import { useConfig } from '../contexts/ConfigContext.js'; | |
| import { recordFlickerFrame } from '@google/gemini-cli-core'; | |
| import { appEvents, AppEvent } from '../../utils/events.js'; | |
| import { useUIState } from '../contexts/UIStateContext.js'; | |
| /** | |
| * A hook that detects when the UI flickers (renders taller than the terminal). | |
| * This is a sign of a rendering bug that should be fixed. | |
| * | |
| * @param rootUiRef A ref to the root UI element. | |
| * @param terminalHeight The height of the terminal. | |
| */ | |
| export function useFlickerDetector( | |
| rootUiRef: React.RefObject<DOMElement | null>, | |
| terminalHeight: number, | |
| ) { | |
| const config = useConfig(); | |
| const { constrainHeight } = useUIState(); | |
| useEffect(() => { | |
| if (rootUiRef.current) { | |
| const measurement = measureElement(rootUiRef.current); | |
| if (measurement.height > terminalHeight) { | |
| // If we are not constraining the height, we are intentionally | |
| // overflowing the screen. | |
| if (!constrainHeight) { | |
| return; | |
| } | |
| recordFlickerFrame(config); | |
| appEvents.emit(AppEvent.Flicker); | |
| } | |
| } | |
| }); | |
| } | |