{-#LANGUAGE CPP #-}
module Xmobar.Plugins.Monitors.Uptime (uptimeConfig, runUptime) where
import Xmobar.Plugins.Monitors.Common
#if defined(freebsd_HOST_OS)
import qualified Xmobar.Plugins.Monitors.Uptime.FreeBSD as MU
#else
import qualified Xmobar.Plugins.Monitors.Uptime.Linux as MU
#endif
uptimeConfig :: IO MConfig
uptimeConfig :: IO MConfig
uptimeConfig = String -> [String] -> IO MConfig
mkMConfig String
"Up <days>d <hours>h <minutes>m"
[String
"days", String
"hours", String
"minutes", String
"seconds"]
secsPerDay :: Integer
secsPerDay :: Integer
secsPerDay = Integer
24 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
3600
uptime :: Monitor [String]
uptime :: Monitor [String]
uptime = do
t <- IO Float -> Monitor Float
forall a. IO a -> Monitor a
io IO Float
MU.readUptime
u <- getConfigValue useSuffix
let tsecs = Float -> Integer
forall b. Integral b => Float -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor Float
t
secs = Integer
tsecs Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
`mod` Integer
secsPerDay
days = Integer
tsecs Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
`quot` Integer
secsPerDay
hours = Integer
secs Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
`quot` Integer
3600
mins = (Integer
secs Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
`mod` Integer
3600) Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
`div` Integer
60
ss = Integer
secs Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
`mod` Integer
60
str a
x String
s = if Bool
u then a -> String
forall a. Show a => a -> String
show a
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
s else a -> String
forall a. Show a => a -> String
show a
x
mapM (`showWithColors'` days)
[str days "d", str hours "h", str mins "m", str ss "s"]
runUptime :: [String] -> Monitor String
runUptime :: [String] -> ReaderT MConfig IO String
runUptime [String]
_ = Monitor [String]
uptime Monitor [String]
-> ([String] -> ReaderT MConfig IO String)
-> ReaderT MConfig IO String
forall a b.
ReaderT MConfig IO a
-> (a -> ReaderT MConfig IO b) -> ReaderT MConfig IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [String] -> ReaderT MConfig IO String
parseTemplate