From c7667a521264a7f2d397b651f7991664349d6897 Mon Sep 17 00:00:00 2001 From: Eric Mrak Date: Thu, 13 Mar 2014 19:41:42 -0700 Subject: MultiCpu now has vbar --- readme.md | 6 +++--- src/Plugins/Monitors/MultiCpu.hs | 17 ++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/readme.md b/readme.md index 84c3946..5776aff 100644 --- a/readme.md +++ b/readme.md @@ -732,9 +732,9 @@ something like: - Aliases to `multicpu` - Args: default monitor arguments - Variables that can be used with the `-t`/`--template` argument: - `autototal`, `autobar`, `autouser`, `autonice`, - `autosystem`, `autoidle`, `total`, `bar`, `user`, `nice`, - `system`, `idle`, `total0`, `bar0`, `user0`, `nice0`, + `autototal`, `autobar`, `autovbar`, `autouser`, `autonice`, + `autosystem`, `autoidle`, `total`, `bar`, `vbar`, `user`, `nice`, + `system`, `idle`, `total0`, `bar0`, `vbar0`, `user0`, `nice0`, `system0`, `idle0`, ... The auto* variables automatically detect the number of CPUs on the system and display one entry for each. 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: %" $ - ["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 -- cgit v1.2.3