diff options
author | jao <jao@gnu.org> | 2022-04-14 16:41:36 +0100 |
---|---|---|
committer | jao <jao@gnu.org> | 2022-04-14 16:41:36 +0100 |
commit | 727478f5b8916d8d98ae4208d4f6a80abb4fafc7 (patch) | |
tree | 4fa4a57f31e5cc9cfd172edb31eae420809dbec5 /src | |
parent | c714967eb3cab550ed1387d43182ee3b498124e3 (diff) | |
download | xmobar-727478f5b8916d8d98ae4208d4f6a80abb4fafc7.tar.gz xmobar-727478f5b8916d8d98ae4208d4f6a80abb4fafc7.tar.bz2 |
Memory: new argument to scale usage units
Fixes #624
Diffstat (limited to 'src')
-rw-r--r-- | src/Xmobar/Plugins/Monitors/Mem.hs | 24 | ||||
-rw-r--r-- | src/Xmobar/Plugins/Monitors/Mem/Linux.hs | 9 |
2 files changed, 18 insertions, 15 deletions
diff --git a/src/Xmobar/Plugins/Monitors/Mem.hs b/src/Xmobar/Plugins/Monitors/Mem.hs index 6a863ce..d55ac2b 100644 --- a/src/Xmobar/Plugins/Monitors/Mem.hs +++ b/src/Xmobar/Plugins/Monitors/Mem.hs @@ -13,7 +13,7 @@ -- ----------------------------------------------------------------------------- -module Xmobar.Plugins.Monitors.Mem (memConfig, runMem, totalMem, usedMem) where +module Xmobar.Plugins.Monitors.Mem (memConfig, runMem) where import Xmobar.Plugins.Monitors.Common import System.Console.GetOpt @@ -29,6 +29,7 @@ data MemOpts = MemOpts { usedIconPattern :: Maybe IconPattern , freeIconPattern :: Maybe IconPattern , availableIconPattern :: Maybe IconPattern + , scale :: Float } defaultOpts :: MemOpts @@ -36,6 +37,7 @@ defaultOpts = MemOpts { usedIconPattern = Nothing , freeIconPattern = Nothing , availableIconPattern = Nothing + , scale = 1.0 } options :: [OptDescr (MemOpts -> MemOpts)] @@ -46,31 +48,29 @@ options = o { freeIconPattern = Just $ parseIconPattern x }) "") "" , Option "" ["available-icon-pattern"] (ReqArg (\x o -> o { availableIconPattern = Just $ parseIconPattern x }) "") "" + , Option "" ["scale"] (ReqArg (\x o -> o { scale = read x }) "") "" ] memConfig :: IO MConfig memConfig = mkMConfig - "Mem: <usedratio>% (<cache>M)" -- template + "Mem: <usedratio>% (<cache>M)" ["usedbar", "usedvbar", "usedipat", "freebar", "freevbar", "freeipat", "availablebar", "availablevbar", "availableipat", "usedratio", "freeratio", "availableratio", - "total", "free", "buffer", "cache", "available", "used"] -- available replacements - -totalMem :: IO Float -totalMem = fmap ((*1024) . (!!1)) MM.parseMEM - -usedMem :: IO Float -usedMem = fmap ((*1024) . (!!6)) MM.parseMEM + "total", "free", "buffer", "cache", "available", "used"] formatMem :: MemOpts -> [Float] -> Monitor [String] formatMem opts (r:fr:ar:xs) = - do let f = showDigits 0 - mon i x = [showPercentBar (100 * x) x, showVerticalBar (100 * x) x, showIconPattern i x] + do d <- getConfigValue decDigits + let f = showDigits d + mon i x = [ showPercentBar (100 * x) x + , showVerticalBar (100 * x) x + , showIconPattern i x] sequence $ mon (usedIconPattern opts) r ++ mon (freeIconPattern opts) fr ++ mon (availableIconPattern opts) ar ++ map showPercentWithColors [r, fr, ar] - ++ map (showWithColors f) xs + ++ map (showWithColors f . (/ scale opts)) xs formatMem _ _ = replicate 10 `fmap` getConfigValue naString runMem :: [String] -> Monitor String diff --git a/src/Xmobar/Plugins/Monitors/Mem/Linux.hs b/src/Xmobar/Plugins/Monitors/Mem/Linux.hs index 9e48d22..79dcc9d 100644 --- a/src/Xmobar/Plugins/Monitors/Mem/Linux.hs +++ b/src/Xmobar/Plugins/Monitors/Mem/Linux.hs @@ -23,11 +23,14 @@ parseMEM :: IO [Float] parseMEM = do file <- fileMEM let content = map words $ take 8 $ lines file - info = M.fromList $ map (\line -> (head line, (read $ line !! 1 :: Float) / 1024)) content - [total, free, buffer, cache] = map (info M.!) ["MemTotal:", "MemFree:", "Buffers:", "Cached:"] + info = M.fromList $ map ( + \line -> (head line, (read $ line !! 1 :: Float) / 1024)) content + [total, free, buffer, cache] = + map (info M.!) ["MemTotal:", "MemFree:", "Buffers:", "Cached:"] available = M.findWithDefault (free + buffer + cache) "MemAvailable:" info used = total - available usedratio = used / total freeratio = free / total availableratio = available / total - return [usedratio, freeratio, availableratio, total, free, buffer, cache, available, used] + return [ usedratio, freeratio, availableratio + , total, free, buffer, cache, available, used] |