{-#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
  d <- Selector Int -> Monitor Int
forall a. Selector a -> Monitor a
getConfigValue Selector Int
decDigits
  other <- mapM (showWithColors (showDigits d)) xs
  ratio <- showPercentWithColors r
  return $ ratio:other
formatSwap [Float]
_ = Int -> String -> [String]
forall a. Int -> a -> [a]
replicate Int
4 (String -> [String])
-> ReaderT MConfig IO String -> Monitor [String]
forall a b.
(a -> b) -> ReaderT MConfig IO a -> ReaderT MConfig IO b
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 m <- IO [Float] -> Monitor [Float]
forall a. IO a -> Monitor a
io IO [Float]
MS.parseMEM
       l <- formatSwap m
       parseTemplate l