From df35f664776cbb4b588f9ee71853d2be784364fc Mon Sep 17 00:00:00 2001 From: Adam Vogt Date: Wed, 23 Sep 2009 04:28:35 +0200 Subject: Output to stdout whenever fields are defaulted in a config. Ignore-this: 3bf71f10543f14aa17b6b403480bcdde This is done without a command line flag, but perhaps it should be. darcs-hash:20090923022835-1499c-d05af3db7816672e8a8cb4987215dcc3f9a96947.gz --- Main.hs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'Main.hs') diff --git a/Main.hs b/Main.hs index 44dda60..a94c597 100644 --- a/Main.hs +++ b/Main.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE FlexibleContexts #-} ----------------------------------------------------------------------------- -- | -- Module : Xmobar.Main @@ -24,6 +25,8 @@ import Parsers import Config import XUtil +import Data.List (intercalate) + import Paths_xmobar (version) import Data.IORef import Data.Version (showVersion) @@ -33,6 +36,8 @@ import System.Exit import System.Environment import System.Posix.Files +import Control.Monad.Writer (MonadWriter,MonadIO,unless,runWriterT) + -- $main -- | The main entry point @@ -41,9 +46,12 @@ main = do d <- openDisplay "" args <- getArgs (o,file) <- getOpts args - c <- case file of - [cfgfile] -> readConfig cfgfile - _ -> readDefaultConfig + (c,defaultings) <- runWriterT $ case file of + [cfgfile] -> readConfig cfgfile + _ -> readDefaultConfig + + unless (null defaultings) $ putStrLn $ "Fields missing from config defaulted: " + ++ intercalate "," defaultings -- listen for ConfigureEvents on the root window, for xrandr support: rootw <- rootWindow d (defaultScreen d) @@ -60,18 +68,18 @@ main = do releaseFont d fs -- | Reads the configuration files or quits with an error -readConfig :: FilePath -> IO Config +readConfig :: (MonadIO m, MonadWriter [String] m) => FilePath -> m Config readConfig f = do - file <- fileExist f - s <- if file then readFileSafe f else error $ f ++ ": file not found!\n" ++ usage + file <- io $ fileExist f + s <- io $ if file then readFileSafe f else error $ f ++ ": file not found!\n" ++ usage either (\err -> error $ f ++ ": configuration file contains errors at:\n" ++ show err) - return $ parseConfig s + id $ parseConfig s -- | Read default configuration file or load the default config -readDefaultConfig :: IO Config +readDefaultConfig :: (MonadIO m, MonadWriter [String] m) => m Config readDefaultConfig = do - home <- getEnv "HOME" + home <- io $ getEnv "HOME" let path = home ++ "/.xmobarrc" - f <- fileExist path + f <- io $ fileExist path if f then readConfig path else return defaultConfig data Opts = Help -- cgit v1.2.3