source dump of claude code
at main 16 lines 556 B view raw
1import { useContext } from 'react' 2import TerminalFocusContext from '../components/TerminalFocusContext.js' 3 4/** 5 * Hook to check if the terminal has focus. 6 * 7 * Uses DECSET 1004 focus reporting - the terminal sends escape sequences 8 * when it gains or loses focus. These are handled automatically 9 * by Ink and filtered from useInput. 10 * 11 * @returns true if the terminal is focused (or focus state is unknown) 12 */ 13export function useTerminalFocus(): boolean { 14 const { isTerminalFocused } = useContext(TerminalFocusContext) 15 return isTerminalFocused 16}