summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Plugins/Monitors/Cpu.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Xmobar/Plugins/Monitors/Cpu.hs')
-rw-r--r--src/Xmobar/Plugins/Monitors/Cpu.hs13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/Xmobar/Plugins/Monitors/Cpu.hs b/src/Xmobar/Plugins/Monitors/Cpu.hs
index 6c2494f..f234dcf 100644
--- a/src/Xmobar/Plugins/Monitors/Cpu.hs
+++ b/src/Xmobar/Plugins/Monitors/Cpu.hs
@@ -187,11 +187,19 @@ computeFields (x:xs) inputFields =
else (Field {fieldName = x, fieldCompute = Skip}) : (computeFields xs inputFields)
formatCpu :: CpuArguments -> CpuData -> IO [String]
-formatCpu args@CpuArguments{..} cpuData = mapM (formatField cpuParams cpuOpts cpuData) cpuFields
+formatCpu args@CpuArguments{..} cpuData = do
+ strs <- mapM (formatField cpuParams cpuOpts cpuData) cpuFields
+ pure $ filter (not . null) strs
getInputFields :: CpuArguments -> [String]
getInputFields CpuArguments{..} = map (\(_,f,_) -> f) cpuInputTemplate
+optimizeAllTemplate :: CpuArguments -> CpuArguments
+optimizeAllTemplate args@CpuArguments{..} =
+ let inputFields = getInputFields args
+ allTemplates = filter (\(field, _) -> field `elem` inputFields) cpuAllTemplate
+ in args { cpuAllTemplate = allTemplates }
+
data CpuArguments = CpuArguments {
cpuDataRef :: !CpuDataRef,
cpuParams :: !PureConfig,
@@ -217,8 +225,7 @@ getArguments cpuArgs = do
(o, _, []) -> pure $ foldr id defaultOpts o
(_,_,errs) -> error $ "getArguments options: " <> show errs
let cpuFields = computeFields (map fst cpuAllTemplate) (map (\(_,f,_) -> f) cpuInputTemplate)
- pure CpuArguments{..}
-
+ pure $ optimizeAllTemplate CpuArguments{..}
runCpu :: CpuArguments -> IO String
runCpu args@CpuArguments{..} = do