diff options
author | Krzysztof Kosciuszkiewicz <k.kosciuszkiewicz@gmail.com> | 2007-07-19 12:15:05 +0200 |
---|---|---|
committer | Krzysztof Kosciuszkiewicz <k.kosciuszkiewicz@gmail.com> | 2007-07-19 12:15:05 +0200 |
commit | 16f199b381d9be2996318a8dd1c474006a008957 (patch) | |
tree | 15cee43582014ee06ec3a2b01fd8776b535c0a0a | |
parent | 238c4ab7e2f076f879d931588f140bab78654747 (diff) | |
download | xmobar-16f199b381d9be2996318a8dd1c474006a008957.tar.gz xmobar-16f199b381d9be2996318a8dd1c474006a008957.tar.bz2 |
Moved battery line parsing into the Maybe monad.
darcs-hash:20070719101505-ba08c-99b2005230d97d19f73c7dfdb7ba328bc4046063.gz
-rw-r--r-- | Plugins/Monitors/Batt.hs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/Plugins/Monitors/Batt.hs b/Plugins/Monitors/Batt.hs index 4341452..44ee378 100644 --- a/Plugins/Monitors/Batt.hs +++ b/Plugins/Monitors/Batt.hs @@ -51,14 +51,13 @@ mkMap :: B.ByteString -> B.ByteString -> BattMap mkMap a b = M.fromList . mapMaybe parseLine $ concatMap B.lines [a, b] parseLine :: B.ByteString -> Maybe (String, Integer) -parseLine s = +parseLine s = do let (k, r) = B.break (==':') s - (v, _) = B.span (isDigit) (B.tail r) + (_, r') = B.span (isSpace) (B.tail r) + (v, _) = B.span (isDigit) r' (ks, vs) = (B.unpack k, B.unpack v) - in case (ks, vs) of - ([], _) -> Nothing - (_, []) -> Nothing - _ -> Just (ks, read vs) + guard $ all (> 0) (map B.length [r, k, v]) + return (ks, read vs) parseBATT :: IO Float parseBATT = |