summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/Monitors/Cpu.hs
diff options
context:
space:
mode:
authorAlexander Shabalin <shabalyn.a@gmail.com>2014-09-07 22:24:00 +0400
committerAlexander Shabalin <shabalyn.a@gmail.com>2014-09-14 12:03:48 +0400
commite590f14593728b8afc2b77e8be356e5c06428107 (patch)
tree7a316e70cc1c7ae84499516f61579f755b7dce0a /src/Plugins/Monitors/Cpu.hs
parente8e4415b7eba49d2d6ddb18ab13b3151c9a787bd (diff)
downloadxmobar-e590f14593728b8afc2b77e8be356e5c06428107.tar.gz
xmobar-e590f14593728b8afc2b77e8be356e5c06428107.tar.bz2
Implement DynamicString for Monitors supporting vbar.
* Batt * Bright * Cpu * Disk * MPD * Mem * MultiCpu * Net * Volume * Wireless
Diffstat (limited to 'src/Plugins/Monitors/Cpu.hs')
-rw-r--r--src/Plugins/Monitors/Cpu.hs38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/Plugins/Monitors/Cpu.hs b/src/Plugins/Monitors/Cpu.hs
index 10d945f..5abde7e 100644
--- a/src/Plugins/Monitors/Cpu.hs
+++ b/src/Plugins/Monitors/Cpu.hs
@@ -18,11 +18,33 @@ module Plugins.Monitors.Cpu (startCpu) where
import Plugins.Monitors.Common
import qualified Data.ByteString.Lazy.Char8 as B
import Data.IORef (IORef, newIORef, readIORef, writeIORef)
+import System.Console.GetOpt
+
+data CpuOpts = CpuOpts
+ { loadDynamicString :: Maybe DynamicString
+ }
+
+defaultOpts :: CpuOpts
+defaultOpts = CpuOpts
+ { loadDynamicString = Nothing
+ }
+
+options :: [OptDescr (CpuOpts -> CpuOpts)]
+options =
+ [ Option "" ["load-dynamic-string"] (ReqArg (\x o ->
+ o { loadDynamicString = Just $ parseDynamicString x }) "") ""
+ ]
+
+parseOpts :: [String] -> IO CpuOpts
+parseOpts argv =
+ case getOpt Permute options argv of
+ (o, _, []) -> return $ foldr id defaultOpts o
+ (_, _, errs) -> ioError . userError $ concat errs
cpuConfig :: IO MConfig
cpuConfig = mkMConfig
"Cpu: <total>%"
- ["bar","vbar","total","user","nice","system","idle","iowait"]
+ ["bar","vbar","dstr","total","user","nice","system","idle","iowait"]
type CpuDataRef = IORef [Int]
@@ -42,19 +64,21 @@ parseCpu cref =
percent = map ((/ tot) . fromIntegral) dif
return percent
-formatCpu :: [Float] -> Monitor [String]
-formatCpu [] = return $ replicate 8 ""
-formatCpu xs = do
+formatCpu :: CpuOpts -> [Float] -> Monitor [String]
+formatCpu _ [] = return $ replicate 8 ""
+formatCpu opts xs = do
let t = sum $ take 3 xs
b <- showPercentBar (100 * t) t
v <- showVerticalBar (100 * t) t
+ d <- showDynamicString (loadDynamicString opts) t
ps <- showPercentsWithColors (t:xs)
- return (b:v:ps)
+ return (b:v:d:ps)
runCpu :: CpuDataRef -> [String] -> Monitor String
-runCpu cref _ =
+runCpu cref argv =
do c <- io (parseCpu cref)
- l <- formatCpu c
+ opts <- io $ parseOpts argv
+ l <- formatCpu opts c
parseTemplate l
startCpu :: [String] -> Int -> (String -> IO ()) -> IO ()