use-terminal-focus.ts
1 import { useContext } from 'react' 2 import 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 */ 13 export function useTerminalFocus(): boolean { 14 const { isTerminalFocused } = useContext(TerminalFocusContext) 15 return isTerminalFocused 16 }