module System.Console.Haskeline.Internal
( debugTerminalKeys ) where
import System.Console.Haskeline (defaultSettings, outputStrLn)
import System.Console.Haskeline.Command
import System.Console.Haskeline.InputT
import System.Console.Haskeline.LineState
import System.Console.Haskeline.Monads
import System.Console.Haskeline.RunCommand
import System.Console.Haskeline.Term
debugTerminalKeys :: IO a
debugTerminalKeys = runInputT defaultSettings $ do
outputStrLn
"Press any keys to debug Haskeline's input, or ctrl-c to exit:"
rterm <- InputT ask
case termOps rterm of
Right _ -> error "debugTerminalKeys: not run in terminal mode"
Left tops -> runInputCmdT tops $ runCommandLoop tops prompt
loop emptyIM
where
loop = KeyMap $ \k -> Just $ Consumed $
(const $ do
effect (LineChange $ const ([],[]))
effect (PrintLines [show k])
setState emptyIM)
>|> keyCommand loop
prompt = stringToGraphemes "> "