@@ -36,22 +36,25 @@
36-- Directive format:
36-- Directive format:
39−-- \"map\" string key modifier_list
39+-- \"map\" term string key modifier_list
41-- key := KEsc | KChar Char | KBS ... (same as 'Key')
41-- key := KEsc | KChar Char | KBS ... (same as 'Key')
42-- modifier_list := \"[\" modifier+ \"]\"
42-- modifier_list := \"[\" modifier+ \"]\"
43-- modifier := MShift | MCtrl | MMeta | MAlt
43-- modifier := MShift | MCtrl | MMeta | MAlt
44+-- term := "_" | string
46-- EG: If the contents are
47-- EG: If the contents are
49−-- map \"\\ESC[B\" KUp []
50+-- map _ \"\\ESC[B\" KUp []
50−-- map \"\\ESC[1;3B\" KDown [MAlt]
51+-- map _ \"\\ESC[1;3B\" KDown [MAlt]
52+-- map "xterm" \"\\ESC[D\" KLeft []
53−-- Then the bytes @\"\\ESC[B\"@ will result in the KUp event. The bytes @\"\\ESC[1;3B\"@ will result
55+-- Then the bytes @\"\\ESC[B\"@ will result in the KUp event on all terminals. The bytes
54−-- in the event KDown with the MAlt modifier.
56+-- @\"\\ESC[1;3B\"@ will result in the event KDown with the MAlt modifier on all terminals.
57+-- The bytes @\"\\ESC[D\"@ will result in the KLeft event when @TERM@ is @xterm@.
56-- If a debug log is requested then vty will output the current input table to the log in the above
59-- If a debug log is requested then vty will output the current input table to the log in the above
@@ -85,6 +88,10 @@ import Text.Parsec hiding ((<|>))
85import Text.Parsec.Token ( GenLanguageDef(..) )
88import Text.Parsec.Token ( GenLanguageDef(..) )
86import qualified Text.Parsec.Token as P
89import qualified Text.Parsec.Token as P
91+-- | Mappings from input bytes to event in the order specified. Later entries take precedence over
92+-- earlier in the case multiple entries have the same byte string.
93+type InputMap = [(Maybe String, String, Event)]
88data Config = Config
95data Config = Config
89 { specifiedEscPeriod :: Maybe Int
96 { specifiedEscPeriod :: Maybe Int
90 -- | Debug information is appended to this file if not Nothing.
97 -- | Debug information is appended to this file if not Nothing.
@@ -93,7 +100,7 @@ data Config = Config
93 -- from terminfo.
100 -- from terminfo.
95 -- See "Graphics.Vty.Config" module documentation for documentation of the @map@ directive.
102 -- See "Graphics.Vty.Config" module documentation for documentation of the @map@ directive.
96− , inputOverrides :: ClassifyTable
103+ , inputMap :: InputMap
97 } deriving (Show, Eq)
104 } deriving (Show, Eq)
99-- | AKA VTIME. The default is 100000 microseconds or 0.1 seconds. Set using the
106-- | AKA VTIME. The default is 100000 microseconds or 0.1 seconds. Set using the
@@ -161,6 +168,7 @@ configLexer = P.makeTokenParser configLanguage
161mapDecl = do
168mapDecl = do
162 void $ string "map"
169 void $ string "map"
163 P.whiteSpace configLexer
170 P.whiteSpace configLexer
171+ termIdent <- (char "_" >> return Nothing) <|>
164 bytes <- P.stringLiteral configLexer
172 bytes <- P.stringLiteral configLexer
165 key <- parseKey
173 key <- parseKey
166 modifiers <- parseModifiers
174 modifiers <- parseModifiers