summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/Monitors/Common.hs
diff options
context:
space:
mode:
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