on master help sign in
start to move all input map config to the same scheme
commit23a5b904086ebf039f831f026ef32506facf2eb5 authorCorey O'Connor <coreyoconnor@gmail.com> dateMon 2 Jun 2014, 23:06 (12 years ago) parent2c756c1
3 files changed+20−11
src/Graphics/Vty/Config.hs+14−6 src/Graphics/Vty/Input/Events.hs+2−3 test/VerifyConfig.hs+4−2
src/Graphics/Vty/Config.hs+14−6
@@ -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
src/Graphics/Vty/Input/Events.hs+2−3
@@ -1,5 +1,7 @@
11module Graphics.Vty.Input.Events where
22
3+import Data.Map (Map)
4+
35-- | Representations of non-modifier keys.
46--
57-- * KFun is indexed from 0 to 63. Range of supported FKeys varies by terminal and keyboard.
@@ -38,6 +40,3 @@ data Event
3840 | EvResize Int Int
3941 deriving (Eq,Show,Ord)
4042
41−-- | representation of mapping from input bytes to event. Later entries take precedence over earlier
42−-- in the case multiple entries have the same byte string.
43−type ClassifyTable = [(String, Event)]
test/VerifyConfig.hs+4−2
@@ -21,9 +21,11 @@ import Text.Printf
2121exampleConfig :: String
2222exampleConfig = [s|
2323-- comments should be ignored.
24−map "\ESC[B" KUp []
24+map _ "\ESC[B" KUp []
2525askfjla dfasjdflk jasdlkfj asdfj -- lines failing parse should be ignored
26−map "\ESC[1;3B" KDown [MAlt]
26+map _ "\ESC[1;3B" KDown [MAlt]
27+map "xterm" "\ESC[1;3B" KDown [MAlt]
28+map "xterm-256-color" "\ESC[1;3B" KDown [MAlt]
2729debugLog "/tmp/vty-debug.txt"
2830|]
2931