diff --git a/src/Data/Terminfo/Parse.hs b/src/Data/Terminfo/Parse.hs index db5b7c7..9904e53 100644 --- a/src/Data/Terminfo/Parse.hs +++ b/src/Data/Terminfo/Parse.hs @@ -16,7 +16,7 @@ import qualified Data.Vector.Unboxed as Vector import Numeric (showHex) -import Text.ParserCombinators.Parsec +import Text.Parsec data CapExpression = CapExpression { capOps :: !CapOps diff --git a/src/Graphics/Vty/Config.hs b/src/Graphics/Vty/Config.hs index 4420e73..3f8a0ce 100644 --- a/src/Graphics/Vty/Config.hs +++ b/src/Graphics/Vty/Config.hs @@ -7,11 +7,17 @@ module Graphics.Vty.Config where import Data.Default +import Data.Either (either) +import Data.Monoid import Graphics.Vty.Input.Events import System.FilePath +import Text.Parsec +import qualified Text.Parsec.Token as P +import Text.Parsec.Language (haskellDef) + data Config = Config { singleEscPeriod :: Int -- ^ AKA VTIME. The default is 100000 microseconds or 0.1 seconds. -- | Debug information about the input process is appended to the file. @@ -26,5 +32,22 @@ instance Default Config where , inputOverrides = [] } +-- not a proper monoid but useful as one. +instance Monoid Config where + mempty = def + mappend c0 c1 = c1 { inputOverrides = inputOverrides c0 <> inputOverrides c1 } + parseConfigFile :: FilePath -> IO Config -parseConfigFile path = return def +parseConfigFile path = either (const def) id <$> parseFromFile parseConfig path + +parseConfig = do + let lexer = P.makeTokenParser haskellDef + parseOverride = do + P.whiteSpace lexer + string "map" + P.whiteSpace lexer + bytes <- P.stringLiteral + key <- parseKey + modifier <- parseModifier + _ <- manyTill space newline + overrides <- many $ try parseOverride <|> ignoreOverride