From 528dfc748ffbde6c83333daefd2b265dcd62f206 Mon Sep 17 00:00:00 2001 From: "Jose A. Ortega Ruiz" Date: Wed, 20 Jan 2010 22:56:08 +0100 Subject: New Monitor option to specify minimum percentage width Ignore-this: 5e0413c218f257c0db06f83665bd2e5 The new option, -p, is a number specifying how many characters the numerical part of percentages should take. Padding consists of whitespace. E.g. -p 3 makes '3%' appear as ' 3%'. The default value is 0, which means padding is disabled. darcs-hash:20100120215608-40885-2c2ac6718af740971dad491eea92947bae840163.gz --- Plugins/Monitors/Cpu.hs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'Plugins/Monitors/Cpu.hs') diff --git a/Plugins/Monitors/Cpu.hs b/Plugins/Monitors/Cpu.hs index 9ab6d8f..e813713 100644 --- a/Plugins/Monitors/Cpu.hs +++ b/Plugins/Monitors/Cpu.hs @@ -3,7 +3,7 @@ -- Module : Plugins.Monitors.Cpu -- Copyright : (c) Andrea Rossato -- License : BSD-style (see LICENSE) --- +-- -- Maintainer : Andrea Rossato -- Stability : unstable -- Portability : unportable @@ -31,23 +31,19 @@ cpuParser = map read . map B.unpack . tail . B.words . flip (!!) 0 . B.lines parseCPU :: IO [Float] -parseCPU = +parseCPU = do (a,b) <- doActionTwiceWithDelay 750000 cpuData let dif = zipWith (-) b a tot = foldr (+) 0 dif percent = map (/ tot) dif return percent -formatCpu :: [Float] -> Monitor [String] +formatCpu :: [Float] -> Monitor [String] formatCpu [] = return [""] -formatCpu x = - do let f s = floatToPercent (s / 100) - t = foldr (+) 0 $ take 3 x - list = t:x - mapM (showWithColors f) . map (* 100) $ list +formatCpu xs = showPercentsWithColors $ (foldr (+) 0 $ take 3 xs) : xs runCpu :: [String] -> Monitor String runCpu _ = do c <- io $ parseCPU l <- formatCpu c - parseTemplate l + parseTemplate l -- cgit v1.2.3