on master help sign in
ok fine. actually trying to understand and fixup the input layer
commit5c7598bb1178da8e44c88e7367f9e7f1c811fbe3 authorCorey O'Connor <corey@ooyala.com> dateWed 30 Oct 2013, 10:25 (13 years ago) parent0d272ac
3 files changed+39−10
README.md+7 src/Graphics/Vty/Error.hs−1 src/Graphics/Vty/Input.hs+32−9
README.md+7
@@ -76,3 +76,10 @@ rm -rf dist ; cabal configure --enable-tests --disable-library-coverage \
7676 --enable-library-profiling \
7777 --enable-executable-profiling
7878~~~
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
33
44import Control.Exception
55
6−
76-- | The type of exceptions specific to vty.
87--
98-- These have fully qualified names by default since, IMO, exception handling requires this.
src/Graphics/Vty/Input.hs+32−9
@@ -1,4 +1,24 @@
11-- 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+--
222module Graphics.Vty.Input ( Key(..)
323 , Modifier(..)
424 , Button(..)
@@ -13,12 +33,15 @@ import Graphics.Vty.Input.Internal
1333import Graphics.Vty.Input.Terminfo
1434
1535import Data.Char
36+import Data.IORef
1637import Data.Word
1738
1839import Control.Monad (when, void)
1940import Control.Concurrent
2041import Control.Exception
2142
43+import qualified GHC.Event as GHC
44+
2245import System.Console.Terminfo
2346
2447import System.Posix.Signals.Exts
@@ -41,11 +64,12 @@ initTermInput escDelay terminal = do
4164 eventChannel <- newChan
4265 inputChannel <- newChan
4366 hadInput <- newEmptyMVar
44− oattr <- getTerminalAttributes stdInput
45− let nattr = foldl withoutMode oattr [ StartStopOutput, KeyboardInterrupts
46− , EnableEcho, ProcessInput, ExtendedFunctions
47− ]
48− setTerminalAttributes stdInput nattr Immediately
67+ attr <- getTerminalAttributes stdInput
68+ -- disable IXON,
69+ let attr' = foldl withoutMode attr [ StartStopOutput, KeyboardInterrupts
70+ , EnableEcho, ProcessInput, ExtendedFunctions
71+ ]
72+ setTerminalAttributes stdInput attr' Immediately
4973 set_term_timing
5074 let finishAtomicInput = writeChan inputChannel '\xFFFE'
5175 inputThread :: IO ()
@@ -77,8 +101,7 @@ initTermInput escDelay terminal = do
77101 threadDelay escDelay -- microseconds
78102 hadNoInput <- isEmptyMVar hadInput -- no input yet?
79103 -- TODO(corey): there is a race between here and the inputThread.
80− when hadNoInput $ do
81− finishAtomicInput
104+ when hadNoInput finishAtomicInput
82105 loop
83106
84107 caps_legacy_table = map_to_legacy_table $ caps_classify_table terminal keys_from_caps_table
@@ -90,7 +113,7 @@ initTermInput escDelay terminal = do
90113 noInputThreadId <- forkIO $ noInputThread
91114 let pokeIO = Catch $ do
92115 let e = error "(getsize in input layer)"
93− setTerminalAttributes stdInput nattr Immediately
116+ setTerminalAttributes stdInput attr' Immediately
94117 writeChan eventChannel (EvResize e e)
95118 _ <- installHandler windowChange pokeIO Nothing
96119 _ <- installHandler continueProcess pokeIO Nothing
@@ -101,6 +124,6 @@ initTermInput escDelay terminal = do
101124 killThread noInputThreadId
102125 _ <- installHandler windowChange Ignore Nothing
103126 _ <- installHandler continueProcess Ignore Nothing
104− setTerminalAttributes stdInput oattr Immediately
127+ setTerminalAttributes stdInput attr Immediately
105128 return (readChan eventChannel, uninit)
106129