From 4b30381ad102b30e311c17ab4c6c43e328f2cf66 Mon Sep 17 00:00:00 2001 From: jao Date: Sat, 5 Oct 2019 22:43:57 +0100 Subject: New flag `contiguous-icons` for `MultiCpu` (issue #388) --- changelog.md | 11 ++++++++++- readme.md | 2 ++ src/Xmobar/Plugins/Monitors/MultiCpu.hs | 18 ++++++++++++------ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/changelog.md b/changelog.md index 4870637..50915f6 100644 --- a/changelog.md +++ b/changelog.md @@ -1,10 +1,19 @@ +## Version 0.31 + +_New features_ + + - New option `--contiguous-icons` for `MultiCpu` to draw icons + without padding (see [issue #388]). + +[issue #388]: https://github.com/jaor/xmobar/issues/388 + ## Version 0.30 (August, 2019) _New features_ - New monitor `MultiCoreTemp`, thanks to Felix Springer. - `DiskIO`: Additional template variables for absolute number of - bytes rather than speeds (see [issue #390]. + bytes rather than speeds (see [issue #390]). - `WeatherX`: An extension to the `Weather` monitor allowing the spefication of custom strings or icons for sky conditions. - The battery monitors accept the new arguments `-a` and `-A` to diff --git a/readme.md b/readme.md index 6388ba5..bf5893e 100644 --- a/readme.md +++ b/readme.md @@ -866,6 +866,8 @@ specification, such as `("clear", "")`. corresponds to nth cpu. - `--fallback-icon-pattern`: dynamic string used by `autoipat` and `ipat{i}` when no `--load-icon-patterns` has been provided for `cpu{i}` + - `--contiguous-icons`: flag (no value needs to be provided) that + causes the load icons to be drawn without padding. - Thresholds refer to percentage of CPU load - Variables that can be used with the `-t`/`--template` argument: `autototal`, `autobar`, `autovbar`, `autoipat`, `autouser`, `autonice`, diff --git a/src/Xmobar/Plugins/Monitors/MultiCpu.hs b/src/Xmobar/Plugins/Monitors/MultiCpu.hs index 3db3b5f..70ae132 100644 --- a/src/Xmobar/Plugins/Monitors/MultiCpu.hs +++ b/src/Xmobar/Plugins/Monitors/MultiCpu.hs @@ -25,6 +25,7 @@ data MultiCpuOpts = MultiCpuOpts { loadIconPatterns :: [IconPattern] , loadIconPattern :: Maybe IconPattern , fallbackIconPattern :: Maybe IconPattern + , contiguous :: Bool } defaultOpts :: MultiCpuOpts @@ -32,6 +33,7 @@ defaultOpts = MultiCpuOpts { loadIconPatterns = [] , loadIconPattern = Nothing , fallbackIconPattern = Nothing + , contiguous = False } options :: [OptDescr (MultiCpuOpts -> MultiCpuOpts)] @@ -42,6 +44,7 @@ options = o { loadIconPatterns = parseIconPattern x : loadIconPatterns o }) "") "" , Option "" ["fallback-icon-pattern"] (ReqArg (\x o -> o { fallbackIconPattern = Just $ parseIconPattern x }) "") "" + , Option "" ["contiguous-icons"] (NoArg (\o -> o {contiguous = True})) "" ] parseOpts :: [String] -> IO MultiCpuOpts @@ -87,7 +90,8 @@ percent b a = if tot > 0 then map (/ tot) $ take 4 dif else [0, 0, 0, 0] formatMultiCpus :: MultiCpuOpts -> [[Float]] -> Monitor [String] formatMultiCpus _ [] = return [] -formatMultiCpus opts xs = concat <$> mapM (\(i, x) -> formatCpu opts i x) (zip [0..] xs) +formatMultiCpus opts xs = + concat <$> mapM (\(i, x) -> formatCpu opts i x) (zip [0..] xs) formatCpu :: MultiCpuOpts -> Int -> [Float] -> Monitor [String] formatCpu opts i xs @@ -100,7 +104,8 @@ formatCpu opts i xs return (b:h:d:ps) where tryString | i == 0 = loadIconPattern opts - | i <= length (loadIconPatterns opts) = Just $ loadIconPatterns opts !! (i - 1) + | i <= length (loadIconPatterns opts) = + Just $ loadIconPatterns opts !! (i - 1) | otherwise = fallbackIconPattern opts splitEvery :: Int -> [a] -> [[a]] @@ -109,16 +114,17 @@ splitEvery n = unfoldr (\x -> if null x then Nothing else Just $ splitAt n x) groupData :: [String] -> [[String]] groupData = transpose . tail . splitEvery vNum -formatAutoCpus :: [String] -> Monitor [String] -formatAutoCpus [] = return $ replicate vNum "" -formatAutoCpus xs = return $ map unwords (groupData xs) +formatAutoCpus :: MultiCpuOpts -> [String] -> Monitor [String] +formatAutoCpus _ [] = return $ replicate vNum "" +formatAutoCpus opts xs = + return $ map (if (contiguous opts) then concat else unwords) (groupData xs) runMultiCpu :: CpuDataRef -> [String] -> Monitor String runMultiCpu cref argv = do c <- io $ parseCpuData cref opts <- io $ parseOpts argv l <- formatMultiCpus opts c - a <- formatAutoCpus l + a <- formatAutoCpus opts l parseTemplate $ a ++ l startMultiCpu :: [String] -> Int -> (String -> IO ()) -> IO () -- cgit v1.2.3