on master help sign in
start to move all input map config to the same scheme
23a5b90Corey O'Connor
src/Graphics/Vty/Config.hs+14−6
@@ -36,22 +36,25 @@
36-- Directive format:
36-- Directive format:
37--
37--
38-- @
38-- @
39−-- \"map\" string key modifier_list
39+-- \"map\" term string key modifier_list
40-- where
40-- where
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
44-- @
45-- @
45--
46--
46-- EG: If the contents are
47-- EG: If the contents are
47--
48--
48-- @
49-- @
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 []
51-- @
53-- @
52--
54--
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@.
55--
58--
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
57-- format.
60-- format.
@@ -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
87
90
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+
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.
94 --
101 --
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)
98
105
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
src/Graphics/Vty/Input/Events.hs+2−3
@@ -1,5 +1,7 @@
1module Graphics.Vty.Input.Events where
1module Graphics.Vty.Input.Events where
2
2
3+import Data.Map (Map)
4+
3-- | Representations of non-modifier keys.
5-- | Representations of non-modifier keys.
4--
6--
5-- * KFun is indexed from 0 to 63. Range of supported FKeys varies by terminal and keyboard.
7-- * KFun is indexed from 0 to 63. Range of supported FKeys varies by terminal and keyboard.
@@ -38,6 +40,3 @@ data Event
38 | EvResize Int Int
40 | EvResize Int Int
39 deriving (Eq,Show,Ord)
41 deriving (Eq,Show,Ord)
40
42
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
21exampleConfig :: String
21exampleConfig :: String
22exampleConfig = [s|
22exampleConfig = [s|
23-- comments should be ignored.
23-- comments should be ignored.
24−map "\ESC[B" KUp []
24+map _ "\ESC[B" KUp []
25askfjla dfasjdflk jasdlkfj asdfj -- lines failing parse should be ignored
25askfjla dfasjdflk jasdlkfj asdfj -- lines failing parse should be ignored
26+map _ "\ESC[1;3B" KDown [MAlt]
27+map "xterm" "\ESC[1;3B" KDown [MAlt]
26−map "\ESC[1;3B" KDown [MAlt]
28+map "xterm-256-color" "\ESC[1;3B" KDown [MAlt]
27debugLog "/tmp/vty-debug.txt"
29debugLog "/tmp/vty-debug.txt"
28|]
30|]
29
31