@@ -1,35 +1,12 @@
1-- Copyright Corey O'Connor
1-- 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
4−-- | Representations of non-modifier keys.
8+import Graphics.Vty.Input.Data.ANSI
5−--
9+import Graphics.Vty.Input.Events
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)
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)
18−-- | Mouse buttons. Not yet used.
19−data Button = BLeft | BMiddle | BRight
20− deriving (Eq,Show,Ord)
23−data Event = EvKey Key [Modifier] | EvMouse Int Int Button [Modifier]
25− deriving (Eq,Show,Ord)
27−-- | representation of mapping from input bytes to output event
30−type ClassifyTableV1 = [(String, (Key, [Modifier]))]
32−type ClassifyTable = [(String, Event)]
34map_to_legacy_table :: ClassifyTable -> ClassifyTableV1
11map_to_legacy_table :: ClassifyTable -> ClassifyTableV1
35map_to_legacy_table = map f
12map_to_legacy_table = map f
@@ -54,124 +31,3 @@ keys_from_caps_table =
54function_key_caps_table :: ClassifyTable
31function_key_caps_table :: ClassifyTable
55function_key_caps_table = flip map [0..63] $ \n -> ("kf" ++ show n, EvKey (KFun n) [])
32function_key_caps_table = flip map [0..63] $ \n -> ("kf" ++ show n, EvKey (KFun n) [])
57−-- | Encoding for navigation keys.
59−-- TODO: This is not the same as the input bytes pulled from teh caps table.
60−nav_keys_0 :: ClassifyTableV1
72− where k c s = ("\ESC["++c,(s,[]))
74−-- | VT 100 (?) encoding for shift, meta and ctrl plus arrows/home/end
75−nav_keys_1 :: ClassifyTableV1
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
84−-- | VT 100 (?) encoding for ins, del, pageup, pagedown, home, end
85−nav_keys_2 :: ClassifyTableV1
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]
91−-- | VT 100 (?) encoding for ctrl + ins, del, pageup, pagedown, home, end
92−nav_keys_3 :: ClassifyTableV1
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]
98−-- | Support for simple characters.
100−-- we limit to < 0xC1. The UTF8 sequence detector will catch all values 0xC2 and above before this
101−-- classify table is reached.
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]]
108−-- | VT 100 (?) encoding for shift plus function keys
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."
116−-- That is more complex than below. I cannot fault the original author for just hard coding a table.
117−function_keys_1 :: ClassifyTableV1
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] ]
122−-- | VT 100 (?) encoding for meta plus char
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':[' ' .. '~'],
136−ctrl_char_keys :: ClassifyTableV1
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.
145−-- TODO: CTRL-i is the same as tab thing
146−ctrl_meta_keys :: ClassifyTableV1
148− [ ('\ESC':[toEnum x],(KASCII y,[MMeta,MCtrl])) | (x,y) <- zip [0..31] ('@':['a'..'z']++['['..'_']),
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,[]))
163−-- | classify table for ANSI terminals
164−ansi_classify_table :: [ClassifyTableV1]
165−ansi_classify_table =
175− , special_support_keys