1-- | The input layer for VTY. This provides methods for initializing an 'Input' structure which can
2-- then be used to read 'Event's from the terminal.
4-- Right, brain rot trying to figure this out exactly. So, as far as I can care:
6-- There are two input modes for control sequences:
12-- Which should be used depends on the need to enter Unicode as UTF-8 or not.
14-- * 7 bit mode: UTF-8 can be input unambiguiously. The timing of ESC in the input sequence
15-- determines whether the ESC is: Individual, part of a control key sequence, part of a meta key
18-- * 8 bit mode: UTF-8 cannot be input unamboguiously AFAIK. Does not require an escape delay.
20-- vty assumes 7 bit mode. Which is the default AFAIK.
22-- 1. ESC individually: ESC byte, no bytes for control-seq-period,
23-- no bytes for meta-combo-period.
25-- 2. control keys that contain ESC in their byte sequence: ESC byte, bytes read within
26-- control-seq-period are part of the sequence. Up until the next valid input block.
28-- 3. ESC used as meta in a key combination: ESC byte, no other bytes read within
29-- control-seq-period. Bytes up until next valid input block are the input events plus meta.
31-- If the current runtime is the threaded runtime then the terminal's VMIN and VTIME parameters can
32-- be applied to implement the above rules.
33-- If the current runtime does not support forkOS then there is currently no implementation. Vty
34-- used to implement a parser which did tricky things with non-blocking reads and timers. This could
36module Graphics.Vty.Input ( Key(..)
42 , input_for_current_terminal
43 , input_for_name_and_io
47import Graphics.Vty.Input.Events
48import Graphics.Vty.Input.Internal
49import Graphics.Vty.Input.Terminfo
51import Control.Concurrent
55import qualified System.Console.Terminfo as Terminfo
56import System.Environment
57import System.Posix.Signals.Exts
58import System.Posix.Terminal
59import System.Posix.IO (stdInput)
60import System.Posix.Types (Fd)
62-- | Set up the current terminal for input.
63-- This determines the current terminal then invokes 'input_for_name_and_io'
64input_for_current_terminal :: Config -> IO Input
65input_for_current_terminal config = do
66 term_name <- getEnv "TERM"
67 input_for_name_and_io config term_name stdInput
69-- | Set up the terminal attached to the given Fd for input. Returns a 'Input'.
71-- The terminal is modified as follows:
74-- - disables software flow control on outgoing data. This stops the process from being
75-- suspended if the output terminal cannot keep up. I presume this has little effect these
76-- days. I hope this means that output will be buffered if the terminal cannot keep up. In the
77-- old days the output might of been dropped?
79-- "raw" mode is used for input.
82-- - enables keyboard combinations that result in signals. This should probably be a dynamic
86-- - input is not echod to the output. Pobably should be a dynamic option.
89-- - canonical mode (line mode) input is not used. Probably should be a dynamic option.
92-- - extended functions are disabled. Uh. Whatever these are.
94input_for_name_and_io :: Config -> String -> Fd -> IO Input
95input_for_name_and_io config term_name term_fd = do
96 terminal <- Terminfo.setupTerm term_name
97 attr <- getTerminalAttributes term_fd
98 let attr' = foldl withoutMode attr [ StartStopOutput, KeyboardInterrupts
99 , EnableEcho, ProcessInput, ExtendedFunctions
101 setTerminalAttributes term_fd attr' Immediately
102 let classify_table = classify_table_for_term term_name terminal
103 apply_timing_config term_fd config
104 input <- newIORef config >>= \ref -> initInputForFd ref classify_table term_fd
105 let pokeIO = Catch $ do
106 let e = error "(getsize in input layer)"
107 setTerminalAttributes term_fd attr' Immediately
108 writeChan (_event_channel input) (EvResize e e)
109 _ <- installHandler windowChange pokeIO Nothing
110 _ <- installHandler continueProcess pokeIO Nothing
112 { shutdown_input = do
114 _ <- installHandler windowChange Ignore Nothing
115 _ <- installHandler continueProcess Ignore Nothing
116 setTerminalAttributes term_fd attr Immediately
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