@@ -1,35 +1,12 @@
11-- Copyright Corey O'Connor
2−module Graphics.Vty.Input.Data where
2+module Graphics.Vty.Input.Data ( module Graphics.Vty.Input.Data
3+ , module Graphics.Vty.Input.Data.ANSI
4+ , module Graphics.Vty.Input.Events
5+ )
6+where
37
4−-- | Representations of non-modifier keys.
5−--
6−-- KFun is indexed from 0 to 63. Range of supported FKeys varies by terminal and keyboard.
7−data Key = KEsc | KFun Int | KBackTab | KPrtScr | KPause | KASCII Char | KBS | KIns
8− | KHome | KPageUp | KDel | KEnd | KPageDown | KBegin | KNP5 | KUp | KMenu
9− | KLeft | KDown | KRight | KEnter
10− deriving (Eq,Show,Ord)
11−
12−-- | Modifier keys. Key codes are interpreted such that users are more likely to
13−-- have Meta than Alt; for instance on the PC Linux console, 'MMeta' will
14−-- generally correspond to the physical Alt key.
15−data Modifier = MShift | MCtrl | MMeta | MAlt
16− deriving (Eq,Show,Ord)
17−
18−-- | Mouse buttons. Not yet used.
19−data Button = BLeft | BMiddle | BRight
20− deriving (Eq,Show,Ord)
21−
22−-- | Generic events.
23−data Event = EvKey Key [Modifier] | EvMouse Int Int Button [Modifier]
24− | EvResize Int Int
25− deriving (Eq,Show,Ord)
26−
27−-- | representation of mapping from input bytes to output event
28−--
29−-- deprecated
30−type ClassifyTableV1 = [(String, (Key, [Modifier]))]
31−
32−type ClassifyTable = [(String, Event)]
8+import Graphics.Vty.Input.Data.ANSI
9+import Graphics.Vty.Input.Events
3310
3411map_to_legacy_table :: ClassifyTable -> ClassifyTableV1
3512map_to_legacy_table = map f
@@ -54,124 +31,3 @@ keys_from_caps_table =
5431function_key_caps_table :: ClassifyTable
5532function_key_caps_table = flip map [0..63] $ \n -> ("kf" ++ show n, EvKey (KFun n) [])
5633
57−-- | Encoding for navigation keys.
58−--
59−-- TODO: This is not the same as the input bytes pulled from teh caps table.
60−nav_keys_0 :: ClassifyTableV1
61−nav_keys_0 =
62− [ k "G" KNP5
63− , k "P" KPause
64− , k "A" KUp
65− , k "B" KDown
66− , k "C" KRight
67− , k "D" KLeft
68− , k "H" KHome
69− , k "F" KEnd
70− , k "E" KBegin
71− ]
72− where k c s = ("\ESC["++c,(s,[]))
73−
74−-- | VT 100 (?) encoding for shift, meta and ctrl plus arrows/home/end
75−nav_keys_1 :: ClassifyTableV1
76−nav_keys_1 =
77− [("\ESC[" ++ charCnt ++ show mc++c,(s,m))
78− | charCnt <- ["1;", ""], -- we can have a count or not
79− (m,mc) <- [([MShift],2::Int), ([MCtrl],5), ([MMeta],3),
80− ([MShift, MCtrl],6), ([MShift, MMeta],4)], -- modifiers and their codes
81− (c,s) <- [("A", KUp), ("B", KDown), ("C", KRight), ("D", KLeft), ("H", KHome), ("F", KEnd)] -- directions and their codes
82− ]
83−
84−-- | VT 100 (?) encoding for ins, del, pageup, pagedown, home, end
85−nav_keys_2 :: ClassifyTableV1
86−nav_keys_2 =
87− let k n s = ("\ESC["++show n++"~",(s,[]))
88− in zipWith k [2::Int,3,5,6,1,4]
89− [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
90−
91−-- | VT 100 (?) encoding for ctrl + ins, del, pageup, pagedown, home, end
92−nav_keys_3 :: ClassifyTableV1
93−nav_keys_3 =
94− let k n s = ("\ESC["++show n++";5~",(s,[MCtrl]))
95− in zipWith k [2::Int,3,5,6,1,4]
96− [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
97−
98−-- | Support for simple characters.
99−--
100−-- we limit to < 0xC1. The UTF8 sequence detector will catch all values 0xC2 and above before this
101−-- classify table is reached.
102−--
103−-- TODO: resolve
104−-- 1. start at ' '. The earlier characters are all ctrl_char_keys
105−simple_chars :: ClassifyTableV1
106−simple_chars = [(x:[],(KASCII x,[])) | x <- [' ' .. toEnum 0xC1]]
107−
108−-- | VT 100 (?) encoding for shift plus function keys
109−--
110−-- TODO: I suspect this should be generated by interpretting the terminals use of meta mode:
111−-- "If the terminal has a ``meta key'' which acts as a shift key, setting the 8th bit of any
112−-- character transmitted, this fact can be indicated with km. Other- wise, software will
113−-- assume that the 8th bit is parity and it will usually be cleared. If strings exist to turn this
114−-- ``meta mode'' on and off, they can be given as smm and rmm."
115−--
116−-- That is more complex than below. I cannot fault the original author for just hard coding a table.
117−function_keys_1 :: ClassifyTableV1
118−function_keys_1 =
119− let f ff nrs m = [ ("\ESC["++show n++"~",(KFun (n-(nrs!!0)+ff), m)) | n <- nrs ] in
120− concat [f 1 [25,26] [MShift], f 3 [28,29] [MShift], f 5 [31..34] [MShift] ]
121−
122−-- | VT 100 (?) encoding for meta plus char
123−--
124−-- TODO: resolve -
125−--
126−-- 1. removed 'ESC' from second list due to duplication with "special_support_keys".
127−-- 2. removed '[' from second list due to conflict with 7-bit encoding for ESC. Whether meta+[ is
128−-- the same as ESC should examine km and current encoding.
129−-- 3. stopped enumeration at '~' instead of '\DEL'. The latter is mapped to KBS by
130−-- special_support_keys.
131−function_keys_2 :: ClassifyTableV1
132−function_keys_2 = [ ('\ESC':[x],(KASCII x,[MMeta])) | x <- '\t':[' ' .. '~'],
133− x /= '[']
134−
135−-- | Ctrl+Char
136−ctrl_char_keys :: ClassifyTableV1
137−ctrl_char_keys =
138− [ ([toEnum x],(KASCII y,[MCtrl]))
139− | (x,y) <- zip ([0..31]) ('@':['a'..'z']++['['..'_']),
140− y /= 'i' -- Resolve issue #3 where CTRL-i hides TAB.
141− ]
142−
143−-- | Ctrl+Meta+Char
144−--
145−-- TODO: CTRL-i is the same as tab thing
146−ctrl_meta_keys :: ClassifyTableV1
147−ctrl_meta_keys =
148− [ ('\ESC':[toEnum x],(KASCII y,[MMeta,MCtrl])) | (x,y) <- zip [0..31] ('@':['a'..'z']++['['..'_']),
149− y /= 'i'
150− ]
151−
152−-- | Special support
153−special_support_keys :: ClassifyTableV1
154−special_support_keys =
155− [ -- special support for ESC
156− ("\ESC",(KEsc,[])) , ("\ESC\ESC",(KEsc,[MMeta]))
157− -- Special support for backspace
158− , ("\DEL",(KBS,[])), ("\ESC\DEL",(KBS,[MMeta]))
159− -- Special support for Enter
160− , ("\ESC\^J",(KEnter,[MMeta])), ("\^J",(KEnter,[]))
161− ]
162−
163−-- | classify table for ANSI terminals
164−ansi_classify_table :: [ClassifyTableV1]
165−ansi_classify_table =
166− [ nav_keys_0
167− , nav_keys_1
168− , nav_keys_2
169− , nav_keys_3
170− , simple_chars
171− , function_keys_1
172− , function_keys_2
173− , ctrl_char_keys
174− , ctrl_meta_keys
175− , special_support_keys
176− ]
177−