module Graphics.Vty.Input.Focus
( requestFocusEvents
, disableFocusEvents
, isFocusEvent
, classifyFocusEvent
)
where
import Graphics.Vty.Input.Events
import Graphics.Vty.Input.Classify.Types
import Graphics.Vty.Input.Classify.Parse
import Control.Monad.State
import Data.List (isPrefixOf)
requestFocusEvents :: String
requestFocusEvents = "\ESC[?1004h"
disableFocusEvents :: String
disableFocusEvents = "\ESC[?1004l"
isFocusEvent :: String -> Bool
isFocusEvent s = isPrefixOf focusIn s ||
isPrefixOf focusOut s
focusIn :: String
focusIn = "\ESC[I"
focusOut :: String
focusOut = "\ESC[O"
classifyFocusEvent :: String -> KClass
classifyFocusEvent s = runParser s $ do
when (not $ isFocusEvent s) failParse
expectChar '\ESC'
expectChar '['
ty <- readChar
case ty of
'I' -> return EvGainedFocus
'O' -> return EvLostFocus
_ -> failParse