From 12424d6eda711947eff7fad4f1429627b780fe01 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Sun, 26 May 2013 14:20:51 +0200 Subject: New idle status for battery monitor --- news.md | 3 ++- readme.md | 7 ++++++- src/Plugins/Monitors/Batt.hs | 11 ++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/news.md b/news.md index 0379160..740d2dd 100644 --- a/news.md +++ b/news.md @@ -5,7 +5,8 @@ _New features_ - The battery monitor accepts template variables in its `-O` and - `-o` (on/off AC-status) arguments (see [github #109]). + `-o` and the new `-i` (on/off/idle AC-status) arguments (see + [github #109]). [github #109]: https://github.com/jaor/xmobar/issues/109 diff --git a/readme.md b/readme.md index 6055f56..fe22d37 100644 --- a/readme.md +++ b/readme.md @@ -734,6 +734,7 @@ something like: (these options, being specific to the monitor, are to be specified after a `--` in the argument list): - `-O`: string for AC "on" status (default: "On") + - `-i`: string for AC "idle" status (default: "On") - `-o`: string for AC "off" status (default: "Off") - `-L`: low power (`watts`) threshold (default: -12) - `-H`: high power threshold (default: -10) @@ -753,7 +754,7 @@ something like: Run BatteryP ["BAT0"] ["-t", " (%)", "-L", "10", "-H", "80", "-p", "3", - "--", "-O", "On - ", "-o", "", + "--", "-O", "On - ", "-i", "", "-L", "-15", "-H", "-5", "-l", "red", "-m", "blue", "-h", "green"] 600 @@ -774,6 +775,10 @@ something like: , "--", "-O", "Charging", "-o", "Battery: %" ] 10 +- The "idle" AC state is selected whenever the AC power entering the + battery is zero. + + ### `TopProc Args RefreshRate` - Aliases to `top` diff --git a/src/Plugins/Monitors/Batt.hs b/src/Plugins/Monitors/Batt.hs index dc18c54..eddec06 100644 --- a/src/Plugins/Monitors/Batt.hs +++ b/src/Plugins/Monitors/Batt.hs @@ -25,6 +25,7 @@ import System.Console.GetOpt data BattOpts = BattOpts { onString :: String , offString :: String + , idleString :: String , posColor :: Maybe String , lowWColor :: Maybe String , mediumWColor :: Maybe String @@ -39,6 +40,7 @@ defaultOpts :: BattOpts defaultOpts = BattOpts { onString = "On" , offString = "Off" + , idleString = "On" , posColor = Nothing , lowWColor = Nothing , mediumWColor = Nothing @@ -53,6 +55,7 @@ options :: [OptDescr (BattOpts -> BattOpts)] options = [ Option "O" ["on"] (ReqArg (\x o -> o { onString = x }) "") "" , Option "o" ["off"] (ReqArg (\x o -> o { offString = x }) "") "" + , Option "i" ["idle"] (ReqArg (\x o -> o { idleString = x }) "") "" , Option "p" ["positive"] (ReqArg (\x o -> o { posColor = Just x }) "") "" , Option "l" ["low"] (ReqArg (\x o -> o { lowWColor = Just x }) "") "" , Option "m" ["medium"] (ReqArg (\x o -> o { mediumWColor = Just x }) "") "" @@ -140,10 +143,12 @@ readBatteries opts bfs = ft = sum (map full bats) left = if ft > 0 then sum (map now bats) / ft else 0 watts = sign * sum (map power bats) - time = if watts == 0 then 0 else sum $ map time' bats - mwatts = if watts == 0 then 1 else sign * watts + idle = watts == 0 + time = if idle then 0 else sum $ map time' bats + mwatts = if idle then 1 else sign * watts time' b = (if ac then full b - now b else now b) / mwatts - acstr = if ac then onString opts else offString opts + acstr = if idle then idleString opts else + if ac then onString opts else offString opts return $ if isNaN left then NA else Result left watts time acstr runBatt :: [String] -> Monitor String -- cgit v1.2.3