@@ -2,7 +2,10 @@
22-- Copyright 2009-2010 Corey O'Connor
33{-# OPTIONS_GHC -Wall #-}
44{-# LANGUAGE ForeignFunctionInterface #-}
5−module Graphics.Vty.Input ( module Graphics.Vty.Input.Data
5+module Graphics.Vty.Input ( Key(..)
6+ , Modifier(..)
7+ , Button(..)
8+ , Event(..)
69 , initTermInput
710 )
811 where
@@ -43,8 +46,9 @@ initTermInput escDelay terminal = do
4346 inputChannel <- newChan
4447 hadInput <- newEmptyMVar
4548 oattr <- getTerminalAttributes stdInput
46− let nattr = foldl withoutMode oattr [StartStopOutput, KeyboardInterrupts,
47− EnableEcho, ProcessInput, ExtendedFunctions]
49+ let nattr = foldl withoutMode oattr [ StartStopOutput, KeyboardInterrupts
50+ , EnableEcho, ProcessInput, ExtendedFunctions
51+ ]
4852 setTerminalAttributes stdInput nattr Immediately
4953 set_term_timing
5054 let inputToEventThread :: IO ()
@@ -126,64 +130,6 @@ initTermInput escDelay terminal = do
126130 caps_classify_table
127131 = map_to_legacy_table [(x,y) | (Just x,y) <- map (first (getCapability terminal . tiGetStr)) $ caps_table]
128132
129− ansi_classify_table :: [[([Char], (Key, [Modifier]))]]
130− ansi_classify_table =
131− [ let k c s = ("\ESC["++c,(s,[])) in [ k "G" KNP5
132− , k "P" KPause
133− , k "A" KUp
134− , k "B" KDown
135− , k "C" KRight
136− , k "D" KLeft
137− , k "H" KHome
138− , k "F" KEnd
139− , k "E" KBegin
140− ],
141−
142− -- Support for arrows and KHome/KEnd
143− [("\ESC[" ++ charCnt ++ show mc++c,(s,m))
144− | charCnt <- ["1;", ""], -- we can have a count or not
145− (m,mc) <- [([MShift],2::Int), ([MCtrl],5), ([MMeta],3),
146− ([MShift, MCtrl],6), ([MShift, MMeta],4)], -- modifiers and their codes
147− (c,s) <- [("A", KUp), ("B", KDown), ("C", KRight), ("D", KLeft), ("H", KHome), ("F", KEnd)] -- directions and their codes
148− ],
149−
150− let k n s = ("\ESC["++show n++"~",(s,[]))
151− in zipWith k [2::Int,3,5,6,1,4]
152− [KIns,KDel,KPageUp,KPageDown,KHome,KEnd],
153−
154− let k n s = ("\ESC["++show n++";5~",(s,[MCtrl]))
155− in zipWith k [2::Int,3,5,6,1,4]
156− [KIns,KDel,KPageUp,KPageDown,KHome,KEnd],
157−
158− -- Support for simple characters.
159− [ (x:[],(KASCII x,[])) | x <- map toEnum [0..255] ],
160−
161− -- Support for function keys (should use terminfo)
162− [ ("\ESC[["++[toEnum(64+i)],(KFun i,[])) | i <- [1..5] ],
163− let f ff nrs m = [ ("\ESC["++show n++"~",(KFun (n-(nrs!!0)+ff), m)) | n <- nrs ] in
164− concat [ f 6 [17..21] [], f 11 [23,24] [], f 1 [25,26] [MShift], f 3 [28,29] [MShift], f 5 [31..34] [MShift] ],
165− [ ('\ESC':[x],(KASCII x,[MMeta])) | x <- '\ESC':'\t':[' ' .. '\DEL'] ],
166−
167− -- Ctrl+Char
168− [ ([toEnum x],(KASCII y,[MCtrl]))
169− | (x,y) <- zip ([0..31]) ('@':['a'..'z']++['['..'_']),
170− y /= 'i' -- Resolve issue #3 where CTRL-i hides TAB.
171− ],
172−
173− -- Ctrl+Meta+Char
174− [ ('\ESC':[toEnum x],(KASCII y,[MMeta,MCtrl])) | (x,y) <- zip [0..31] ('@':['a'..'z']++['['..'_']) ],
175−
176− -- Special support
177− [ -- special support for ESC
178− ("\ESC",(KEsc,[])) , ("\ESC\ESC",(KEsc,[MMeta])),
179−
180− -- Special support for backspace
181− ("\DEL",(KBS,[])), ("\ESC\DEL",(KBS,[MMeta])),
182−
183− -- Special support for Enter
184− ("\ESC\^J",(KEnter,[MMeta])), ("\^J",(KEnter,[])) ]
185− ]
186−
187133 eventThreadId <- forkIO $ inputToEventThread
188134 inputThreadId <- forkIO $ inputThread
189135 noInputThreadId <- forkIO $ noInputThread