diff options
author | Andrea Rossato <andrea.rossato@ing.unitn.it> | 2007-07-24 13:40:47 +0200 |
---|---|---|
committer | Andrea Rossato <andrea.rossato@ing.unitn.it> | 2007-07-24 13:40:47 +0200 |
commit | bcb7793d5444be36bcb999409771d4493ec157a9 (patch) | |
tree | 65131f918d4718e0f4c0d9a3ca6c54ab61f5c295 /Plugins | |
parent | 4dc0696751355817a5cb35d41f4c9c2daa25f5bc (diff) | |
download | xmobar-bcb7793d5444be36bcb999409771d4493ec157a9.tar.gz xmobar-bcb7793d5444be36bcb999409771d4493ec157a9.tar.bz2 |
Batt: better error handling
darcs-hash:20070724114047-d6583-3006b98cf7421b40d1723047ea3c7fc89136ce7b.gz
Diffstat (limited to 'Plugins')
-rw-r--r-- | Plugins/Monitors/Batt.hs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Plugins/Monitors/Batt.hs b/Plugins/Monitors/Batt.hs index 0c2219a..c4e463a 100644 --- a/Plugins/Monitors/Batt.hs +++ b/Plugins/Monitors/Batt.hs @@ -17,6 +17,9 @@ module Plugins.Monitors.Batt where import qualified Data.ByteString.Lazy.Char8 as B import Plugins.Monitors.Common +data Batt = Batt Float + | NA + battConfig :: IO MConfig battConfig = mkMConfig "Batt: <left>" -- template @@ -34,7 +37,7 @@ readFileBatt (i,s) = b <- catch (B.readFile s) (const $ return B.empty) return (a,b) -parseBATT :: IO Float +parseBATT :: IO Batt parseBATT = do (a1,b1) <- readFileBatt fileB1 (a2,b2) <- readFileBatt fileB2 @@ -43,8 +46,9 @@ parseBATT = x -> read x (f1, p1) = (sp (3,2) a1, sp (2,4) b1) (f2, p2) = (sp (3,2) a2, sp (2,4) b2) - return $ (p1 + p2) / (f1 + f2) --present / full - + left = (p1 + p2) / (f1 + f2) --present / full + return $ if isNaN left then NA else Batt left + formatBatt :: Float -> Monitor [String] formatBatt x = do let f s = floatToPercent (s / 100) @@ -54,5 +58,7 @@ formatBatt x = runBatt :: [String] -> Monitor String runBatt _ = do c <- io $ parseBATT - l <- formatBatt c - parseTemplate l + case c of + Batt x -> do l <- formatBatt x + parseTemplate l + NA -> return "N/A" |