summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/Monitors/Mem.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/Mem.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/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