diff options
author | jao <jao@gnu.org> | 2014-09-24 20:54:16 +0200 |
---|---|---|
committer | jao <jao@gnu.org> | 2014-09-24 20:54:16 +0200 |
commit | b0f07db920d9ed446532dfc1aaddd3e7f57d0592 (patch) | |
tree | 53c0c3ee80a8db536b6fb6decc492c72e7c5a663 /src/Plugins/Monitors/Mem.hs | |
parent | b7973cb8af3b03f6add1a0f0bb4cc790b1223609 (diff) | |
parent | f8b7b22253d72b7b6ecf83bac87a8cda41040f49 (diff) | |
download | xmobar-b0f07db920d9ed446532dfc1aaddd3e7f57d0592.tar.gz xmobar-b0f07db920d9ed446532dfc1aaddd3e7f57d0592.tar.bz2 |
Merge branch 'dynamic-strings' of https://github.com/projedi/xmobar
Diffstat (limited to 'src/Plugins/Monitors/Mem.hs')
-rw-r--r-- | src/Plugins/Monitors/Mem.hs | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/src/Plugins/Monitors/Mem.hs b/src/Plugins/Monitors/Mem.hs index db2e5de..b19c5a7 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 + { usedIconPattern :: Maybe IconPattern + , freeIconPattern :: Maybe IconPattern + } + +defaultOpts :: MemOpts +defaultOpts = MemOpts + { usedIconPattern = Nothing + , freeIconPattern = Nothing + } + +options :: [OptDescr (MemOpts -> MemOpts)] +options = + [ Option "" ["used-icon-pattern"] (ReqArg (\x o -> + o { usedIconPattern = Just $ parseIconPattern x }) "") "" + , Option "" ["free-icon-pattern"] (ReqArg (\x o -> + o { freeIconPattern = Just $ parseIconPattern 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", "usedipat", "freebar", "freevbar", "freeipat", "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 + uipat <- showIconPattern (usedIconPattern opts) r fb <- showPercentBar (100 - rr) (1 - r) fvb <- showVerticalBar (100 - rr) ( 1 - r) + fipat <- showIconPattern (freeIconPattern 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:uipat:fb:fvb:fipat: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 |