From 9425e2f2b424f23346bd6c7af7494be66145c5c0 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 8 Dec 2010 20:03:55 -0500 Subject: Add auto* and auto*% templates These template automatically detect the number of CPUs and list all of them in order, split by a space (with or without a '%' after each number). --- Plugins/Monitors/MultiCpu.hs | 33 ++++++++++++++++++++++++++++----- 1 file 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: %" - [ k ++ n | n <- "" : map show [0 :: Int ..] - , k <- ["bar","total","user","nice","system","idle"]] + mkMConfig "Cpu: %" $ + 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) -- cgit v1.2.3 From 73ac9faa18b948242ada9b90a365fdf0d238d2d2 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 8 Dec 2010 20:11:17 -0500 Subject: Update documentation for MultiCpu --- README | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README b/README index 10c6e9c..628055d 100644 --- a/README +++ b/README @@ -370,8 +370,13 @@ Monitors have default aliases. - aliases to `multicpu` - Args: default monitor arguments (see below) - Variables that can be used with the `-t`/`--template` argument: + `autototal`, `autobar`, `autouser`, `autonice`, + `autosystem`, `autoidle`, `autototal%`, `autobar%`, + `autouser%`, `autonice%`, `autosystem%`, `autoidle%`, `total`, `bar`, `user`, `nice`, `system`, `idle`, `total0`, `bar0`, `user0`, `nice0`, `system0`, `idle0`, ... +- The auto* variables automatically detect the number of CPUs on the system + and displays one entry for each, with or without a trailing '%'. - Default template: `Cpu: %` `Battery Args RefreshRate` -- cgit v1.2.3 From 0054cc5beec8fe7673443f3a4a6a7a878a7f400d Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 8 Dec 2010 20:29:59 -0500 Subject: Remove auto*% options The -P option now covers this case. --- Plugins/Monitors/MultiCpu.hs | 11 +---------- README | 9 ++++----- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/Plugins/Monitors/MultiCpu.hs b/Plugins/Monitors/MultiCpu.hs index f32c966..17620d5 100644 --- a/Plugins/Monitors/MultiCpu.hs +++ b/Plugins/Monitors/MultiCpu.hs @@ -22,7 +22,6 @@ multiCpuConfig :: IO MConfig multiCpuConfig = mkMConfig "Cpu: %" $ map ("auto" ++) monitors - ++ map ((++ "%") . ("auto" ++)) monitors ++ [ k ++ n | n <- "" : map show [0 :: Int ..] , k <- monitors] where monitors = ["bar","total","user","nice","system","idle"] @@ -73,17 +72,9 @@ 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 a <- formatAutoCpus l - p <- formatAutoCpusPercents l - parseTemplate (a ++ p ++ l) + parseTemplate (a ++ l) diff --git a/README b/README index 628055d..1ed9567 100644 --- a/README +++ b/README @@ -371,12 +371,11 @@ Monitors have default aliases. - Args: default monitor arguments (see below) - Variables that can be used with the `-t`/`--template` argument: `autototal`, `autobar`, `autouser`, `autonice`, - `autosystem`, `autoidle`, `autototal%`, `autobar%`, - `autouser%`, `autonice%`, `autosystem%`, `autoidle%`, - `total`, `bar`, `user`, `nice`, `system`, `idle`, - `total0`, `bar0`, `user0`, `nice0`, `system0`, `idle0`, ... + `autosystem`, `autoidle`, `total`, `bar`, `user`, `nice`, + `system`, `idle`, `total0`, `bar0`, `user0`, `nice0`, + `system0`, `idle0`, ... - The auto* variables automatically detect the number of CPUs on the system - and displays one entry for each, with or without a trailing '%'. + and displays one entry for each. - Default template: `Cpu: %` `Battery Args RefreshRate` -- cgit v1.2.3