From b8279eccf85b3709ccce0533846a10fb613a10f4 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Sun, 26 May 2013 05:45:30 +0200 Subject: Allowing template variables in Battery's -O and -o args Should address github issue #109. Thanks to Todd Lunter for the suggestion. --- news.md | 9 +++++++++ readme.md | 10 ++++++++++ src/Plugins/Monitors/Batt.hs | 14 ++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/news.md b/news.md index bc4abce..0379160 100644 --- a/news.md +++ b/news.md @@ -1,5 +1,14 @@ % xmobar - Release notes +## Version 0.18 + +_New features_ + + - The battery monitor accepts template variables in its `-O` and + `-o` (on/off AC-status) arguments (see [github #109]). + +[github #109]: https://github.com/jaor/xmobar/issues/109 + ## Version 0.17 (May 5, 2013) _New features_ diff --git a/readme.md b/readme.md index 013f9d6..6055f56 100644 --- a/readme.md +++ b/readme.md @@ -764,6 +764,16 @@ something like: neither the generic nor the specific options have any effect on ``. + It is also possible to specify template variables in the `-O` and + `-o` switches, as in the following example: + + Run BatteryP ["BAT0"] + ["-t", "" + , "-L", "10", "-H", "80" + , "-l", "red", "-h", "green" + , "--", "-O", "Charging", "-o", "Battery: %" + ] 10 + ### `TopProc Args RefreshRate` - Aliases to `top` diff --git a/src/Plugins/Monitors/Batt.hs b/src/Plugins/Monitors/Batt.hs index a593782..27007f9 100644 --- a/src/Plugins/Monitors/Batt.hs +++ b/src/Plugins/Monitors/Batt.hs @@ -1,7 +1,7 @@ ----------------------------------------------------------------------------- -- | -- Module : Plugins.Monitors.Batt --- Copyright : (c) 2010, 2011, 2012 Jose A Ortega +-- Copyright : (c) 2010, 2011, 2012, 2013 Jose A Ortega -- (c) 2010 Andrea Rossato, Petr Rockai -- License : BSD-style (see LICENSE) -- @@ -149,6 +149,14 @@ 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 ++ "") template + r <- parseTemplate vs + setConfigValue t template + return r + runBatt' :: [String] -> [String] -> Monitor String runBatt' bfs args = do opts <- io $ parseOpts args @@ -158,7 +166,9 @@ runBatt' bfs args = do case c of Result x w t s -> do l <- fmtPercent x - parseTemplate (l ++ s:[fmtTime $ floor t, fmtWatts w opts suffix d]) + let ts = [fmtTime $ floor t, fmtWatts w opts suffix d] + s' <- statusTemplate s (l ++ "":ts) + parseTemplate (l ++ s':ts) NA -> return "N/A" where fmtPercent :: Float -> Monitor [String] fmtPercent x = do -- cgit v1.2.3