summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/Monitors/Mem.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Plugins/Monitors/Mem.hs')
-rw-r--r--src/Plugins/Monitors/Mem.hs45
1 files changed, 37 insertions, 8 deletions
diff --git a/src/Plugins/Monitors/Mem.hs b/src/Plugins/Monitors/Mem.hs
index db2e5de..7524989 100644
--- a/src/Plugins/Monitors/Mem.hs
+++ b/src/Plugins/Monitors/Mem.hs
@@ -16,12 +16,38 @@ module Plugins.Monitors.Mem (memConfig, runMem, totalMem, usedMem) where
import Plugins.Monitors.Common
import qualified Data.Map as M
+import System.Console.GetOpt
+
+data MemOpts = MemOpts
+ { usedDynamicString :: Maybe DynamicString
+ , freeDynamicString :: Maybe DynamicString
+ }
+
+defaultOpts :: MemOpts
+defaultOpts = MemOpts
+ { usedDynamicString = Nothing
+ , freeDynamicString = Nothing
+ }
+
+options :: [OptDescr (MemOpts -> MemOpts)]
+options =
+ [ Option "" ["used-dynamic-string"] (ReqArg (\x o ->
+ o { usedDynamicString = Just $ parseDynamicString x }) "") ""
+ , Option "" ["free-dynamic-string"] (ReqArg (\x o ->
+ o { freeDynamicString = Just $ parseDynamicString x }) "") ""
+ ]
+
+parseOpts :: [String] -> IO MemOpts
+parseOpts argv =
+ case getOpt Permute options argv of
+ (o, _, []) -> return $ foldr id defaultOpts o
+ (_, _, errs) -> ioError . userError $ concat errs
memConfig :: IO MConfig
memConfig = mkMConfig
"Mem: <usedratio>% (<cache>M)" -- template
- ["usedbar", "usedvbar", "freebar", "freevbar", "usedratio", "freeratio", "total",
- "free", "buffer", "cache", "rest", "used"] -- available replacements
+ ["usedbar", "usedvbar", "useddstr", "freebar", "freevbar", "freedstr", "usedratio", "freeratio",
+ "total", "free", "buffer", "cache", "rest", "used"] -- available replacements
fileMEM :: IO String
fileMEM = readFile "/proc/meminfo"
@@ -44,22 +70,25 @@ totalMem = fmap ((*1024) . (!!1)) parseMEM
usedMem :: IO Float
usedMem = fmap ((*1024) . (!!6)) parseMEM
-formatMem :: [Float] -> Monitor [String]
-formatMem (r:fr:xs) =
+formatMem :: MemOpts -> [Float] -> Monitor [String]
+formatMem opts (r:fr:xs) =
do let f = showDigits 0
rr = 100 * r
ub <- showPercentBar rr r
uvb <- showVerticalBar rr r
+ udstr <- showDynamicString (usedDynamicString opts) r
fb <- showPercentBar (100 - rr) (1 - r)
fvb <- showVerticalBar (100 - rr) ( 1 - r)
+ fdstr <- showDynamicString (freeDynamicString opts) (1 - r)
rs <- showPercentWithColors r
fs <- showPercentWithColors fr
s <- mapM (showWithColors f) xs
- return (ub:uvb:fb:fvb:rs:fs:s)
-formatMem _ = replicate 10 `fmap` getConfigValue naString
+ return (ub:uvb:udstr:fb:fvb:fdstr:rs:fs:s)
+formatMem _ _ = replicate 10 `fmap` getConfigValue naString
runMem :: [String] -> Monitor String
-runMem _ =
+runMem argv =
do m <- io parseMEM
- l <- formatMem m
+ opts <- io $ parseOpts argv
+ l <- formatMem opts m
parseTemplate l