on master help sign in
docs
3a57dacCorey O'Connor
README.md+1
@@ -83,3 +83,4 @@ rm -rf dist ; cabal configure --enable-tests --disable-library-coverage \
83* http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
83* http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
84* http://ulisse.elettra.trieste.it/services/doc/serial/config.html
84* http://ulisse.elettra.trieste.it/services/doc/serial/config.html
85* http://www.leonerd.org.uk/hacks/hints/xterm-8bit.html
85* 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 @@
8--
8--
9-- Which is better? Well, depends on if you want to enter Unicode as UTF-8 or not.
9-- Which is better? Well, depends on if you want to enter Unicode as UTF-8 or not.
10--
10--
11−-- * 7 bit mode: UTF-8 can be input unambiguiously. Requires an escape delay to differentiate ESC
11+-- * 7 bit mode: UTF-8 can be input unambiguiously.
12−-- from extended control characters. EG: F1
13-- * 8 bit mode: UTF-8 cannot be input. Does not require an escape delay.
12-- * 8 bit mode: UTF-8 cannot be input. Does not require an escape delay.
14--
13--
15−-- By default 7 bit mode is used. If 8 bit moe is requested then vty will request 8 bit mode from
14+-- vty uses 7 bit mode.
16−-- the terminal. However, if the terminal does not report a capability that uses 8 bit encoding the
15+--
17−-- mode will fall back to 7 bit.
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!
18--
21--
19-- By default, the escape delay is 10000 microseconds. Which is assumed to be well above the
22-- By default, the escape delay is 10000 microseconds. Which is assumed to be well above the
20-- sampling rate required to detect a keyup for a person typing 200 wpm.
23-- 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−--
24module Graphics.Vty.Input ( Key(..)
24module Graphics.Vty.Input ( Key(..)
25 , Modifier(..)
25 , Modifier(..)
26 , Button(..)
26 , Button(..)
@@ -42,8 +42,10 @@ import System.Posix.Signals.Exts
42import System.Posix.Terminal
42import System.Posix.Terminal
43import System.Posix.IO (stdInput)
43import System.Posix.IO (stdInput)
44
44
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.
45defaultEscDelay :: Int
47defaultEscDelay :: Int
46−defaultEscDelay = 4000
48+defaultEscDelay = 10000
47
49
48-- | Set up the terminal for input. Returns a function which reads key
50-- | Set up the terminal for input. Returns a function which reads key
49-- events, and a function for shutting down the terminal access.
51-- 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]
27-- | representation of mapping from input bytes to output event
27-- | representation of mapping from input bytes to output event
28--
28--
29-- deprecated
29-- deprecated
30−type ClassifyTable = [(String, (Key, [Modifier]))]
30+type ClassifyTableV1 = [(String, (Key, [Modifier]))]
31
31
32−map_to_legacy_table :: [(String, Event)] -> ClassifyTable
32+type ClassifyTable = [(String, Event)]
33+
34+map_to_legacy_table :: ClassifyTable -> ClassifyTableV1
33map_to_legacy_table = map f
35map_to_legacy_table = map f
34 where f (s, EvKey k mods) = (s, (k, mods))
36 where f (s, EvKey k mods) = (s, (k, mods))
35 f _ = error "no mapping for mouse or resize events"
37 f _ = error "no mapping for mouse or resize events"
36
38
37-- | classify table directly generated from terminfo cap strings
39-- | classify table directly generated from terminfo cap strings
38−keys_from_caps_table :: [(String, Event)]
40+keys_from_caps_table :: ClassifyTable
39keys_from_caps_table =
41keys_from_caps_table =
40 [ ("khome", EvKey KHome [])
42 [ ("khome", EvKey KHome [])
41 , ("kend", EvKey KEnd [])
43 , ("kend", EvKey KEnd [])
@@ -49,13 +51,13 @@ keys_from_caps_table =
49 ] ++ function_key_caps_table
51 ] ++ function_key_caps_table
50
52
51-- | cap names for function keys
53-- | cap names for function keys
52−function_key_caps_table :: [(String, Event)]
54+function_key_caps_table :: ClassifyTable
53function_key_caps_table = flip map [0..63] $ \n -> ("kf" ++ show n, EvKey (KFun n) [])
55function_key_caps_table = flip map [0..63] $ \n -> ("kf" ++ show n, EvKey (KFun n) [])
54
56
55−-- VT 100 encoding for navigation keys.
57+-- | Encoding for navigation keys.
56--
58--
57−-- TODO: remove those that duplicate entries in caps table.
59+-- TODO: This is not the same as the input bytes pulled from teh caps table.
58−nav_keys_0 :: ClassifyTable
60+nav_keys_0 :: ClassifyTableV1
59nav_keys_0 =
61nav_keys_0 =
60 [ k "G" KNP5
62 [ k "G" KNP5
61 , k "P" KPause
63 , k "P" KPause
@@ -69,8 +71,8 @@ nav_keys_0 =
69 ]
71 ]
70 where k c s = ("\ESC["++c,(s,[]))
72 where k c s = ("\ESC["++c,(s,[]))
71
73
72−-- | VT 100 (?) encoding for arrows and KHome/KEnd
74+-- | VT 100 (?) encoding for shift, meta and ctrl plus arrows/home/end
73−nav_keys_1 :: ClassifyTable
75+nav_keys_1 :: ClassifyTableV1
74nav_keys_1 =
76nav_keys_1 =
75 [("\ESC[" ++ charCnt ++ show mc++c,(s,m))
77 [("\ESC[" ++ charCnt ++ show mc++c,(s,m))
76 | charCnt <- ["1;", ""], -- we can have a count or not
78 | charCnt <- ["1;", ""], -- we can have a count or not
@@ -105,9 +107,6 @@ simple_chars = [(x:[],(KASCII x,[])) | x <- [' ' .. toEnum 0xC1]]
105
107
106-- | VT 100 (?) encoding for shift plus function keys
108-- | VT 100 (?) encoding for shift plus function keys
107--
109--
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] ]
111-- TODO: I suspect this should be generated by interpretting the terminals use of meta mode:
110-- TODO: I suspect this should be generated by interpretting the terminals use of meta mode:
112-- "If the terminal has a ``meta key'' which acts as a shift key, setting the 8th bit of any
111-- "If the terminal has a ``meta key'' which acts as a shift key, setting the 8th bit of any
113-- character transmitted, this fact can be indicated with km. Other- wise, software will
112-- character transmitted, this fact can be indicated with km. Other- wise, software will