From 6c4970ea293796a832ecd1b292ec99a9695bf276 Mon Sep 17 00:00:00 2001 From: Jose A Ortega Ruiz Date: Thu, 4 Feb 2010 02:54:55 +0100 Subject: New DiskU and DiskIO monitors Ignore-this: b72a9ad54c9ae478f2c3fbdcda4d26c8 New monitors for disk usage and throughput, replacing Disk. darcs-hash:20100204015455-748be-41e03ee9dff0e3e9e3725aae8a3e07c6facb70dc.gz --- Plugins/Monitors/Common.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'Plugins/Monitors/Common.hs') diff --git a/Plugins/Monitors/Common.hs b/Plugins/Monitors/Common.hs index 060a5bc..a102036 100644 --- a/Plugins/Monitors/Common.hs +++ b/Plugins/Monitors/Common.hs @@ -36,7 +36,9 @@ module Plugins.Monitors.Common ( -- ** String Manipulation -- $strings , showWithColors + , showWithColors' , showPercentsWithColors + , showWithUnits , takeDigits , showDigits , floatToPercent @@ -291,6 +293,14 @@ showDigits :: Int -> Float -> String showDigits d n = showFFloat (Just d) n "" +showWithUnits :: Int -> Int -> Float -> String +showWithUnits d n x + | x < 0 = "-" ++ showWithUnits d n (-x) + | n > 3 || x < 10^d = show (round x :: Int) ++ units n + | x <= 1024 = showDigits d (x/1024) ++ units (n+1) + | otherwise = showWithUnits d (n+1) (x/1024) + where units = (!!) ["B", "K", "M", "G", "T"] + padString :: Int -> Int -> String -> Bool -> String -> String padString mnw mxw pad pr s = let len = length s @@ -339,6 +349,9 @@ showWithColors f x = [col normalColor | x > ll ] ++ [col lowColor | True] +showWithColors' :: (Num a, Ord a) => String -> a -> Monitor String +showWithColors' str v = showWithColors (const str) v + showPercentsWithColors :: [Float] -> Monitor [String] showPercentsWithColors fs = do fstrs <- mapM floatToPercent fs -- cgit v1.2.3