Config: expose vtyConfigPath, vtyConfigFileEnvName

This commit is contained in:
Jonathan Daugherty 2020-03-05 09:04:49 -08:00
parent 0bea225b6d
commit f1b7839875
2 changed files with 16 additions and 5 deletions

View File

@ -68,9 +68,11 @@ module Graphics.Vty.Config
, getTtyEraseChar
, currentTerminalName
, vtyConfigPath
, widthTableFilename
, vtyDataDirectory
, terminalWidthTablePath
, vtyConfigFileEnvName
)
where
@ -197,12 +199,20 @@ instance Monoid Config where
vtyDataDirectory :: IO FilePath
vtyDataDirectory = getAppUserDataDirectory "vty"
-- | Load a configuration from @'getAppUserDataDirectory'/config@ and
-- @$VTY_CONFIG_FILE@.
vtyConfigPath :: IO FilePath
vtyConfigPath = do
dir <- vtyDataDirectory
return $ dir </> "config"
vtyConfigFileEnvName :: String
vtyConfigFileEnvName = "VTY_CONFIG_FILE"
-- | Load a configuration from 'vtyConfigPath' and @$VTY_CONFIG_FILE@.
userConfig :: IO Config
userConfig = do
configFile <- (mappend <$> vtyDataDirectory <*> pure "/config") >>= parseConfigFile
overrideConfig <- maybe (return defaultConfig) parseConfigFile =<< lookupEnv "VTY_CONFIG_FILE"
configFile <- vtyConfigPath >>= parseConfigFile
overrideConfig <- maybe (return defaultConfig) parseConfigFile =<<
lookupEnv vtyConfigFileEnvName
let base = configFile <> overrideConfig
mappend base <$> overrideEnvConfig

View File

@ -84,9 +84,10 @@ main = do
putStrLn $ "\nOutput table written to " <> outputPath
Just tName <- currentTerminalName
configPath <- vtyConfigPath
putStrLn ""
putStrLn "To configure your Vty-based applications to use this map, add"
putStrLn "the following line to ~/.vty/config:"
putStrLn "the following line to " <> configPath <> ":"
putStrLn ""
putStrLn $ " widthMap " <> show tName <> " " <> show outputPath
putStrLn ""