diff options
author | Jose A. Ortega Ruiz <jao@gnu.org> | 2010-01-20 22:56:08 +0100 |
---|---|---|
committer | Jose A. Ortega Ruiz <jao@gnu.org> | 2010-01-20 22:56:08 +0100 |
commit | 528dfc748ffbde6c83333daefd2b265dcd62f206 (patch) | |
tree | bd5623ec54ee5d67bb699cb20240c2581a5868df /Plugins/Monitors/Cpu.hs | |
parent | 2d6911f940ec82c2054cf96b151ac9ff61372865 (diff) | |
download | xmobar-528dfc748ffbde6c83333daefd2b265dcd62f206.tar.gz xmobar-528dfc748ffbde6c83333daefd2b265dcd62f206.tar.bz2 |
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
Diffstat (limited to 'Plugins/Monitors/Cpu.hs')
-rw-r--r-- | Plugins/Monitors/Cpu.hs | 14 |
1 files changed, 5 insertions, 9 deletions
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 <andrea.rossato@unibz.it> -- 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 |