summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Plugins/Monitors
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-09-21 00:52:15 +0100
committerjao <jao@gnu.org>2022-09-21 01:11:33 +0100
commitc824651f98a84eab63cb5ba4a1a5cd98ba761036 (patch)
treed418e4f7925355c27a7859a48da29e36bd7123da /src/Xmobar/Plugins/Monitors
parent4140eba65f28f1117ebb14d8e9252770c951c0bd (diff)
downloadxmobar-c824651f98a84eab63cb5ba4a1a5cd98ba761036.tar.gz
xmobar-c824651f98a84eab63cb5ba4a1a5cd98ba761036.tar.bz2
linting
Diffstat (limited to 'src/Xmobar/Plugins/Monitors')
-rw-r--r--src/Xmobar/Plugins/Monitors/Batt.hs109
1 files changed, 56 insertions, 53 deletions
diff --git a/src/Xmobar/Plugins/Monitors/Batt.hs b/src/Xmobar/Plugins/Monitors/Batt.hs
index 52600d8..bca122b 100644
--- a/src/Xmobar/Plugins/Monitors/Batt.hs
+++ b/src/Xmobar/Plugins/Monitors/Batt.hs
@@ -3,7 +3,7 @@
-----------------------------------------------------------------------------
-- |
-- Module : Plugins.Monitors.Batt
--- Copyright : (c) 2010, 2011, 2012, 2013, 2015, 2016, 2018, 2019 Jose A Ortega
+-- Copyright : (c) 2010-2013, 2015, 2016, 2018, 2019, 2022 Jose A Ortega
-- (c) 2010 Andrea Rossato, Petr Rockai
-- License : BSD-style (see LICENSE)
--
@@ -15,11 +15,9 @@
--
-----------------------------------------------------------------------------
-module Xmobar.Plugins.Monitors.Batt ( battConfig, runBatt, runBatt' ) where
+module Xmobar.Plugins.Monitors.Batt (battConfig, runBatt, runBatt') where
-import Xmobar.Plugins.Monitors.Batt.Common (BattOpts(..)
- , Result(..)
- , Status(..))
+import Xmobar.Plugins.Monitors.Batt.Common (BattOpts(..), Result(..), Status(..))
import Xmobar.Plugins.Monitors.Common
import System.Console.GetOpt
@@ -83,9 +81,9 @@ options =
]
battConfig :: IO MConfig
-battConfig = mkMConfig
- "Batt: <watts>, <left>% / <timeleft>" -- template
- ["leftbar", "leftvbar", "left", "acstatus", "timeleft", "watts", "leftipat"] -- replacements
+battConfig = mkMConfig "Batt: <watts>, <left>% / <timeleft>" vs
+ where vs = ["leftbar", "leftvbar", "left"
+ , "acstatus", "timeleft", "watts", "leftipat"]
data BatteryStatus
= BattHigh
@@ -129,48 +127,53 @@ formatResult res bopt = do
(100 * x)
parseTemplate (l ++ [st, fmtTime $ floor t, ws, si])
NA -> getConfigValue naString
- 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 ++ pc]
- fmtWatts x o s d = do
- ws <- showWithPadding $ showDigits d x ++ (if s then "W" else "")
- return $ color x o ws
- fmtTime :: Integer -> String
- fmtTime x = hours ++ ":" ++ if length minutes == 2
- then minutes else '0' : minutes
- where hours = show (x `div` 3600)
- minutes = show ((x `mod` 3600) `div` 60)
- fmtStatus
- :: BattOpts
- -> Status
- -> String -- ^ What to in case battery status is unknown
- -> BatteryStatus
- -> String
- fmtStatus opts Idle _ _ = idleString opts
- fmtStatus _ Unknown na _ = na
- fmtStatus opts Full _ _ = idleString opts
- fmtStatus opts Charging _ _ = onString opts
- fmtStatus opts Discharging _ battStatus =
- (case battStatus of
- BattHigh -> highString
- BattMedium -> mediumString
- BattLow -> lowString) opts ++ offString opts
- maybeColor Nothing str = str
- maybeColor (Just c) str = "<fc=" ++ c ++ ">" ++ str ++ "</fc>"
- color x o | x >= 0 = maybeColor (posColor o)
- | -x >= highThreshold o = maybeColor (highWColor o)
- | -x >= lowThreshold o = maybeColor (mediumWColor o)
- | otherwise = maybeColor (lowWColor o)
- getIconPattern opts st x = do
- let x' = minimum [1, x]
- case st of
- Unknown -> showIconPattern (offIconPattern opts) x'
- Idle -> showIconPattern (idleIconPattern opts) x'
- Full -> showIconPattern (idleIconPattern opts) x'
- Charging -> showIconPattern (onIconPattern opts) x'
- Discharging -> showIconPattern (offIconPattern opts) x'
+
+fmtWatts :: Float -> BattOpts -> Bool -> Int -> Monitor String
+fmtWatts x o s d = do
+ ws <- showWithPadding $ showDigits d x ++ (if s then "W" else "")
+ return $ color x o ws
+
+color :: Float -> BattOpts -> String -> String
+color x o | x >= 0 = maybeColor (posColor o)
+ | -x >= highThreshold o = maybeColor (highWColor o)
+ | -x >= lowThreshold o = maybeColor (mediumWColor o)
+ | otherwise = maybeColor (lowWColor o)
+
+fmtTime :: Integer -> String
+fmtTime x = hours ++ ":" ++ if length minutes == 2 then minutes else '0' : minutes
+ where hours = show (x `div` 3600)
+ minutes = show ((x `mod` 3600) `div` 60)
+
+fmtPercent :: Float -> Bool -> Monitor [String]
+fmtPercent x sp = do
+ let x' = min 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 ++ pc]
+
+fmtStatus :: BattOpts -> Status -> String -> BatteryStatus -> String
+fmtStatus opts Idle _ _ = idleString opts
+fmtStatus _ Unknown na _ = na
+fmtStatus opts Full _ _ = idleString opts
+fmtStatus opts Charging _ _ = onString opts
+fmtStatus opts Discharging _ battStatus =
+ (case battStatus of
+ BattHigh -> highString
+ BattMedium -> mediumString
+ BattLow -> lowString) opts ++ offString opts
+
+maybeColor :: Maybe String -> String -> String
+maybeColor Nothing str = str
+maybeColor (Just c) str = "<fc=" ++ c ++ ">" ++ str ++ "</fc>"
+
+getIconPattern :: BattOpts -> Status -> Float -> Monitor String
+getIconPattern opts st x = do
+ let x' = min 1 x
+ case st of
+ Unknown -> showIconPattern (offIconPattern opts) x'
+ Idle -> showIconPattern (idleIconPattern opts) x'
+ Full -> showIconPattern (idleIconPattern opts) x'
+ Charging -> showIconPattern (onIconPattern opts) x'
+ Discharging -> showIconPattern (offIconPattern opts) x'