on master help sign in
implement config parsing
commitce9515ad7a00e42dfd28a42a947fb7fc18379e66 authorCorey O'Connor <coreyoconnor@gmail.com> dateFri 18 Apr 2014, 21:44 (13 years ago) parent021a059
2 files changed+25−2
src/Data/Terminfo/Parse.hs+1−1 src/Graphics/Vty/Config.hs+24−1
src/Data/Terminfo/Parse.hs+1−1
@@ -16,7 +16,7 @@ import qualified Data.Vector.Unboxed as Vector
1616
1717import Numeric (showHex)
1818
19−import Text.ParserCombinators.Parsec
19+import Text.Parsec
2020
2121data CapExpression = CapExpression
2222 { capOps :: !CapOps
src/Graphics/Vty/Config.hs+24−1
@@ -7,11 +7,17 @@
77module Graphics.Vty.Config where
88
99import Data.Default
10+import Data.Either (either)
11+import Data.Monoid
1012
1113import Graphics.Vty.Input.Events
1214
1315import System.FilePath
1416
17+import Text.Parsec
18+import qualified Text.Parsec.Token as P
19+import Text.Parsec.Language (haskellDef)
20+
1521data Config = Config
1622 { singleEscPeriod :: Int -- ^ AKA VTIME. The default is 100000 microseconds or 0.1 seconds.
1723 -- | Debug information about the input process is appended to the file.
@@ -26,5 +32,22 @@ instance Default Config where
2632 , inputOverrides = []
2733 }
2834
35+-- not a proper monoid but useful as one.
36+instance Monoid Config where
37+ mempty = def
38+ mappend c0 c1 = c1 { inputOverrides = inputOverrides c0 <> inputOverrides c1 }
39+
2940parseConfigFile :: FilePath -> IO Config
30−parseConfigFile path = return def
41+parseConfigFile path = either (const def) id <$> parseFromFile parseConfig path
42+
43+parseConfig = do
44+ let lexer = P.makeTokenParser haskellDef
45+ parseOverride = do
46+ P.whiteSpace lexer
47+ string "map"
48+ P.whiteSpace lexer
49+ bytes <- P.stringLiteral
50+ key <- parseKey
51+ modifier <- parseModifier
52+ _ <- manyTill space newline
53+ overrides <- many $ try parseOverride <|> ignoreOverride