summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/Monitors/Common.hs
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/Common.hs
parent12424d6eda711947eff7fad4f1429627b780fe01 (diff)
downloadxmobar-f655873269ccd8992c5f5610327a24f78c449403.tar.gz
xmobar-f655873269ccd8992c5f5610327a24f78c449403.tar.bz2
Made parseTemplate recursively replace template variables.
Diffstat (limited to 'src/Plugins/Monitors/Common.hs')
-rw-r--r--src/Plugins/Monitors/Common.hs26
1 files changed, 12 insertions, 14 deletions
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