@@ -2,8 +2,8 @@
22{-# LANGUAGE NoMonomorphismRestriction #-}
33-- | A 'Config' can be provided to mkVty to customize the applications use of vty.
44--
5−-- The 'Config' provided is mappend'd to 'Config's loaded from $HOME/.config/vty.config and
6−-- $VTY_CONFIG_FILE. The $VTY_CONFIG_FILE takes precedence over the input.conf file or the
5+-- The 'Config' provided is mappend'd to 'Config's loaded from 'getAppUserDataDirectory'`/config`
6+-- and $VTY_CONFIG_FILE. The $VTY_CONFIG_FILE takes precedence over the `config` file or the
77-- application provided 'Config'.
88--
99-- Each line of the input config is processed individually. Lines that fail to parse are ignored.
@@ -35,6 +35,7 @@ module Graphics.Vty.Config where
3535
3636import Control.Applicative hiding (many)
3737
38+import Control.Exception (catch, IOException)
3839import Control.Monad (void)
3940import Control.Monad.Trans.Class
4041import Control.Monad.Trans.Writer
@@ -45,6 +46,8 @@ import Data.Monoid
4546
4647import Graphics.Vty.Input.Events
4748
49+import System.Directory (getAppUserDataDirectory)
50+import System.Environment (lookupEnv)
4851import Text.Parsec hiding ((<|>))
4952import Text.Parsec.Token ( GenLanguageDef(..) )
5053import qualified Text.Parsec.Token as P
@@ -81,12 +84,14 @@ type ConfigParser s a = ParsecT s () (Writer Config) a
8184
8285userConfig :: IO Config
8386userConfig = do
84− userGlobalConfig <- parseConfigFile "$HOME/.config/vty.config"
85− overrideConfig <- parseConfigFile "$VTY_CONFIG_FILE"
86− return $ userGlobalConfig `mappend` overrideConfig
87+ vtyConfig <- (mappend <$> getAppUserDataDirectory "vty" <*> pure "/config") >>= parseConfigFile
88+ overrideConfig <- lookupEnv "VTY_CONFIG_FILE" >>= maybe (return def) parseConfigFile
89+ return $ vtyConfig `mappend` overrideConfig
8790
8891parseConfigFile :: FilePath -> IO Config
89−parseConfigFile path = runParseConfig path <$> BS.readFile path
92+parseConfigFile path = do
93+ catch (runParseConfig path <$> BS.readFile path)
94+ (\(e :: IOException) -> return def)
9095
9196runParseConfig :: Stream s (Writer Config) Char => String -> s -> Config
9297runParseConfig name = execWriter . runParserT parseConfig () name