diff options
author | jao <jao@gnu.org> | 2019-10-15 03:01:30 +0100 |
---|---|---|
committer | jao <jao@gnu.org> | 2019-10-15 03:01:30 +0100 |
commit | d0c5040aca2add1398e37ef96004924fc8e6ee41 (patch) | |
tree | 219b65b4d2bde12f73265035d2d8cf42c02d353a | |
parent | 38d8eb053374c824e25551a4610a7be2f4f80a31 (diff) | |
download | xmobar-d0c5040aca2add1398e37ef96004924fc8e6ee41.tar.gz xmobar-d0c5040aca2add1398e37ef96004924fc8e6ee41.tar.bz2 |
Battery: -P to show %
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | readme.md | 1 | ||||
-rw-r--r-- | src/Xmobar/Plugins/Monitors/Batt.hs | 13 | ||||
-rw-r--r-- | src/Xmobar/Plugins/Monitors/Common/Output.hs | 3 |
4 files changed, 13 insertions, 5 deletions
diff --git a/changelog.md b/changelog.md index fb027c5..c0957ad 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,7 @@ _New features_ - New plugin `MailX` extending `Mail` with colors and prefix/suffix. - New options `--lows`, `--mediums`, and `--highs` for `Battery` to display an additional string depending on battery level. + - New option `-P` in `Battery` to add a `%` symbol to `<left>`. - New options `-L` and `-H` for `Volume` to set low and high volume levels, as well as `-l`, `-m`, and `-h` to display an additional string depending on current volume level. @@ -911,6 +911,7 @@ specification, such as `("clear", "<icon=weather-clear.xbm/>")`. percentage left in the battery is less or equal than the threshold given by the `-A` option. If not present, no action is undertaken. + - `-P`: to include a percentage symbol in `left`. - `--on-icon-pattern`: dynamic string for current battery charge when AC is "on" in `leftipat`. - `--off-icon-pattern`: dynamic string for current battery charge diff --git a/src/Xmobar/Plugins/Monitors/Batt.hs b/src/Xmobar/Plugins/Monitors/Batt.hs index 16137b1..3f407b6 100644 --- a/src/Xmobar/Plugins/Monitors/Batt.hs +++ b/src/Xmobar/Plugins/Monitors/Batt.hs @@ -48,6 +48,7 @@ data BattOpts = BattOpts , lowString :: String , mediumString :: String , highString :: String + , incPerc :: Bool } defaultOpts :: BattOpts @@ -71,6 +72,7 @@ defaultOpts = BattOpts , lowString = "" , mediumString = "" , highString = "" + , incPerc = False } options :: [OptDescr (BattOpts -> BattOpts)] @@ -87,6 +89,7 @@ options = , Option "f" ["online"] (ReqArg (\x o -> o { onlineFile = x }) "") "" , Option "s" ["scale"] (ReqArg (\x o -> o {scale = read x}) "") "" , Option "a" ["action"] (ReqArg (\x o -> o { onLowAction = Just x }) "") "" + , Option "P" ["percent"] (NoArg (\o -> o {incPerc = True})) "" , Option "A" ["action-threshold"] (ReqArg (\x o -> o { actionThreshold = read x }) "") "" , Option "" ["on-icon-pattern"] (ReqArg (\x o -> @@ -243,13 +246,14 @@ runBatt = runBatt' ["BAT", "BAT0", "BAT1", "BAT2"] runBatt' :: [String] -> [String] -> Monitor String runBatt' bfs args = do opts <- io $ parseOpts args + let sp = incPerc opts c <- io $ readBatteries opts =<< mapM batteryFiles bfs suffix <- getConfigValue useSuffix d <- getConfigValue decDigits nas <- getConfigValue naString case c of Result x w t s -> - do l <- fmtPercent x + do l <- fmtPercent x sp ws <- fmtWatts w opts suffix d si <- getIconPattern opts s x st <- showWithColors' @@ -257,13 +261,14 @@ runBatt' bfs args = do (100 * x) parseTemplate (l ++ [st, fmtTime $ floor t, ws, si]) NA -> getConfigValue naString - where fmtPercent :: Float -> Monitor [String] - fmtPercent x = do + where fmtPercent :: Float -> Bool -> Monitor [String] + fmtPercent x sp = do let x' = minimum [1, x] + pc <- if sp then colorizeString (100 * x') "%" else return "" p <- showPercentWithColors x' b <- showPercentBar (100 * x') x' vb <- showVerticalBar (100 * x') x' - return [b, vb, p] + return [b, vb, p ++ pc] fmtWatts x o s d = do ws <- showWithPadding $ showDigits d x ++ (if s then "W" else "") return $ color x o ws diff --git a/src/Xmobar/Plugins/Monitors/Common/Output.hs b/src/Xmobar/Plugins/Monitors/Common/Output.hs index 53c5b0f..7a14a74 100644 --- a/src/Xmobar/Plugins/Monitors/Common/Output.hs +++ b/src/Xmobar/Plugins/Monitors/Common/Output.hs @@ -1,7 +1,7 @@ ------------------------------------------------------------------------------ -- | -- Module: Xmobar.Plugins.Monitors.Strings --- Copyright: (c) 2018 Jose Antonio Ortega Ruiz +-- Copyright: (c) 2018, 2019 Jose Antonio Ortega Ruiz -- License: BSD3-style (see LICENSE) -- -- Maintainer: jao@gnu.org @@ -18,6 +18,7 @@ module Xmobar.Plugins.Monitors.Common.Output ( IconPattern , parseIconPattern , padString + , colorizeString , showWithPadding , showWithColors , showWithColors' |