@@ -36,22 +36,25 @@
3636-- Directive format:
3737--
3838-- @
39−-- \"map\" string key modifier_list
39+-- \"map\" term string key modifier_list
4040-- where
4141-- key := KEsc | KChar Char | KBS ... (same as 'Key')
4242-- modifier_list := \"[\" modifier+ \"]\"
4343-- modifier := MShift | MCtrl | MMeta | MAlt
44+-- term := "_" | string
4445-- @
4546--
4647-- EG: If the contents are
4748--
4849-- @
49−-- map \"\\ESC[B\" KUp []
50−-- map \"\\ESC[1;3B\" KDown [MAlt]
50+-- map _ \"\\ESC[B\" KUp []
51+-- map _ \"\\ESC[1;3B\" KDown [MAlt]
52+-- map "xterm" \"\\ESC[D\" KLeft []
5153-- @
5254--
53−-- Then the bytes @\"\\ESC[B\"@ will result in the KUp event. The bytes @\"\\ESC[1;3B\"@ will result
54−-- in the event KDown with the MAlt modifier.
55+-- Then the bytes @\"\\ESC[B\"@ will result in the KUp event on all terminals. The bytes
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@.
5558--
5659-- If a debug log is requested then vty will output the current input table to the log in the above
5760-- format.
@@ -85,6 +88,10 @@ import Text.Parsec hiding ((<|>))
8588import Text.Parsec.Token ( GenLanguageDef(..) )
8689import qualified Text.Parsec.Token as P
8790
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)]
94+
8895data Config = Config
8996 { specifiedEscPeriod :: Maybe Int
9097 -- | Debug information is appended to this file if not Nothing.
@@ -93,7 +100,7 @@ data Config = Config
93100 -- from terminfo.
94101 --
95102 -- See "Graphics.Vty.Config" module documentation for documentation of the @map@ directive.
96− , inputOverrides :: ClassifyTable
103+ , inputMap :: InputMap
97104 } deriving (Show, Eq)
98105
99106-- | AKA VTIME. The default is 100000 microseconds or 0.1 seconds. Set using the
@@ -161,6 +168,7 @@ configLexer = P.makeTokenParser configLanguage
161168mapDecl = do
162169 void $ string "map"
163170 P.whiteSpace configLexer
171+ termIdent <- (char "_" >> return Nothing) <|>
164172 bytes <- P.stringLiteral configLexer
165173 key <- parseKey
166174 modifiers <- parseModifiers