summaryrefslogtreecommitdiffhomepage
path: root/Monitors/Common.hs
diff options
context:
space:
mode:
authorKrzysztof Kosciuszkiewicz <k.kosciuszkiewicz@gmail.com>2007-07-10 16:08:45 +0200
committerKrzysztof Kosciuszkiewicz <k.kosciuszkiewicz@gmail.com>2007-07-10 16:08:45 +0200
commit528556a36d5ff686689568c61422143276b0dc96 (patch)
tree80d00a09a14146373d20759961bca381771af580 /Monitors/Common.hs
parent8453821a99a4a211b2c489f1a90fa1ecea8a690d (diff)
downloadxmobar-528556a36d5ff686689568c61422143276b0dc96.tar.gz
xmobar-528556a36d5ff686689568c61422143276b0dc96.tar.bz2
Clean up default options for monitors.
* Moved default configuration to Monitors.Common * Colors are optional and are off by default darcs-hash:20070710140845-ba08c-86afb9d30e4b71ad48539510feabde650b1b6045.gz
Diffstat (limited to 'Monitors/Common.hs')
-rw-r--r--Monitors/Common.hs39
1 files changed, 30 insertions, 9 deletions
diff --git a/Monitors/Common.hs b/Monitors/Common.hs
index 3408122..a7c33e6 100644
--- a/Monitors/Common.hs
+++ b/Monitors/Common.hs
@@ -20,6 +20,7 @@ module Monitors.Common (
, Opts (..)
, setConfigValue
, getConfigValue
+ , newConfig
, runMonitor
, runM
, io
@@ -65,11 +66,11 @@ import System.Exit
type Monitor a = ReaderT MConfig IO a
data MConfig =
- MC { normalColor :: IORef String
+ MC { normalColor :: IORef (Maybe String)
, low :: IORef Int
- , lowColor :: IORef String
+ , lowColor :: IORef (Maybe String)
, high :: IORef Int
- , highColor :: IORef String
+ , highColor :: IORef (Maybe String)
, template :: IORef String
, packageName :: IORef String
, usageTail :: IORef String
@@ -98,6 +99,24 @@ getConfigValue :: Selector a -> Monitor a
getConfigValue s =
sel s
+newConfig :: String
+ -> String
+ -> String
+ -> [OptDescr Opts]
+ -> [String]
+ -> IO MConfig
+newConfig tmpl pkg usg args exprts =
+ do lc <- newIORef Nothing
+ l <- newIORef 33
+ nc <- newIORef Nothing
+ h <- newIORef 66
+ hc <- newIORef Nothing
+ t <- newIORef tmpl
+ p <- newIORef pkg
+ u <- newIORef usg
+ a <- newIORef args
+ e <- newIORef exprts
+ return $ MC nc l lc h hc t p u a e
data Opts = Help
| Version
@@ -162,9 +181,9 @@ doConfigOptions (o:oo) =
Version -> io $ versinfo pn version >> exitWith ExitSuccess
High h -> setConfigValue (read h) high >> next
Low l -> setConfigValue (read l) low >> next
- HighColor hc -> setConfigValue hc highColor >> next
- NormalColor nc -> setConfigValue nc normalColor >> next
- LowColor lc -> setConfigValue lc lowColor >> next
+ HighColor hc -> setConfigValue (Just hc) highColor >> next
+ NormalColor nc -> setConfigValue (Just nc) normalColor >> next
+ LowColor lc -> setConfigValue (Just lc) lowColor >> next
Template t -> setConfigValue t template >> next
_ -> next
@@ -279,11 +298,13 @@ stringParser :: Pos -> B.ByteString -> String
stringParser (x,y) =
flip (!!) x . map B.unpack . B.words . flip (!!) y . B.lines
-setColor :: String -> Selector String -> Monitor String
+setColor :: String -> Selector (Maybe String) -> Monitor String
setColor str s =
do a <- getConfigValue s
- return $ "<fc=" ++ a ++ ">" ++
- str ++ "</fc>"
+ case a of
+ Nothing -> return str
+ Just c -> return $
+ "<fc=" ++ c ++ ">" ++ str ++ "</fc>"
showWithColors :: (Float -> String) -> Float -> Monitor String
showWithColors f x =