summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/Monitors
diff options
context:
space:
mode:
authorTodd Lunter <tlunter@gmail.com>2013-05-26 13:23:59 -0400
committerTodd Lunter <tlunter@gmail.com>2013-05-26 13:23:59 -0400
commitf655873269ccd8992c5f5610327a24f78c449403 (patch)
treea8800a63ae49bc8611d53c30128edb953bf534fc /src/Plugins/Monitors
parent12424d6eda711947eff7fad4f1429627b780fe01 (diff)
downloadxmobar-f655873269ccd8992c5f5610327a24f78c449403.tar.gz
xmobar-f655873269ccd8992c5f5610327a24f78c449403.tar.bz2
Made parseTemplate recursively replace template variables.
Diffstat (limited to 'src/Plugins/Monitors')
-rw-r--r--src/Plugins/Monitors/Batt.hs5
-rw-r--r--src/Plugins/Monitors/Common.hs26
2 files changed, 14 insertions, 17 deletions
diff --git a/src/Plugins/Monitors/Batt.hs b/src/Plugins/Monitors/Batt.hs
index eddec06..4c0232f 100644
--- a/src/Plugins/Monitors/Batt.hs
+++ b/src/Plugins/Monitors/Batt.hs
@@ -163,9 +163,8 @@ runBatt' bfs args = do
case c of
Result x w t s ->
do l <- fmtPercent x
- let ts = [fmtTime $ floor t, fmtWatts w opts suffix d]
- s' <- parseTemplate' (s ++ "<acstatus>") (l ++ "":ts)
- parseTemplate (l ++ s':ts)
+ let ts = [fmtTime $ floor t, fmtWatts w opts suffix d]
+ parseTemplate (l ++ s:ts)
NA -> return "N/A"
where fmtPercent :: Float -> Monitor [String]
fmtPercent x = do
diff --git a/src/Plugins/Monitors/Common.hs b/src/Plugins/Monitors/Common.hs
index 881d679..5caaa85 100644
--- a/src/Plugins/Monitors/Common.hs
+++ b/src/Plugins/Monitors/Common.hs
@@ -302,28 +302,26 @@ templateParser = many templateStringParser --"%")
parseTemplate :: [String] -> Monitor String
parseTemplate l =
do t <- getConfigValue template
- s <- io $ runP templateParser t
e <- getConfigValue export
let m = Map.fromList . zip e $ l
- return $ combine m s
+ parseTemplate' t m
-- | Works like parseTemplate, but using the given template string.
-parseTemplate' :: String -> [String] -> Monitor String
-parseTemplate' t l = do
- t' <- getConfigValue template
- setConfigValue t template
- r <- parseTemplate l
- setConfigValue t' template
- return r
+parseTemplate' :: String -> Map.Map String String -> Monitor String
+parseTemplate' t m =
+ do s <- io $ runP templateParser t
+ combine m s
-- | Given a finite "Map" and a parsed templatet produces the
-- | resulting output string.
-combine :: Map.Map String String -> [(String, String, String)] -> String
-combine _ [] = []
+combine :: Map.Map String String -> [(String, String, String)] -> Monitor String
+combine _ [] = return []
combine m ((s,ts,ss):xs) =
- s ++ str ++ ss ++ combine m xs
- where str = Map.findWithDefault err ts m
- err = "<" ++ ts ++ " not found!>"
+ do next <- combine m xs
+ let str = Map.findWithDefault err ts m
+ err = "<" ++ ts ++ " not found!>"
+ nstr <- parseTemplate' str m
+ return $ s ++ (if nstr == [] then str else nstr) ++ ss ++ next
-- $strings