summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorSibi Prabakaran <sibi@psibi.in>2020-06-14 15:23:23 +0530
committerjao <jao@gnu.org>2020-06-23 16:38:20 +0100
commit66b7372d725bf5caade46c998e1597a8d1842ad2 (patch)
tree31b440b2af307453e970c77f06cb90a1ad6eb7e9 /src
parentb2f829d94981f23fdd1eedf4a778f61882c69af2 (diff)
downloadxmobar-66b7372d725bf5caade46c998e1597a8d1842ad2.tar.gz
xmobar-66b7372d725bf5caade46c998e1597a8d1842ad2.tar.bz2
Further optimization
Diffstat (limited to 'src')
-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