From 66b7372d725bf5caade46c998e1597a8d1842ad2 Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Sun, 14 Jun 2020 15:23:23 +0530 Subject: Further optimization --- src/Xmobar/Plugins/Monitors/Cpu.hs | 13 ++++++++++--- 1 file 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 -- cgit v1.2.3