on master help sign in
ok fine. actually trying to understand and fixup the input layer
5c7598bCorey O'Connor
README.md+7
@@ -76,3 +76,10 @@ rm -rf dist ; cabal configure --enable-tests --disable-library-coverage \
76 --enable-library-profiling \
76 --enable-library-profiling \
77 --enable-executable-profiling
77 --enable-executable-profiling
78~~~
78~~~
79+
80+# References
81+
82+* https://github.com/b4winckler/vim/blob/master/src/term.c
83+* http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
84+* http://ulisse.elettra.trieste.it/services/doc/serial/config.html
85+* http://www.leonerd.org.uk/hacks/hints/xterm-8bit.html
src/Graphics/Vty/Error.hs−1
@@ -3,7 +3,6 @@ module Graphics.Vty.Error
3
3
4import Control.Exception
4import Control.Exception
5
5
6−
7-- | The type of exceptions specific to vty.
6-- | The type of exceptions specific to vty.
8--
7--
9-- These have fully qualified names by default since, IMO, exception handling requires this.
8-- These have fully qualified names by default since, IMO, exception handling requires this.
src/Graphics/Vty/Input.hs+32−9
@@ -1,4 +1,24 @@
1-- Copyright 2009-2010 Corey O'Connor
1-- Copyright 2009-2010 Corey O'Connor
2+--
3+-- There are two input modes:
4+-- 1. 7 bit
5+-- 2. 8 bit
6+--
7+-- Which is better? Well, depends on if you want to enter Unicode as UTF-8 or not.
8+--
9+-- * 7 bit mode: UTF-8 can be input unambiguiously. Requires an escape delay to differentiate ESC
10+-- from extended control characters. EG: F1
11+-- * 8 bit mode: UTF-8 cannot be input. Does not require an escape delay.
12+--
13+-- By default 7 bit mode is used. If 8 bit moe is requested then vty will request 8 bit mode from
14+-- the terminal. However, if the terminal does not report a capability that uses 8 bit encoding the
15+-- mode will fall back to 7 bit.
16+--
17+-- By default, the escape delay is 10000 microseconds. Which is assumed to be well above the
18+-- sampling rate required to detect a keyup for a person typing 200 wpm.
19+--
20+-- 0. set raw mode with min == 0 and time == 0
21+--
2module Graphics.Vty.Input ( Key(..)
22module Graphics.Vty.Input ( Key(..)
3 , Modifier(..)
23 , Modifier(..)
4 , Button(..)
24 , Button(..)
@@ -13,12 +33,15 @@ import Graphics.Vty.Input.Internal
13import Graphics.Vty.Input.Terminfo
33import Graphics.Vty.Input.Terminfo
14
34
15import Data.Char
35import Data.Char
36+import Data.IORef
16import Data.Word
37import Data.Word
17
38
18import Control.Monad (when, void)
39import Control.Monad (when, void)
19import Control.Concurrent
40import Control.Concurrent
20import Control.Exception
41import Control.Exception
21
42
43+import qualified GHC.Event as GHC
44+
22import System.Console.Terminfo
45import System.Console.Terminfo
23
46
24import System.Posix.Signals.Exts
47import System.Posix.Signals.Exts
@@ -41,11 +64,12 @@ initTermInput escDelay terminal = do
41 eventChannel <- newChan
64 eventChannel <- newChan
42 inputChannel <- newChan
65 inputChannel <- newChan
43 hadInput <- newEmptyMVar
66 hadInput <- newEmptyMVar
44− oattr <- getTerminalAttributes stdInput
67+ attr <- getTerminalAttributes stdInput
68+ -- disable IXON,
45− let nattr = foldl withoutMode oattr [ StartStopOutput, KeyboardInterrupts
69+ let attr' = foldl withoutMode attr [ StartStopOutput, KeyboardInterrupts
46− , EnableEcho, ProcessInput, ExtendedFunctions
70+ , EnableEcho, ProcessInput, ExtendedFunctions
47− ]
71+ ]
48− setTerminalAttributes stdInput nattr Immediately
72+ setTerminalAttributes stdInput attr' Immediately
49 set_term_timing
73 set_term_timing
50 let finishAtomicInput = writeChan inputChannel '\xFFFE'
74 let finishAtomicInput = writeChan inputChannel '\xFFFE'
51 inputThread :: IO ()
75 inputThread :: IO ()
@@ -77,8 +101,7 @@ initTermInput escDelay terminal = do
77 threadDelay escDelay -- microseconds
101 threadDelay escDelay -- microseconds
78 hadNoInput <- isEmptyMVar hadInput -- no input yet?
102 hadNoInput <- isEmptyMVar hadInput -- no input yet?
79 -- TODO(corey): there is a race between here and the inputThread.
103 -- TODO(corey): there is a race between here and the inputThread.
80− when hadNoInput $ do
81− finishAtomicInput
104+ when hadNoInput finishAtomicInput
82 loop
105 loop
83
106
84 caps_legacy_table = map_to_legacy_table $ caps_classify_table terminal keys_from_caps_table
107 caps_legacy_table = map_to_legacy_table $ caps_classify_table terminal keys_from_caps_table
@@ -90,7 +113,7 @@ initTermInput escDelay terminal = do
90 noInputThreadId <- forkIO $ noInputThread
113 noInputThreadId <- forkIO $ noInputThread
91 let pokeIO = Catch $ do
114 let pokeIO = Catch $ do
92 let e = error "(getsize in input layer)"
115 let e = error "(getsize in input layer)"
93− setTerminalAttributes stdInput nattr Immediately
116+ setTerminalAttributes stdInput attr' Immediately
94 writeChan eventChannel (EvResize e e)
117 writeChan eventChannel (EvResize e e)
95 _ <- installHandler windowChange pokeIO Nothing
118 _ <- installHandler windowChange pokeIO Nothing
96 _ <- installHandler continueProcess pokeIO Nothing
119 _ <- installHandler continueProcess pokeIO Nothing
@@ -101,6 +124,6 @@ initTermInput escDelay terminal = do
101 killThread noInputThreadId
124 killThread noInputThreadId
102 _ <- installHandler windowChange Ignore Nothing
125 _ <- installHandler windowChange Ignore Nothing
103 _ <- installHandler continueProcess Ignore Nothing
126 _ <- installHandler continueProcess Ignore Nothing
104− setTerminalAttributes stdInput oattr Immediately
127+ setTerminalAttributes stdInput attr Immediately
105 return (readChan eventChannel, uninit)
128 return (readChan eventChannel, uninit)
106
129