summaryrefslogtreecommitdiffhomepage
path: root/Plugins/Monitors/MultiCpu.hs
diff options
context:
space:
mode:
authorJose A. Ortega Ruiz <jao@gnu.org>2010-01-19 03:17:53 +0100
committerJose A. Ortega Ruiz <jao@gnu.org>2010-01-19 03:17:53 +0100
commit3d100946bc6f900fb5a4035213f4c8c1fd81f062 (patch)
tree980a5df2503bebddf45888ef07fa98cc0904c536 /Plugins/Monitors/MultiCpu.hs
parent583e88ca4f36938942e982ed1d2f45dd1ea01446 (diff)
downloadxmobar-3d100946bc6f900fb5a4035213f4c8c1fd81f062.tar.gz
xmobar-3d100946bc6f900fb5a4035213f4c8c1fd81f062.tar.bz2
Tiny refactoring
Ignore-this: 404b0000887a9c4dfc5209a9f647d561 darcs-hash:20100119021753-40885-3dd49b3e05ab638a27f51f79e1ee0ad34563f001.gz
Diffstat (limited to 'Plugins/Monitors/MultiCpu.hs')
-rw-r--r--Plugins/Monitors/MultiCpu.hs12
1 files changed, 6 insertions, 6 deletions
diff --git a/Plugins/Monitors/MultiCpu.hs b/Plugins/Monitors/MultiCpu.hs
index 39e48c8..43283a8 100644
--- a/Plugins/Monitors/MultiCpu.hs
+++ b/Plugins/Monitors/MultiCpu.hs
@@ -41,26 +41,26 @@ parseCpuData =
do (as, bs) <- doActionTwiceWithDelay 950000 cpuData
let p0 = zipWith percent bs as
return p0
- -- (as', bs') <- doActionTwiceWithDelay 350000 cpuData
- -- let p1 = zipWith percent bs' as'
- -- return $ zipWith (\x y -> zipWith (\a b -> (a + b) / 2.0) x y) p1 p0
percent :: [Float] -> [Float] -> [Float]
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 (repeat " 0%")
+formatMultiCpus [] = return $ take 15 emptyPercs
formatMultiCpus xs = fmap concat $ mapM formatCpu xs
formatCpu :: [Float] -> Monitor [String]
formatCpu x
- | length x < 4 = return $ take 5 (repeat "")
+ | length x < 4 = return $ take 5 emptyPercs
| otherwise = mapM (showWithColors f) . map (* 100) $ (t:x)
where f s = pad $ floatToPercent (s / 100)
t = foldr (+) 0 $ take 3 x
- pad s = take (4 - length s) (repeat ' ') ++ s
+ pad s = take (4 - length s) " " ++ s
runMultiCpu :: [String] -> Monitor String
runMultiCpu _ =