on master help sign in
docs
commit3a57dac719475a9429dcaf6e0a72a9053ff833ae authorCorey O'Connor <coreyoconnor@gmail.com> dateSun 17 Nov 2013, 03:22 (13 years ago) parent0cd1432
3 files changed+23−21
README.md+1 src/Graphics/Vty/Input.hs+11−9 src/Graphics/Vty/Input/Data.hs+11−12
README.md+1
@@ -83,3 +83,4 @@ rm -rf dist ; cabal configure --enable-tests --disable-library-coverage \
8383* http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
8484* http://ulisse.elettra.trieste.it/services/doc/serial/config.html
8585* http://www.leonerd.org.uk/hacks/hints/xterm-8bit.html
86+* http://www.unixwiz.net/techtips/termios-vmin-vtime.html
src/Graphics/Vty/Input.hs+11−9
@@ -8,19 +8,19 @@
88--
99-- Which is better? Well, depends on if you want to enter Unicode as UTF-8 or not.
1010--
11−-- * 7 bit mode: UTF-8 can be input unambiguiously. Requires an escape delay to differentiate ESC
12−-- from extended control characters. EG: F1
11+-- * 7 bit mode: UTF-8 can be input unambiguiously.
1312-- * 8 bit mode: UTF-8 cannot be input. Does not require an escape delay.
1413--
15−-- By default 7 bit mode is used. If 8 bit moe is requested then vty will request 8 bit mode from
16−-- the terminal. However, if the terminal does not report a capability that uses 8 bit encoding the
17−-- mode will fall back to 7 bit.
14+-- vty uses 7 bit mode.
15+--
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!
1821--
1922-- By default, the escape delay is 10000 microseconds. Which is assumed to be well above the
2023-- sampling rate required to detect a keyup for a person typing 200 wpm.
21−--
22−-- 0. set raw mode with min == 0 and time == 0
23−--
2424module Graphics.Vty.Input ( Key(..)
2525 , Modifier(..)
2626 , Button(..)
@@ -42,8 +42,10 @@ import System.Posix.Signals.Exts
4242import System.Posix.Terminal
4343import System.Posix.IO (stdInput)
4444
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.
4547defaultEscDelay :: Int
46−defaultEscDelay = 4000
48+defaultEscDelay = 10000
4749
4850-- | Set up the terminal for input. Returns a function which reads key
4951-- events, and a function for shutting down the terminal access.
src/Graphics/Vty/Input/Data.hs+11−12
@@ -27,15 +27,17 @@ data Event = EvKey Key [Modifier] | EvMouse Int Int Button [Modifier]
2727-- | representation of mapping from input bytes to output event
2828--
2929-- deprecated
30−type ClassifyTable = [(String, (Key, [Modifier]))]
30+type ClassifyTableV1 = [(String, (Key, [Modifier]))]
3131
32−map_to_legacy_table :: [(String, Event)] -> ClassifyTable
32+type ClassifyTable = [(String, Event)]
33+
34+map_to_legacy_table :: ClassifyTable -> ClassifyTableV1
3335map_to_legacy_table = map f
3436 where f (s, EvKey k mods) = (s, (k, mods))
3537 f _ = error "no mapping for mouse or resize events"
3638
3739-- | classify table directly generated from terminfo cap strings
38−keys_from_caps_table :: [(String, Event)]
40+keys_from_caps_table :: ClassifyTable
3941keys_from_caps_table =
4042 [ ("khome", EvKey KHome [])
4143 , ("kend", EvKey KEnd [])
@@ -49,13 +51,13 @@ keys_from_caps_table =
4951 ] ++ function_key_caps_table
5052
5153-- | cap names for function keys
52−function_key_caps_table :: [(String, Event)]
54+function_key_caps_table :: ClassifyTable
5355function_key_caps_table = flip map [0..63] $ \n -> ("kf" ++ show n, EvKey (KFun n) [])
5456
55−-- VT 100 encoding for navigation keys.
57+-- | Encoding for navigation keys.
5658--
57−-- TODO: remove those that duplicate entries in caps table.
58−nav_keys_0 :: ClassifyTable
59+-- TODO: This is not the same as the input bytes pulled from teh caps table.
60+nav_keys_0 :: ClassifyTableV1
5961nav_keys_0 =
6062 [ k "G" KNP5
6163 , k "P" KPause
@@ -69,8 +71,8 @@ nav_keys_0 =
6971 ]
7072 where k c s = ("\ESC["++c,(s,[]))
7173
72−-- | VT 100 (?) encoding for arrows and KHome/KEnd
73−nav_keys_1 :: ClassifyTable
74+-- | VT 100 (?) encoding for shift, meta and ctrl plus arrows/home/end
75+nav_keys_1 :: ClassifyTableV1
7476nav_keys_1 =
7577 [("\ESC[" ++ charCnt ++ show mc++c,(s,m))
7678 | charCnt <- ["1;", ""], -- we can have a count or not
@@ -105,9 +107,6 @@ simple_chars = [(x:[],(KASCII x,[])) | x <- [' ' .. toEnum 0xC1]]
105107
106108-- | VT 100 (?) encoding for shift plus function keys
107109--
108−-- (corey): yes. This definitely should. On my terminal these keys do not operate as expected.
109−-- function_keys_0 :: ClassifyTable
110−-- function_keys_0 = [ ("\ESC[["++[toEnum(64+i)],(KFun i,[])) | i <- [1..5] ]
111110-- TODO: I suspect this should be generated by interpretting the terminals use of meta mode:
112111-- "If the terminal has a ``meta key'' which acts as a shift key, setting the 8th bit of any
113112-- character transmitted, this fact can be indicated with km. Other- wise, software will