From b4f0f35ef118064bc7829b6224a896b448a37bc4 Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Sun, 14 Jun 2020 09:46:47 +0530 Subject: Optimize CPU monitor --- src/Xmobar/Plugins/Monitors/Common/Run.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/Xmobar/Plugins/Monitors/Common/Run.hs') diff --git a/src/Xmobar/Plugins/Monitors/Common/Run.hs b/src/Xmobar/Plugins/Monitors/Common/Run.hs index 760eab1..9b0c1b7 100644 --- a/src/Xmobar/Plugins/Monitors/Common/Run.hs +++ b/src/Xmobar/Plugins/Monitors/Common/Run.hs @@ -23,6 +23,8 @@ module Xmobar.Plugins.Monitors.Common.Run ( runM , runMLD , getArgvs , doArgs + , computePureConfig + , commonOptions ) where import Control.Exception (SomeException,handle) @@ -33,6 +35,8 @@ import System.Console.GetOpt import Xmobar.Plugins.Monitors.Common.Types import Xmobar.Run.Exec (doEveryTenthSeconds) +commonOptions = options + options :: [OptDescr Opts] options = [ @@ -66,6 +70,8 @@ getArgvs args = (_, n, [] ) -> n (_, _, errs) -> errs + + doArgs :: [String] -> ([String] -> Monitor String) -> ([String] -> Monitor Bool) @@ -140,3 +146,18 @@ runMLD args conf action looper detect cb = handle (cb . showException) loop showException :: SomeException -> String showException = ("error: "++) . show . flip asTypeOf undefined + +computePureConfig :: [String] -> IO MConfig -> IO PureConfig +computePureConfig args mconfig = do + newConfig <- getMConfig args mconfig + getPureConfig newConfig + +getMConfig :: [String] -> IO MConfig -> IO MConfig +getMConfig args mconfig = do + config <- mconfig + runReaderT (updateOptions args >> ask) config + +updateOptions :: [String] -> Monitor () +updateOptions args= case getOpt Permute options args of + (o, _, []) -> doConfigOptions o + _ -> return () -- cgit v1.2.3