diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2013-05-26 13:49:48 +0200 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2013-05-26 13:49:48 +0200 |
commit | 430b8d21493092690a3c27c8c285202312f776bd (patch) | |
tree | ef94e39e335ddb814c868ad716ea21e822dd5ebf /src/Plugins | |
parent | b8279eccf85b3709ccce0533846a10fb613a10f4 (diff) | |
download | xmobar-430b8d21493092690a3c27c8c285202312f776bd.tar.gz xmobar-430b8d21493092690a3c27c8c285202312f776bd.tar.bz2 |
Refactoring and slight generalisation of the new Battery feature
Diffstat (limited to 'src/Plugins')
-rw-r--r-- | src/Plugins/Monitors/Batt.hs | 10 | ||||
-rw-r--r-- | src/Plugins/Monitors/Common.hs | 12 |
2 files changed, 12 insertions, 10 deletions
diff --git a/src/Plugins/Monitors/Batt.hs b/src/Plugins/Monitors/Batt.hs index 27007f9..dc18c54 100644 --- a/src/Plugins/Monitors/Batt.hs +++ b/src/Plugins/Monitors/Batt.hs @@ -149,14 +149,6 @@ readBatteries opts bfs = runBatt :: [String] -> Monitor String runBatt = runBatt' ["BAT0","BAT1","BAT2"] -statusTemplate:: String -> [String] -> Monitor String -statusTemplate s vs = do - t <- getConfigValue template - setConfigValue (s ++ "<acstatus>") template - r <- parseTemplate vs - setConfigValue t template - return r - runBatt' :: [String] -> [String] -> Monitor String runBatt' bfs args = do opts <- io $ parseOpts args @@ -167,7 +159,7 @@ runBatt' bfs args = do Result x w t s -> do l <- fmtPercent x let ts = [fmtTime $ floor t, fmtWatts w opts suffix d] - s' <- statusTemplate s (l ++ "":ts) + s' <- parseTemplate' (s ++ "<acstatus>") (l ++ "":ts) parseTemplate (l ++ s':ts) NA -> return "N/A" where fmtPercent :: Float -> Monitor [String] diff --git a/src/Plugins/Monitors/Common.hs b/src/Plugins/Monitors/Common.hs index 0547311..881d679 100644 --- a/src/Plugins/Monitors/Common.hs +++ b/src/Plugins/Monitors/Common.hs @@ -1,7 +1,7 @@ ----------------------------------------------------------------------------- -- | -- Module : Plugins.Monitors.Common --- Copyright : (c) 2010, 2011 Jose Antonio Ortega Ruiz +-- Copyright : (c) 2010, 2011, 2013 Jose Antonio Ortega Ruiz -- (c) 2007-2010 Andrea Rossato -- License : BSD-style (see LICENSE) -- @@ -35,6 +35,7 @@ module Plugins.Monitors.Common ( , getAfterString , skipTillString , parseTemplate + , parseTemplate' -- ** String Manipulation -- $strings , padString @@ -306,6 +307,15 @@ parseTemplate l = let m = Map.fromList . zip e $ l return $ combine m s +-- | 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 + -- | Given a finite "Map" and a parsed templatet produces the -- | resulting output string. combine :: Map.Map String String -> [(String, String, String)] -> String |