Skip to content

Commit 0b4f698

Browse files
authored
Turn debugTerminalKeys into a single loop. (#111)
Make it a looped KeyCommand inside a single call to runInputCmdT, rather than calling runInputCmdT once for each character. This removes some noise by letting us clear the prompt before printing the key that was read. It also hopefully makes it closer to "real" results when entering multiple keys (e.g., holding them down).
1 parent 3214a17 commit 0b4f698

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

System/Console/Haskeline/Internal.hs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module System.Console.Haskeline.Internal
22
( debugTerminalKeys ) where
33

4-
import Control.Monad (forever)
54
import System.Console.Haskeline (defaultSettings, outputStrLn)
65
import System.Console.Haskeline.Command
76
import System.Console.Haskeline.InputT
@@ -19,16 +18,20 @@ import System.Console.Haskeline.Term
1918
-- Haskeline's behavior may be modified by editing your @~/.haskeline@
2019
-- file. For details, see: <https://github.com/judah/haskeline/wiki/CustomKeyBindings>
2120
--
22-
debugTerminalKeys :: IO ()
21+
debugTerminalKeys :: IO a
2322
debugTerminalKeys = runInputT defaultSettings $ do
2423
outputStrLn
2524
"Press any keys to debug Haskeline's input, or ctrl-c to exit:"
2625
rterm <- InputT ask
2726
case termOps rterm of
2827
Right _ -> error "debugTerminalKeys: not run in terminal mode"
29-
Left tops -> forever $ getKey tops >>= outputStrLn . show
28+
Left tops -> runInputCmdT tops $ runCommandLoop tops prompt
29+
loop emptyIM
3030
where
31-
getKey tops = runInputCmdT tops
32-
$ runCommandLoop tops prompt getKeyCmd emptyIM
33-
getKeyCmd = KeyMap $ \k -> Just $ Consumed $ const $ return k
31+
loop = KeyMap $ \k -> Just $ Consumed $
32+
(const $ do
33+
effect (LineChange $ const ([],[]))
34+
effect (PrintLines [show k])
35+
setState emptyIM)
36+
>|> keyCommand loop
3437
prompt = stringToGraphemes "> "

0 commit comments

Comments
 (0)