From 71d9835f761020fac3f22dcb2229d684eeddb083 Mon Sep 17 00:00:00 2001 From: Andrea Rossato Date: Thu, 28 Jun 2007 00:13:46 +0200 Subject: Cpu.hs more code clean up darcs-hash:20070627221346-d6583-38b075b2fca4963bc8e7abe2449b411bc2abad10.gz --- Monitors/Cpu.hs | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/Monitors/Cpu.hs b/Monitors/Cpu.hs index f24b9ee..e712c98 100644 --- a/Monitors/Cpu.hs +++ b/Monitors/Cpu.hs @@ -26,7 +26,7 @@ data Config = , cpuNormalColor :: String , cpuCritical :: Integer , cpuCriticalColor :: String - } + } deriving (Show) defaultConfig :: Config defaultConfig = @@ -46,6 +46,11 @@ floatToPercent :: Float -> String floatToPercent n = showFFloat (Just 2) (n*100) "%" +setColor :: Show a => String -> a -> (a -> String) -> String +setColor str conf ty = + "" ++ + str ++ "" + fileCPU :: IO B.ByteString fileCPU = B.readFile "/proc/stat" @@ -74,29 +79,17 @@ parseCPU = return percent formatCpu :: [Float] -> String -formatCpu [] = "" formatCpu (us:ni:sy:_) - | x >= c = setColor z cpuCriticalColor - | x >= n = setColor z cpuNormalColor - | otherwise = floatToPercent y + | x >= c = setColor y config cpuCriticalColor + | x >= n = setColor y config cpuNormalColor + | otherwise = y where x = (us * 100) + (sy * 100) + (ni * 100) - y = us + sy + ni - z = floatToPercent y + y = floatToPercent $ us + sy + ni c = fromInteger (cpuCritical config) n = fromInteger (cpuNormal config) formatCpu _ = "" -setColor :: String -> (Config -> String) -> String -setColor str ty = - "" ++ - str ++ "" - -cpu :: IO String -cpu = - do l <- parseCPU - return $ "Cpu: " ++ formatCpu l - main :: IO () main = - do c <- cpu - putStrLn c + do s <- parseCPU + putStrLn $ "Cpu: " ++ formatCpu s -- cgit v1.2.3