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/MultiCpu.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/MultiCpu.hs')
-rw-r--r-- | Plugins/Monitors/MultiCpu.hs | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/Plugins/Monitors/MultiCpu.hs b/Plugins/Monitors/MultiCpu.hs index 1c89a76..360671b 100644 --- a/Plugins/Monitors/MultiCpu.hs +++ b/Plugins/Monitors/MultiCpu.hs @@ -16,7 +16,7 @@ module Plugins.Monitors.MultiCpu(multiCpuConfig, runMultiCpu) where import Plugins.Monitors.Common import qualified Data.ByteString.Lazy.Char8 as B -import Data.List(isPrefixOf) +import Data.List (isPrefixOf) multiCpuConfig :: IO MConfig multiCpuConfig = mkMConfig @@ -47,20 +47,14 @@ percent b a = if tot > 0 then map (/ tot) $ take 4 dif else [0, 0, 0, 0] where dif = zipWith (-) b a tot = foldr (+) 0 dif -emptyPercs :: [String] -emptyPercs = repeat " 0%" - formatMultiCpus :: [[Float]] -> Monitor [String] -formatMultiCpus [] = return $ take 15 emptyPercs +formatMultiCpus [] = showPercentsWithColors $ replicate 15 0.0 formatMultiCpus xs = fmap concat $ mapM formatCpu xs formatCpu :: [Float] -> Monitor [String] -formatCpu x - | length x < 4 = return $ take 5 emptyPercs - | otherwise = mapM (showWithColors f . (* 100)) (t:x) - where f = pad . floatToPercent . (/ 100) - t = foldr (+) 0 $ take 3 x - pad s = take (4 - length s) " " ++ s +formatCpu xs + | length xs < 4 = showPercentsWithColors $ replicate 5 0.0 + | otherwise = showPercentsWithColors $ (foldr (+) 0 $ take 3 xs) : xs runMultiCpu :: [String] -> Monitor String runMultiCpu _ = |