diff options
Diffstat (limited to 'Plugins/Monitors')
| -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 | 
