diff options
author | Andrea Rossato <andrea.rossato@ing.unitn.it> | 2007-06-28 00:13:46 +0200 |
---|---|---|
committer | Andrea Rossato <andrea.rossato@ing.unitn.it> | 2007-06-28 00:13:46 +0200 |
commit | 71d9835f761020fac3f22dcb2229d684eeddb083 (patch) | |
tree | 2d66b78331cb61dab8ec0705965b3312e2335608 /Monitors/Cpu.hs | |
parent | 4ced049c50e0465a233dc062104298eb8a6f7852 (diff) | |
download | xmobar-71d9835f761020fac3f22dcb2229d684eeddb083.tar.gz xmobar-71d9835f761020fac3f22dcb2229d684eeddb083.tar.bz2 |
Cpu.hs more code clean up
darcs-hash:20070627221346-d6583-38b075b2fca4963bc8e7abe2449b411bc2abad10.gz
Diffstat (limited to 'Monitors/Cpu.hs')
-rw-r--r-- | Monitors/Cpu.hs | 31 |
1 files 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 = + "<fc=" ++ ty conf ++ ">" ++ + str ++ "</fc>" + 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 = - "<fc=" ++ ty config ++ ">" ++ - str ++ "</fc>" - -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 |