summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--news.md3
-rw-r--r--readme.md7
-rw-r--r--src/Plugins/Monitors/Batt.hs11
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", "<acstatus><watts> (<left>%)",
"-L", "10", "-H", "80", "-p", "3",
- "--", "-O", "<fc=green>On</fc> - ", "-o", "",
+ "--", "-O", "<fc=green>On</fc> - ", "-i", "",
"-L", "-15", "-H", "-5",
"-l", "red", "-m", "blue", "-h", "green"]
600
@@ -774,6 +775,10 @@ something like:
, "--", "-O", "Charging", "-o", "Battery: <left>%"
] 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