1{-# LANGUAGE ScopedTypeVariables #-}
2{-# LANGUAGE ForeignFunctionInterface #-}
3-- Copyright Corey O'Connor
4module Graphics.Vty.Input.Data where
6-- | Representations of non-modifier keys.
7data 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.
15data Modifier = MShift | MCtrl | MMeta | MAlt
16 deriving (Eq,Show,Ord)
18-- |Mouse buttons. Not yet used.
19data Button = BLeft | BMiddle | BRight
20 deriving (Eq,Show,Ord)
23data Event = EvKey Key [Modifier] | EvMouse Int Int Button [Modifier]
25 deriving (Eq,Show,Ord)
27data KClass = Valid Key [Modifier] | Invalid | Prefix | MisPfx Key [Modifier] [Char]
30map_to_legacy_table :: [(String, Event)] -> [(String, (Key, [Modifier]))]
31map_to_legacy_table = map f
32 where f (s, EvKey k mods) = (s, (k, mods))
33 f _ = error "no mapping for mouse or resize events"
35-- | classify table directly generated from terminfo cap strings
36caps_table :: [(String, Event)]
38 [ ("khome", EvKey KHome [])
39 , ("kend", EvKey KEnd [])
40 , ("cbt", EvKey KBackTab [])
41 , ("kcud1", EvKey KDown [])
42 , ("kcuu1", EvKey KUp [])
43 , ("kcuf1", EvKey KRight [])
44 , ("kcub1", EvKey KLeft [])
45 , ("kLFT", EvKey KLeft [MShift])
46 , ("kRIT", EvKey KRight [MShift])
49nav_keys_0 :: [([Char], (Key, [Modifier]))]
61 where k c s = ("\ESC["++c,(s,[]))
63-- Support for arrows and KHome/KEnd
64nav_keys_1 :: [([Char], (Key, [Modifier]))]
66 [("\ESC[" ++ charCnt ++ show mc++c,(s,m))
67 | charCnt <- ["1;", ""], -- we can have a count or not
68 (m,mc) <- [([MShift],2::Int), ([MCtrl],5), ([MMeta],3),
69 ([MShift, MCtrl],6), ([MShift, MMeta],4)], -- modifiers and their codes
70 (c,s) <- [("A", KUp), ("B", KDown), ("C", KRight), ("D", KLeft), ("H", KHome), ("F", KEnd)] -- directions and their codes
73nav_keys_2 :: [([Char], (Key, [Modifier]))]
75 let k n s = ("\ESC["++show n++"~",(s,[]))
76 in zipWith k [2::Int,3,5,6,1,4]
77 [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
79nav_keys_3 :: [([Char], (Key, [Modifier]))]
81 let k n s = ("\ESC["++show n++";5~",(s,[MCtrl]))
82 in zipWith k [2::Int,3,5,6,1,4]
83 [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
85-- Support for simple characters.
86simple_chars :: [([Char], (Key, [Modifier]))]
87simple_chars = [ (x:[],(KASCII x,[])) | x <- map toEnum [0..255] ]
89-- Support for function keys (should use terminfo)
90function_keys_0 :: [([Char], (Key, [Modifier]))]
91function_keys_0 = [ ("\ESC[["++[toEnum(64+i)],(KFun i,[])) | i <- [1..5] ]
93function_keys_1 :: [([Char], (Key, [Modifier]))]
95 let f ff nrs m = [ ("\ESC["++show n++"~",(KFun (n-(nrs!!0)+ff), m)) | n <- nrs ] in
96 concat [ f 6 [17..21] [], f 11 [23,24] [], f 1 [25,26] [MShift], f 3 [28,29] [MShift], f 5 [31..34] [MShift] ]
98function_keys_2 :: [([Char], (Key, [Modifier]))]
99function_keys_2 = [ ('\ESC':[x],(KASCII x,[MMeta])) | x <- '\ESC':'\t':[' ' .. '\DEL'] ]
102ctrl_char_keys :: [([Char], (Key, [Modifier]))]
104 [ ([toEnum x],(KASCII y,[MCtrl]))
105 | (x,y) <- zip ([0..31]) ('@':['a'..'z']++['['..'_']),
106 y /= 'i' -- Resolve issue #3 where CTRL-i hides TAB.
110ctrl_meta_keys :: [([Char], (Key, [Modifier]))]
112 [ ('\ESC':[toEnum x],(KASCII y,[MMeta,MCtrl])) | (x,y) <- zip [0..31] ('@':['a'..'z']++['['..'_']) ]
115special_support_keys :: [([Char], (Key, [Modifier]))]
116special_support_keys =
117 [ -- special support for ESC
118 ("\ESC",(KEsc,[])) , ("\ESC\ESC",(KEsc,[MMeta]))
119 -- Special support for backspace
120 , ("\DEL",(KBS,[])), ("\ESC\DEL",(KBS,[MMeta]))
121 -- Special support for Enter
122 , ("\ESC\^J",(KEnter,[MMeta])), ("\^J",(KEnter,[]))
125-- | classify table for ANSI terminals
126ansi_classify_table :: [[([Char], (Key, [Modifier]))]]
138 , special_support_keys
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list