diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2010-12-07 16:26:09 +0100 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2010-12-07 16:26:09 +0100 |
commit | 4768d84d13a015c76200010e32ae1515264fd1bb (patch) | |
tree | e78d47d15b5cc9e86f3db72b89a072a7dd22bc08 /Plugins | |
parent | 70d92eae0a496b995607c111cc31d7a55099fbc1 (diff) | |
download | xmobar-4768d84d13a015c76200010e32ae1515264fd1bb.tar.gz xmobar-4768d84d13a015c76200010e32ae1515264fd1bb.tar.bz2 |
Fix for swap used ratio (issue 24)
Thanks to Dan Brown for pointing this out. I've applied a modified
version of his patch (inclusion of % will be treated separately).
Diffstat (limited to 'Plugins')
-rw-r--r-- | Plugins/Monitors/Common.hs | 4 | ||||
-rw-r--r-- | Plugins/Monitors/Swap.hs | 19 |
2 files changed, 13 insertions, 10 deletions
diff --git a/Plugins/Monitors/Common.hs b/Plugins/Monitors/Common.hs index 9362fd8..c90c616 100644 --- a/Plugins/Monitors/Common.hs +++ b/Plugins/Monitors/Common.hs @@ -39,6 +39,7 @@ module Plugins.Monitors.Common ( , showWithPadding , showWithColors , showWithColors' + , showPercentWithColors , showPercentsWithColors , showPercentBar , showLogBar @@ -386,6 +387,9 @@ showPercentsWithColors fs = do fstrs <- mapM floatToPercent fs zipWithM (showWithColors . const) fstrs (map (*100) fs) +showPercentWithColors :: Float -> Monitor String +showPercentWithColors f = liftM head $ showPercentsWithColors [f] + showPercentBar :: Float -> Float -> Monitor String showPercentBar v x = do bb <- getConfigValue barBack diff --git a/Plugins/Monitors/Swap.hs b/Plugins/Monitors/Swap.hs index 02acb45..8901a2a 100644 --- a/Plugins/Monitors/Swap.hs +++ b/Plugins/Monitors/Swap.hs @@ -21,7 +21,7 @@ import qualified Data.ByteString.Lazy.Char8 as B swapConfig :: IO MConfig swapConfig = mkMConfig "Swap: <usedratio>" -- template - ["total", "used", "free", "usedratio"] -- available replacements + ["usedratio", "total", "used", "free"] -- available replacements fileMEM :: IO B.ByteString fileMEM = B.readFile "/proc/meminfo" @@ -30,7 +30,7 @@ parseMEM :: IO [Float] parseMEM = do file <- fileMEM let li i l - | l /= [] = (head l) !! i + | l /= [] = head l !! i | otherwise = B.empty fs s l | l == [] = False @@ -39,18 +39,17 @@ parseMEM = st = map B.words . B.lines $ file tot = get_data "SwapTotal:" st free = get_data "SwapFree:" st - return [tot, (tot - free), free, (tot - free) / tot] + return [(tot - free) / tot, tot, tot - free, free] formatSwap :: [Float] -> Monitor [String] -formatSwap x = - do let f1 n = showDigits 2 n - (hd, tl) = splitAt 3 x - firsts <- mapM (showWithColors f1) hd - lasts <- showPercentsWithColors (map (/100) tl) - return $ firsts ++ lasts +formatSwap (r:xs) = + do other <- mapM (showWithColors (showDigits 2)) xs + ratio <- showPercentWithColors r + return $ ratio:other +formatSwap _ = return $ replicate 4 "N/A" runSwap :: [String] -> Monitor String runSwap _ = - do m <- io $ parseMEM + do m <- io parseMEM l <- formatSwap m parseTemplate l |