{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
module Graphics.Vty.Input.Terminfo where
import Graphics.Vty.Input.Events
import qualified Graphics.Vty.Input.Terminfo.ANSIVT as ANSIVT
import Control.Arrow
import System.Console.Terminfo
classifyMapForTerm :: String -> Terminal -> ClassifyMap
classifyMapForTerm :: String -> Terminal -> ClassifyMap
classifyMapForTerm String
termName Terminal
term =
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall a b. (a -> b) -> a -> b
$ Terminal -> ClassifyMap -> ClassifyMap
capsClassifyMap Terminal
term ClassifyMap
keysFromCapsTable
forall a. a -> [a] -> [a]
: ClassifyMap
universalTable
forall a. a -> [a] -> [a]
: String -> [ClassifyMap]
termSpecificTables String
termName
universalTable :: ClassifyMap
universalTable :: ClassifyMap
universalTable = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ClassifyMap
visibleChars, ClassifyMap
ctrlChars, ClassifyMap
ctrlMetaChars, ClassifyMap
specialSupportKeys]
capsClassifyMap :: Terminal -> [(String,Event)] -> ClassifyMap
capsClassifyMap :: Terminal -> ClassifyMap -> ClassifyMap
capsClassifyMap Terminal
terminal ClassifyMap
table = [(String
x,Event
y) | (Just String
x,Event
y) <- forall a b. (a -> b) -> [a] -> [b]
map forall {d}. (String, d) -> (Maybe String, d)
extractCap ClassifyMap
table]
where extractCap :: (String, d) -> (Maybe String, d)
extractCap = forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (forall a. Terminal -> Capability a -> Maybe a
getCapability Terminal
terminal forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Capability String
tiGetStr)
termSpecificTables :: String -> [ClassifyMap]
termSpecificTables :: String -> [ClassifyMap]
termSpecificTables String
_termName = [ClassifyMap]
ANSIVT.classifyTable
visibleChars :: ClassifyMap
visibleChars :: ClassifyMap
visibleChars = [ ([Char
x], Key -> [Modifier] -> Event
EvKey (Char -> Key
KChar Char
x) [])
| Char
x <- [Char
' ' .. forall a. Enum a => Int -> a
toEnum Int
0xC1]
]
ctrlChars :: ClassifyMap
ctrlChars :: ClassifyMap
ctrlChars =
[ ([forall a. Enum a => Int -> a
toEnum Int
x],Key -> [Modifier] -> Event
EvKey (Char -> Key
KChar Char
y) [Modifier
MCtrl])
| (Int
x,Char
y) <- forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0..Int
31] (Char
'@'forall a. a -> [a] -> [a]
:[Char
'a'..Char
'z']forall a. [a] -> [a] -> [a]
++[Char
'['..Char
'_'])
, Char
y forall a. Eq a => a -> a -> Bool
/= Char
'i'
, Char
y forall a. Eq a => a -> a -> Bool
/= Char
'h'
]
ctrlMetaChars :: ClassifyMap
ctrlMetaChars :: ClassifyMap
ctrlMetaChars = forall a b. (a -> b) -> [a] -> [b]
map (\(String
s,EvKey Key
c [Modifier]
m) -> (Char
'\ESC'forall a. a -> [a] -> [a]
:String
s, Key -> [Modifier] -> Event
EvKey Key
c (Modifier
MMetaforall a. a -> [a] -> [a]
:[Modifier]
m))) ClassifyMap
ctrlChars
specialSupportKeys :: ClassifyMap
specialSupportKeys :: ClassifyMap
specialSupportKeys =
[ (String
"\ESC\ESC[5~",Key -> [Modifier] -> Event
EvKey Key
KPageUp [Modifier
MMeta])
, (String
"\ESC\ESC[6~",Key -> [Modifier] -> Event
EvKey Key
KPageDown [Modifier
MMeta])
, (String
"\ESC",Key -> [Modifier] -> Event
EvKey Key
KEsc []), (String
"\ESC\ESC",Key -> [Modifier] -> Event
EvKey Key
KEsc [Modifier
MMeta])
, (String
"\DEL",Key -> [Modifier] -> Event
EvKey Key
KBS []), (String
"\ESC\DEL",Key -> [Modifier] -> Event
EvKey Key
KBS [Modifier
MMeta]), (String
"\b",Key -> [Modifier] -> Event
EvKey Key
KBS [])
, (String
"\ESC\^J",Key -> [Modifier] -> Event
EvKey Key
KEnter [Modifier
MMeta]), (String
"\^J",Key -> [Modifier] -> Event
EvKey Key
KEnter [])
, (String
"\t", Key -> [Modifier] -> Event
EvKey (Char -> Key
KChar Char
'\t') [])
]
keysFromCapsTable :: ClassifyMap
keysFromCapsTable :: ClassifyMap
keysFromCapsTable =
[ (String
"ka1", Key -> [Modifier] -> Event
EvKey Key
KUpLeft [])
, (String
"ka3", Key -> [Modifier] -> Event
EvKey Key
KUpRight [])
, (String
"kb2", Key -> [Modifier] -> Event
EvKey Key
KCenter [])
, (String
"kbs", Key -> [Modifier] -> Event
EvKey Key
KBS [])
, (String
"kbeg", Key -> [Modifier] -> Event
EvKey Key
KBegin [])
, (String
"kcbt", Key -> [Modifier] -> Event
EvKey Key
KBackTab [])
, (String
"kc1", Key -> [Modifier] -> Event
EvKey Key
KDownLeft [])
, (String
"kc3", Key -> [Modifier] -> Event
EvKey Key
KDownRight [])
, (String
"kdch1", Key -> [Modifier] -> Event
EvKey Key
KDel [])
, (String
"kcud1", Key -> [Modifier] -> Event
EvKey Key
KDown [])
, (String
"kend", Key -> [Modifier] -> Event
EvKey Key
KEnd [])
, (String
"kent", Key -> [Modifier] -> Event
EvKey Key
KEnter [])
, (String
"khome", Key -> [Modifier] -> Event
EvKey Key
KHome [])
, (String
"kich1", Key -> [Modifier] -> Event
EvKey Key
KIns [])
, (String
"kcub1", Key -> [Modifier] -> Event
EvKey Key
KLeft [])
, (String
"knp", Key -> [Modifier] -> Event
EvKey Key
KPageDown [])
, (String
"kpp", Key -> [Modifier] -> Event
EvKey Key
KPageUp [])
, (String
"kcuf1", Key -> [Modifier] -> Event
EvKey Key
KRight [])
, (String
"kDC", Key -> [Modifier] -> Event
EvKey Key
KDel [Modifier
MShift])
, (String
"kEND", Key -> [Modifier] -> Event
EvKey Key
KEnd [Modifier
MShift])
, (String
"kHOM", Key -> [Modifier] -> Event
EvKey Key
KHome [Modifier
MShift])
, (String
"kIC", Key -> [Modifier] -> Event
EvKey Key
KIns [Modifier
MShift])
, (String
"kLFT", Key -> [Modifier] -> Event
EvKey Key
KLeft [Modifier
MShift])
, (String
"kRIT", Key -> [Modifier] -> Event
EvKey Key
KRight [Modifier
MShift])
, (String
"kcuu1", Key -> [Modifier] -> Event
EvKey Key
KUp [])
] forall a. [a] -> [a] -> [a]
++ ClassifyMap
functionKeyCapsTable
functionKeyCapsTable :: ClassifyMap
functionKeyCapsTable :: ClassifyMap
functionKeyCapsTable = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a b. (a -> b) -> [a] -> [b]
map [Int
0..Int
63] forall a b. (a -> b) -> a -> b
$ \Int
n -> (String
"kf" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Int
n, Key -> [Modifier] -> Event
EvKey (Int -> Key
KFun Int
n) [])