{-#LANGUAGE CPP #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Plugins.Monitors.Swap
-- Copyright   :  (c) Andrea Rossato
-- License     :  BSD-style (see LICENSE)
--
-- Maintainer  :  Jose A. Ortega Ruiz <jao@gnu.org>
-- Stability   :  unstable
-- Portability :  unportable
--
-- A  swap usage monitor for Xmobar
--
-----------------------------------------------------------------------------

module Xmobar.Plugins.Monitors.Swap where

import Xmobar.Plugins.Monitors.Common

#if defined(freebsd_HOST_OS)
import qualified Xmobar.Plugins.Monitors.Swap.FreeBSD as MS
#else
import qualified Xmobar.Plugins.Monitors.Swap.Linux as MS
#endif

swapConfig :: IO MConfig
swapConfig :: IO MConfig
swapConfig = String -> [String] -> IO MConfig
mkMConfig String
"Swap: <usedratio>%"
                       [String
"usedratio", String
"total", String
"used", String
"free"]

formatSwap :: [Float] -> Monitor [String]
formatSwap :: [Float] -> Monitor [String]
formatSwap (Float
r:[Float]
xs) = do
  Int
d <- forall a. Selector a -> Monitor a
getConfigValue MConfig -> IORef Int
decDigits
  [String]
other <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall a. (Num a, Ord a) => (a -> String) -> a -> Monitor String
showWithColors (forall a. RealFloat a => Int -> a -> String
showDigits Int
d)) [Float]
xs
  String
ratio <- Float -> Monitor String
showPercentWithColors Float
r
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ String
ratioforall a. a -> [a] -> [a]
:[String]
other
formatSwap [Float]
_ = forall a. Int -> a -> [a]
replicate Int
4 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` forall a. Selector a -> Monitor a
getConfigValue MConfig -> IORef String
naString

runSwap :: [String] -> Monitor String
runSwap :: [String] -> Monitor String
runSwap [String]
_ =
    do [Float]
m <- forall a. IO a -> Monitor a
io IO [Float]
MS.parseMEM
       [String]
l <- [Float] -> Monitor [String]
formatSwap [Float]
m
       [String] -> Monitor String
parseTemplate [String]
l