diff options
author | Jose A Ortega Ruiz <jao@gnu.org> | 2010-02-04 02:54:55 +0100 |
---|---|---|
committer | Jose A Ortega Ruiz <jao@gnu.org> | 2010-02-04 02:54:55 +0100 |
commit | 6c4970ea293796a832ecd1b292ec99a9695bf276 (patch) | |
tree | af6ae522a14cfb75ef2434953ad87be17ba5fee9 /Plugins/Monitors/Common.hs | |
parent | cf25ae10fa019378c5aa5c7381275bd475c11ed4 (diff) | |
download | xmobar-6c4970ea293796a832ecd1b292ec99a9695bf276.tar.gz xmobar-6c4970ea293796a832ecd1b292ec99a9695bf276.tar.bz2 |
New DiskU and DiskIO monitors
Ignore-this: b72a9ad54c9ae478f2c3fbdcda4d26c8
New monitors for disk usage and throughput, replacing Disk.
darcs-hash:20100204015455-748be-41e03ee9dff0e3e9e3725aae8a3e07c6facb70dc.gz
Diffstat (limited to 'Plugins/Monitors/Common.hs')
-rw-r--r-- | Plugins/Monitors/Common.hs | 13 |
1 files changed, 13 insertions, 0 deletions
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 |