summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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