{-# 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 =
[ClassifyMap] -> ClassifyMap
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([ClassifyMap] -> ClassifyMap) -> [ClassifyMap] -> ClassifyMap
forall a b. (a -> b) -> a -> b
$ Terminal -> ClassifyMap -> ClassifyMap
capsClassifyMap Terminal
term ClassifyMap
keysFromCapsTable
ClassifyMap -> [ClassifyMap] -> [ClassifyMap]
forall a. a -> [a] -> [a]
: ClassifyMap
universalTable
ClassifyMap -> [ClassifyMap] -> [ClassifyMap]
forall a. a -> [a] -> [a]
: String -> [ClassifyMap]
termSpecificTables String
termName
universalTable :: ClassifyMap
universalTable :: ClassifyMap
universalTable = [ClassifyMap] -> ClassifyMap
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) <- ((String, Event) -> (Maybe String, Event))
-> ClassifyMap -> [(Maybe String, Event)]
forall a b. (a -> b) -> [a] -> [b]
map (String, Event) -> (Maybe String, Event)
forall d. (String, d) -> (Maybe String, d)
extractCap ClassifyMap
table]
where extractCap :: (String, d) -> (Maybe String, d)
extractCap = (String -> Maybe String) -> (String, d) -> (Maybe String, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (Terminal -> Capability String -> Maybe String
forall a. Terminal -> Capability a -> Maybe a
getCapability Terminal
terminal (Capability String -> Maybe String)
-> (String -> Capability String) -> String -> Maybe String
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
' ' .. Int -> Char
forall a. Enum a => Int -> a
toEnum Int
0xC1]
]
ctrlChars :: ClassifyMap
ctrlChars :: ClassifyMap
ctrlChars =
[ ([Int -> Char
forall a. Enum a => Int -> a
toEnum Int
x],Key -> [Modifier] -> Event
EvKey (Char -> Key
KChar Char
y) [Modifier
MCtrl])
| (Int
x,Char
y) <- [Int] -> String -> [(Int, Char)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0..Int
31] (Char
'@'Char -> String -> String
forall a. a -> [a] -> [a]
:[Char
'a'..Char
'z']String -> String -> String
forall a. [a] -> [a] -> [a]
++[Char
'['..Char
'_'])
, Char
y Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'i'
, Char
y Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'h'
]
ctrlMetaChars :: ClassifyMap
ctrlMetaChars :: ClassifyMap
ctrlMetaChars = ((String, Event) -> (String, Event)) -> ClassifyMap -> ClassifyMap
forall a b. (a -> b) -> [a] -> [b]
map (\(String
s,EvKey Key
c [Modifier]
m) -> (Char
'\ESC'Char -> String -> String
forall a. a -> [a] -> [a]
:String
s, Key -> [Modifier] -> Event
EvKey Key
c (Modifier
MMetaModifier -> [Modifier] -> [Modifier]
forall 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
"\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 [])
] ClassifyMap -> ClassifyMap -> ClassifyMap
forall a. [a] -> [a] -> [a]
++ ClassifyMap
functionKeyCapsTable
functionKeyCapsTable :: ClassifyMap
functionKeyCapsTable :: ClassifyMap
functionKeyCapsTable = ((Int -> (String, Event)) -> [Int] -> ClassifyMap)
-> [Int] -> (Int -> (String, Event)) -> ClassifyMap
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Int -> (String, Event)) -> [Int] -> ClassifyMap
forall a b. (a -> b) -> [a] -> [b]
map [Int
0..Int
63] ((Int -> (String, Event)) -> ClassifyMap)
-> (Int -> (String, Event)) -> ClassifyMap
forall a b. (a -> b) -> a -> b
$ \Int
n -> (String
"kf" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
n, Key -> [Modifier] -> Event
EvKey (Int -> Key
KFun Int
n) [])