1-- Copyright 2009-2010 Corey O'Connor
3-- Right, I'm mostly guessing on these details. So, as far as I can figure:
5-- There are two input modes:
9-- Which is better? Well, depends on if you want to enter Unicode as UTF-8 or not.
11-- * 7 bit mode: UTF-8 can be input unambiguiously.
12-- * 8 bit mode: UTF-8 cannot be input. Does not require an escape delay.
14-- vty uses 7 bit mode.
16-- To differentiate between ESC and control keys that contain ESC:
17-- vty using the timing of the input to differentiate.
18-- This, I best I can figure, is what VMIN and VTIME are supposed to be for.
19-- For some reason, I don't yet know, vty implements the timing in the library.
20-- I'm not sure if this is an advantage or not!
22-- By default, the escape delay is 10000 microseconds. Which is assumed to be well above the
23-- sampling rate required to detect a keyup for a person typing 200 wpm.
24module Graphics.Vty.Input ( Key(..)
33import Graphics.Vty.Input.Data
34import Graphics.Vty.Input.Internal
35import Graphics.Vty.Input.Terminfo
37import Control.Concurrent
39import System.Console.Terminfo
41import System.Posix.Signals.Exts
42import System.Posix.Terminal
43import System.Posix.IO (stdInput)
45-- | By default, the escape delay is 10000 microseconds. Which is assumed to be well above the
46-- sampling rate required to detect a keyup for a person typing 200 wpm.
48defaultEscDelay = 10000
50-- | Set up the terminal for input. Returns a function which reads key
51-- events, and a function for shutting down the terminal access.
53-- The terminal is modified as follows:
56-- - disables software flow control on outgoing data. This stops the process from being
57-- suspended if the output terminal cannot keep up. I presume this has little effect these
58-- days. I hope this means that output will be buffered if the terminal cannot keep up. In the
59-- old days the output might of been dropped.
61-- "raw" mode is used for input.
64-- - enables keyboard combinations that result in signals. This should probably be a dynamic
68-- - input is not echod to the output. Pobably should be a dynamic option.
71-- - canonical mode (line mode) input is not used. Probably should be a dynamic option.
74-- - extended functions are disabled. Uh. Whatever these are.
76initTermInput :: Int -> Terminal -> IO (IO Event, IO ())
77initTermInput escDelay terminal = do
78 attr <- getTerminalAttributes stdInput
79 let attr' = foldl withoutMode attr [ StartStopOutput, KeyboardInterrupts
80 , EnableEcho, ProcessInput, ExtendedFunctions
82 setTerminalAttributes stdInput attr' Immediately
84 let classify_table = classify_table_for_term terminal
85 (eventChannel, shutdown_input) <- initInputForFd escDelay classify_table stdInput
86 let pokeIO = Catch $ do
87 let e = error "(getsize in input layer)"
88 setTerminalAttributes stdInput attr' Immediately
89 writeChan eventChannel (EvResize e e)
90 _ <- installHandler windowChange pokeIO Nothing
91 _ <- installHandler continueProcess pokeIO Nothing
92 let shutdown_input' = do
94 _ <- installHandler windowChange Ignore Nothing
95 _ <- installHandler continueProcess Ignore Nothing
96 setTerminalAttributes stdInput attr Immediately
97 return (readChan eventChannel, shutdown_input')
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list