diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Plugins/Monitors/MultiCpu.hs | 17 | 
1 files changed, 10 insertions, 7 deletions
| diff --git a/src/Plugins/Monitors/MultiCpu.hs b/src/Plugins/Monitors/MultiCpu.hs index a1bb082..48c0bc1 100644 --- a/src/Plugins/Monitors/MultiCpu.hs +++ b/src/Plugins/Monitors/MultiCpu.hs @@ -19,13 +19,15 @@ import qualified Data.ByteString.Lazy.Char8 as B  import Data.List (isPrefixOf, transpose, unfoldr)  import Data.IORef (IORef, newIORef, readIORef, writeIORef) +variables = ["bar", "vbar","total","user","nice","system","idle"] +vNum = length variables +  multiCpuConfig :: IO MConfig  multiCpuConfig =    mkMConfig "Cpu: <total>%" $ -            ["auto" ++ k | k <- monitors] ++ +            ["auto" ++ k | k <- variables] ++              [ k ++ n     | n <- "" : map show [0 :: Int ..] -                         , k <- monitors] -    where monitors = ["bar","total","user","nice","system","idle"] +                         , k <- variables]  type CpuDataRef = IORef [[Float]] @@ -56,20 +58,21 @@ formatMultiCpus xs = fmap concat $ mapM formatCpu xs  formatCpu :: [Float] -> Monitor [String]  formatCpu xs -  | length xs < 4 = showPercentsWithColors $ replicate 6 0.0 +  | length xs < 4 = showPercentsWithColors $ replicate vNum 0.0    | otherwise = let t = foldr (+) 0 $ take 3 xs                  in do b <- showPercentBar (100 * t) t +                      h <- showVerticalBar (100 * t)                        ps <- showPercentsWithColors (t:xs) -                      return (b:ps) +                      return (b:h:ps)  splitEvery :: (Eq a) => Int -> [a] -> [[a]]  splitEvery n = unfoldr (\x -> if null x then Nothing else Just $ splitAt n x)  groupData :: [String] -> [[String]] -groupData = transpose . tail . splitEvery 6 +groupData = transpose . tail . splitEvery vNum  formatAutoCpus :: [String] -> Monitor [String] -formatAutoCpus [] = return $ replicate 6 "" +formatAutoCpus [] = return $ replicate vNum ""  formatAutoCpus xs = return $ map unwords (groupData xs)  runMultiCpu :: CpuDataRef -> [String] -> Monitor String | 
