openbsd-ports/x11/xmobar/files/Batt.hs
dcoppa b31be191b8 Update to xmobar-0.14.
Fix comment into files/Batt.hs.
Adjust WANTLIB.
Use lynx from base instead of curl for the weather plugin.

OK kili@
2012-01-12 21:42:07 +00:00

47 lines
1.5 KiB
Haskell

module Plugins.Monitors.Batt where
import Control.Monad
import Plugins.Monitors.Common
import Plugins.Monitors.Batt.Binding
battConfig :: IO MConfig
battConfig = mkMConfig
"Batt: <left>" -- default template
["left", "leftbar", "minleft", "status"] -- percent left, progress bar, minutes left, status
runBatt :: [String] -> Monitor String
runBatt _ = do
mpowerinfo <- io getApmPowerInfo
case mpowerinfo of
Nothing -> parseTemplate $ take 4 $ repeat "N/A"
Just powerinfo -> do
left <- renderLeft powerinfo
leftbar <- renderLeftBar powerinfo
minleft <- renderMinLeft powerinfo
status <- renderStatus powerinfo
parseTemplate ( left : leftbar : minleft : status : [] )
renderLeft :: ApmPowerInfo -> Monitor String
renderLeft powerinfo = case (apmBatteryState powerinfo) of
BatAbsent -> return []
BatUnknown -> return []
_ -> return $ (show $ apmBatteryPercent powerinfo) ++ "%"
renderLeftBar :: ApmPowerInfo -> Monitor String
renderLeftBar powerinfo = case (apmBatteryState powerinfo) of
BatAbsent -> render 0
BatUnknown -> render 0
_ -> render $ fromIntegral (apmBatteryPercent powerinfo)
where
render x = showPercentBar x (x / 100)
renderMinLeft :: ApmPowerInfo -> Monitor String
renderMinLeft powerinfo = case (apmAcState powerinfo) of
AcOnline -> return []
AcUnknown -> return []
_ -> return $ (show $ apmMinutesLeft powerinfo) ++ "min"
renderStatus :: ApmPowerInfo -> Monitor String
renderStatus powerinfo = return.show $ apmAcState powerinfo