{-#LANGUAGE CPP #-}
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 <- Selector Int -> Monitor Int
forall a. Selector a -> Monitor a
getConfigValue Selector Int
decDigits
[String]
other <- (Float -> ReaderT MConfig IO String) -> [Float] -> Monitor [String]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((Float -> String) -> Float -> ReaderT MConfig IO String
forall a.
(Num a, Ord a) =>
(a -> String) -> a -> ReaderT MConfig IO String
showWithColors (Int -> Float -> String
forall a. RealFloat a => Int -> a -> String
showDigits Int
d)) [Float]
xs
String
ratio <- Float -> ReaderT MConfig IO String
showPercentWithColors Float
r
[String] -> Monitor [String]
forall (m :: * -> *) a. Monad m => a -> m a
return ([String] -> Monitor [String]) -> [String] -> Monitor [String]
forall a b. (a -> b) -> a -> b
$ String
ratioString -> [String] -> [String]
forall a. a -> [a] -> [a]
:[String]
other
formatSwap [Float]
_ = Int -> String -> [String]
forall a. Int -> a -> [a]
replicate Int
4 (String -> [String])
-> ReaderT MConfig IO String -> Monitor [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Selector String -> ReaderT MConfig IO String
forall a. Selector a -> Monitor a
getConfigValue Selector String
naString
runSwap :: [String] -> Monitor String
runSwap :: [String] -> ReaderT MConfig IO String
runSwap [String]
_ =
do [Float]
m <- IO [Float] -> Monitor [Float]
forall a. IO a -> Monitor a
io IO [Float]
MS.parseMEM
[String]
l <- [Float] -> Monitor [String]
formatSwap [Float]
m
[String] -> ReaderT MConfig IO String
parseTemplate [String]
l