@@ -76,6 +76,7 @@ module Graphics.Vty.Config
76 , standardIOConfig
76 , standardIOConfig
77 , runParseConfig
77 , runParseConfig
78 , parseConfigFile
78 , parseConfigFile
@@ -87,7 +88,6 @@ import Control.Exception (catch, IOException, Exception(..), throwIO)
87import Control.Monad (liftM, guard, void)
88import Control.Monad (liftM, guard, void)
89import qualified Data.ByteString as BS
90import qualified Data.ByteString as BS
91import Data.Monoid
91import Data.Monoid
92import Data.Typeable (Typeable)
92import Data.Typeable (Typeable)
@@ -146,8 +146,8 @@ data Config = Config
146 , termName :: Maybe String
146 , termName :: Maybe String
147 } deriving (Show, Eq)
147 } deriving (Show, Eq)
149−instance Default Config where
149+defaultConfig :: Config
150− def = mempty
150+defaultConfig = mempty
152instance Monoid Config where
152instance Monoid Config where
153 mempty = Config
153 mempty = Config
@@ -179,14 +179,14 @@ instance Monoid Config where
179userConfig :: IO Config
179userConfig :: IO Config
180userConfig = do
180userConfig = do
181 configFile <- (mappend <$> getAppUserDataDirectory "vty" <*> pure "/config") >>= parseConfigFile
181 configFile <- (mappend <$> getAppUserDataDirectory "vty" <*> pure "/config") >>= parseConfigFile
182− overrideConfig <- maybe (return def) parseConfigFile =<< getEnv "VTY_CONFIG_FILE"
182+ overrideConfig <- maybe (return defaultConfig) parseConfigFile =<< getEnv "VTY_CONFIG_FILE"
183 let base = configFile <> overrideConfig
183 let base = configFile <> overrideConfig
184 mappend base <$> overrideEnvConfig
184 mappend base <$> overrideEnvConfig
186overrideEnvConfig :: IO Config
186overrideEnvConfig :: IO Config
187overrideEnvConfig = do
187overrideEnvConfig = do
188 d <- getEnv "VTY_DEBUG_LOG"
188 d <- getEnv "VTY_DEBUG_LOG"
189− return $ def { debugLog = d }
189+ return $ defaultConfig { debugLog = d }
191-- | Configures VTY using defaults suitable for terminals. This action
191-- | Configures VTY using defaults suitable for terminals. This action
192-- can raise 'VtyConfigurationError'.
192-- can raise 'VtyConfigurationError'.
@@ -196,7 +196,7 @@ standardIOConfig = do
196 case mb of
196 case mb of
197 Nothing -> throwIO VtyMissingTermEnvVar
197 Nothing -> throwIO VtyMissingTermEnvVar
198 Just t ->
198 Just t ->
199− return def
199+ return defaultConfig
200 { vmin = Just 1
200 { vmin = Just 1
201 , mouseMode = Just False
201 , mouseMode = Just False
202 , bracketedPasteMode = Just False
202 , bracketedPasteMode = Just False
@@ -209,13 +209,13 @@ standardIOConfig = do
209parseConfigFile :: FilePath -> IO Config
209parseConfigFile :: FilePath -> IO Config
210parseConfigFile path = do
210parseConfigFile path = do
211 catch (runParseConfig path <$> BS.readFile path)
211 catch (runParseConfig path <$> BS.readFile path)
212− (\(_ :: IOException) -> return def)
212+ (\(_ :: IOException) -> return defaultConfig)
214runParseConfig :: String -> BS.ByteString -> Config
214runParseConfig :: String -> BS.ByteString -> Config
215runParseConfig name cfgTxt =
215runParseConfig name cfgTxt =
216 case runParser parseConfig () name cfgTxt of
216 case runParser parseConfig () name cfgTxt of
217 Right cfg -> cfg
217 Right cfg -> cfg
218− Left{} -> def
218+ Left{} -> defaultConfig
220------------------------------------------------------------------------
220------------------------------------------------------------------------
@@ -249,13 +249,13 @@ mapDecl = do
249 bytes <- P.stringLiteral configLexer
249 bytes <- P.stringLiteral configLexer
250 key <- parseValue
250 key <- parseValue
251 modifiers <- parseValue
251 modifiers <- parseValue
252− return def { inputMap = [(termIdent, bytes, EvKey key modifiers)] }
252+ return defaultConfig { inputMap = [(termIdent, bytes, EvKey key modifiers)] }
254debugLogDecl :: Parser Config
254debugLogDecl :: Parser Config
255debugLogDecl = do
255debugLogDecl = do
256 "debugLog" <- P.identifier configLexer
256 "debugLog" <- P.identifier configLexer
257 path <- P.stringLiteral configLexer
257 path <- P.stringLiteral configLexer
258− return def { debugLog = Just path }
258+ return defaultConfig { debugLog = Just path }
260ignoreLine :: Parser ()
260ignoreLine :: Parser ()
261ignoreLine = void $ manyTill anyChar newline
261ignoreLine = void $ manyTill anyChar newline
@@ -264,7 +264,7 @@ parseConfig :: Parser Config
264parseConfig = liftM mconcat $ many $ do
264parseConfig = liftM mconcat $ many $ do
265 P.whiteSpace configLexer
265 P.whiteSpace configLexer
266 let directives = [try mapDecl, try debugLogDecl]
266 let directives = [try mapDecl, try debugLogDecl]
267− choice directives <|> (ignoreLine >> return def)
267+ choice directives <|> (ignoreLine >> return defaultConfig)
269class Parse a where parseValue :: Parser a
269class Parse a where parseValue :: Parser a
270instance Parse Char where parseValue = P.charLiteral configLexer
270instance Parse Char where parseValue = P.charLiteral configLexer