diff options
Diffstat (limited to 'Plugins/Monitors')
-rw-r--r-- | Plugins/Monitors/MultiCpu.hs | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/Plugins/Monitors/MultiCpu.hs b/Plugins/Monitors/MultiCpu.hs index 069199b..f32c966 100644 --- a/Plugins/Monitors/MultiCpu.hs +++ b/Plugins/Monitors/MultiCpu.hs @@ -16,13 +16,16 @@ 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,intersperse,transpose) multiCpuConfig :: IO MConfig multiCpuConfig = - mkMConfig "Cpu: <total>%" - [ k ++ n | n <- "" : map show [0 :: Int ..] - , k <- ["bar","total","user","nice","system","idle"]] + mkMConfig "Cpu: <total>%" $ + map ("auto" ++) monitors + ++ map ((++ "%") . ("auto" ++)) monitors + ++ [ k ++ n | n <- "" : map show [0 :: Int ..] + , k <- monitors] + where monitors = ["bar","total","user","nice","system","idle"] cpuData :: IO [[Float]] @@ -59,8 +62,28 @@ formatCpu xs ps <- showPercentsWithColors (t:xs) return (b:ps) +splitEvery :: Int -> [a] -> [[a]] +splitEvery _ [] = [] +splitEvery n l = (take n l) : splitEvery n (drop n l) + +groupData :: [String] -> [[String]] +groupData = transpose . tail . splitEvery 6 + +formatAutoCpus :: [String] -> Monitor [String] +formatAutoCpus [] = return $ replicate 6 "" +formatAutoCpus xs = return $ map concat . map (intersperse " ") $ groupData xs + +formatAutoCpusPercents :: [String] -> Monitor [String] +formatAutoCpusPercents [] = return $ replicate 6 "" +formatAutoCpusPercents xs = return $ map concat . map (intersperse " ") $ withPercents groups + where groups = groupData xs + withPercents [] = [] + withPercents (y:ys) = y : (map (map (++ "%")) (tail ys)) + runMultiCpu :: [String] -> Monitor String runMultiCpu _ = do c <- io parseCpuData l <- formatMultiCpus c - parseTemplate l + a <- formatAutoCpus l + p <- formatAutoCpusPercents l + parseTemplate (a ++ p ++ l) |