-----------------------------------------------------------------------------
-- |
-- Module      :  Plugins.Monitors.MultiCoreTemp
-- Copyright   :  (c) 2019, 2020 Felix Springer
-- License     :  BSD-style (see LICENSE)
--
-- Maintainer  :  Felix Springer <felixspringer149@gmail.com>
-- Stability   :  unstable
-- Portability :  unportable
--
-- A core temperature monitor for Xmobar
--
-----------------------------------------------------------------------------

module Xmobar.Plugins.Monitors.MultiCoreTemp (startMultiCoreTemp) where

import Xmobar.Plugins.Monitors.Common
import Control.Monad (filterM)
import Data.Char (isDigit)
import Data.List (isPrefixOf)
import System.Console.GetOpt
import System.Directory ( doesDirectoryExist
                        , doesFileExist
                        , listDirectory
                        )

-- | Declare Options.
data CTOpts = CTOpts { CTOpts -> Maybe IconPattern
maxIconPattern :: Maybe IconPattern
                     , CTOpts -> Maybe IconPattern
avgIconPattern :: Maybe IconPattern
                     , CTOpts -> Float
mintemp :: Float
                     , CTOpts -> Float
maxtemp :: Float
                     , CTOpts -> Maybe [Char]
hwMonitorPath :: Maybe String
                     }

-- | Set default Options.
defaultOpts :: CTOpts
defaultOpts :: CTOpts
defaultOpts = CTOpts { maxIconPattern :: Maybe IconPattern
maxIconPattern = Maybe IconPattern
forall a. Maybe a
Nothing
                     , avgIconPattern :: Maybe IconPattern
avgIconPattern = Maybe IconPattern
forall a. Maybe a
Nothing
                     , mintemp :: Float
mintemp = Float
0
                     , maxtemp :: Float
maxtemp = Float
100
                     , hwMonitorPath :: Maybe [Char]
hwMonitorPath = Maybe [Char]
forall a. Maybe a
Nothing
                     }

-- | Apply configured Options.
options :: [OptDescr (CTOpts -> CTOpts)]
options :: [OptDescr (CTOpts -> CTOpts)]
options = [ [Char]
-> [[Char]]
-> ArgDescr (CTOpts -> CTOpts)
-> [Char]
-> OptDescr (CTOpts -> CTOpts)
forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
Option [] [[Char]
"max-icon-pattern"]
              (([Char] -> CTOpts -> CTOpts)
-> [Char] -> ArgDescr (CTOpts -> CTOpts)
forall a. ([Char] -> a) -> [Char] -> ArgDescr a
ReqArg
                (\ [Char]
arg CTOpts
opts -> CTOpts
opts { maxIconPattern = Just $ parseIconPattern arg })
                [Char]
"")
              [Char]
""
          , [Char]
-> [[Char]]
-> ArgDescr (CTOpts -> CTOpts)
-> [Char]
-> OptDescr (CTOpts -> CTOpts)
forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
Option [] [[Char]
"avg-icon-pattern"]
              (([Char] -> CTOpts -> CTOpts)
-> [Char] -> ArgDescr (CTOpts -> CTOpts)
forall a. ([Char] -> a) -> [Char] -> ArgDescr a
ReqArg
                (\ [Char]
arg CTOpts
opts -> CTOpts
opts { avgIconPattern = Just $ parseIconPattern arg })
                [Char]
"")
              [Char]
""
          , [Char]
-> [[Char]]
-> ArgDescr (CTOpts -> CTOpts)
-> [Char]
-> OptDescr (CTOpts -> CTOpts)
forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
Option [] [[Char]
"mintemp"]
              (([Char] -> CTOpts -> CTOpts)
-> [Char] -> ArgDescr (CTOpts -> CTOpts)
forall a. ([Char] -> a) -> [Char] -> ArgDescr a
ReqArg
                (\ [Char]
arg CTOpts
opts -> CTOpts
opts { mintemp = read arg })
                [Char]
"")
              [Char]
""
          , [Char]
-> [[Char]]
-> ArgDescr (CTOpts -> CTOpts)
-> [Char]
-> OptDescr (CTOpts -> CTOpts)
forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
Option [] [[Char]
"maxtemp"]
              (([Char] -> CTOpts -> CTOpts)
-> [Char] -> ArgDescr (CTOpts -> CTOpts)
forall a. ([Char] -> a) -> [Char] -> ArgDescr a
ReqArg
                (\ [Char]
arg CTOpts
opts -> CTOpts
opts { maxtemp = read arg })
                [Char]
"")
              [Char]
""
          , [Char]
-> [[Char]]
-> ArgDescr (CTOpts -> CTOpts)
-> [Char]
-> OptDescr (CTOpts -> CTOpts)
forall a. [Char] -> [[Char]] -> ArgDescr a -> [Char] -> OptDescr a
Option [] [[Char]
"hwmon-path"]
              (([Char] -> CTOpts -> CTOpts)
-> [Char] -> ArgDescr (CTOpts -> CTOpts)
forall a. ([Char] -> a) -> [Char] -> ArgDescr a
ReqArg
                (\ [Char]
arg CTOpts
opts -> CTOpts
opts { hwMonitorPath = Just arg })
                [Char]
"")
              [Char]
""
          ]

-- | Generate Config with a default template and options.
cTConfig :: IO MConfig
cTConfig :: IO MConfig
cTConfig = [Char] -> [[Char]] -> IO MConfig
mkMConfig [Char]
cTTemplate [[Char]]
cTOptions
  where cTTemplate :: [Char]
cTTemplate = [Char]
"Temp: <max>°C - <maxpc>%"
        cTOptions :: [[Char]]
cTOptions = [ [Char]
"max" , [Char]
"maxpc" , [Char]
"maxbar" , [Char]
"maxvbar" , [Char]
"maxipat"
                    , [Char]
"avg" , [Char]
"avgpc" , [Char]
"avgbar" , [Char]
"avgvbar" , [Char]
"avgipat"
                    ] [[Char]] -> [[Char]] -> [[Char]]
forall a. [a] -> [a] -> [a]
++ IconPattern -> [Int] -> [[Char]]
forall a b. (a -> b) -> [a] -> [b]
map (([Char]
"core" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++) ([Char] -> [Char]) -> IconPattern -> IconPattern
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IconPattern
forall a. Show a => a -> [Char]
show) [Int
0 :: Int ..]

-- | Returns all paths in dir matching the predicate.
getMatchingPathsInDir :: FilePath -> (String -> Bool) -> IO [FilePath]
getMatchingPathsInDir :: [Char] -> ([Char] -> Bool) -> IO [[Char]]
getMatchingPathsInDir [Char]
dir [Char] -> Bool
f = do Bool
exists <- [Char] -> IO Bool
doesDirectoryExist [Char]
dir
                                 if Bool
exists
                                    then do
                                      [[Char]]
files <- ([Char] -> Bool) -> [[Char]] -> [[Char]]
forall a. (a -> Bool) -> [a] -> [a]
filter [Char] -> Bool
f ([[Char]] -> [[Char]]) -> IO [[Char]] -> IO [[Char]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Char] -> IO [[Char]]
listDirectory [Char]
dir
                                      [[Char]] -> IO [[Char]]
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([[Char]] -> IO [[Char]]) -> [[Char]] -> IO [[Char]]
forall a b. (a -> b) -> a -> b
$ ([Char] -> [Char]) -> [[Char]] -> [[Char]]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\[Char]
file -> [Char]
dir [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"/" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
file) [[Char]]
files
                                    else [[Char]] -> IO [[Char]]
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return []

-- | Given a prefix, suffix, and path string, return true if the path string
-- format is prefix ++ numeric ++ suffix.
numberedPathMatcher :: String -> String -> String -> Bool
numberedPathMatcher :: [Char] -> [Char] -> [Char] -> Bool
numberedPathMatcher [Char]
prefix [Char]
suffix [Char]
path =
    [Char]
prefix [Char] -> [Char] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` [Char]
path
    Bool -> Bool -> Bool
&& Bool -> Bool
not ([Char] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
digits)
    Bool -> Bool -> Bool
&& [Char]
afterDigits [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
suffix
  where afterPrefix :: [Char]
afterPrefix = Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
drop ([Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
prefix) [Char]
path
        digits :: [Char]
digits = (Char -> Bool) -> [Char] -> [Char]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile Char -> Bool
isDigit [Char]
afterPrefix
        afterDigits :: [Char]
afterDigits = (Char -> Bool) -> [Char] -> [Char]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isDigit [Char]
afterPrefix

-- | Returns the first coretemp.N path found.
coretempPath :: IO (Maybe String)
coretempPath :: IO (Maybe [Char])
coretempPath = do [[Char]]
ps <- [Char] -> ([Char] -> Bool) -> IO [[Char]]
getMatchingPathsInDir [Char]
"/sys/bus/platform/devices" [Char] -> Bool
coretempMatcher
                  [[Char]]
xs <- ([Char] -> IO Bool) -> [[Char]] -> IO [[Char]]
forall (m :: * -> *) a.
Applicative m =>
(a -> m Bool) -> [a] -> m [a]
filterM [Char] -> IO Bool
doesDirectoryExist [[Char]]
ps
                  Maybe [Char] -> IO (Maybe [Char])
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (if [[Char]] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Char]]
xs then Maybe [Char]
forall a. Maybe a
Nothing else [Char] -> Maybe [Char]
forall a. a -> Maybe a
Just ([Char] -> Maybe [Char]) -> [Char] -> Maybe [Char]
forall a b. (a -> b) -> a -> b
$ [[Char]] -> [Char]
forall a. HasCallStack => [a] -> a
head [[Char]]
xs [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"/")
  where coretempMatcher :: [Char] -> Bool
coretempMatcher = [Char] -> [Char] -> [Char] -> Bool
numberedPathMatcher [Char]
"coretemp." [Char]
""

-- | Returns the first hwmonN in coretemp path found or the ones in sys/class.
hwmonPaths :: IO [String]
hwmonPaths :: IO [[Char]]
hwmonPaths = do Maybe [Char]
p <- IO (Maybe [Char])
coretempPath
                let (Bool
sc, [Char]
path) = case Maybe [Char]
p of
                                   Just [Char]
s -> (Bool
False, [Char]
s)
                                   Maybe [Char]
Nothing -> (Bool
True, [Char]
"/sys/class/")
                [[Char]]
cps <- [Char] -> ([Char] -> Bool) -> IO [[Char]]
getMatchingPathsInDir ([Char]
path [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"hwmon") [Char] -> Bool
hwmonMatcher
                [[Char]]
ecps <- ([Char] -> IO Bool) -> [[Char]] -> IO [[Char]]
forall (m :: * -> *) a.
Applicative m =>
(a -> m Bool) -> [a] -> m [a]
filterM [Char] -> IO Bool
doesDirectoryExist [[Char]]
cps
                [[Char]] -> IO [[Char]]
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([[Char]] -> IO [[Char]]) -> [[Char]] -> IO [[Char]]
forall a b. (a -> b) -> a -> b
$ if Bool
sc Bool -> Bool -> Bool
|| [[Char]] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Char]]
ecps then [[Char]]
ecps else [[[Char]] -> [Char]
forall a. HasCallStack => [a] -> a
head [[Char]]
ecps]
  where hwmonMatcher :: [Char] -> Bool
hwmonMatcher = [Char] -> [Char] -> [Char] -> Bool
numberedPathMatcher [Char]
"hwmon" [Char]
""

-- | Checks Labels, if they refer to a core and returns Strings of core-
-- temperatures.
corePaths :: Maybe String -> IO [String]
corePaths :: Maybe [Char] -> IO [[Char]]
corePaths Maybe [Char]
s = do [[Char]]
ps <- case Maybe [Char]
s of
                        Just [Char]
pth -> [[Char]] -> IO [[Char]]
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return [[Char]
pth]
                        Maybe [Char]
_ -> IO [[Char]]
hwmonPaths
                 [[Char]]
cps <- [[[Char]]] -> [[Char]]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[[Char]]] -> [[Char]]) -> IO [[[Char]]] -> IO [[Char]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Char] -> IO [[Char]]) -> [[Char]] -> IO [[[Char]]]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse ([Char] -> ([Char] -> Bool) -> IO [[Char]]
`getMatchingPathsInDir` [Char] -> Bool
corePathMatcher) [[Char]]
ps
                 [[Char]]
ls <- ([Char] -> IO Bool) -> [[Char]] -> IO [[Char]]
forall (m :: * -> *) a.
Applicative m =>
(a -> m Bool) -> [a] -> m [a]
filterM [Char] -> IO Bool
doesFileExist [[Char]]
cps
                 [[Char]]
cls <- ([Char] -> IO Bool) -> [[Char]] -> IO [[Char]]
forall (m :: * -> *) a.
Applicative m =>
(a -> m Bool) -> [a] -> m [a]
filterM [Char] -> IO Bool
isLabelFromCore [[Char]]
ls
                 [[Char]] -> IO [[Char]]
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([[Char]] -> IO [[Char]]) -> [[Char]] -> IO [[Char]]
forall a b. (a -> b) -> a -> b
$ ([Char] -> [Char]) -> [[Char]] -> [[Char]]
forall a b. (a -> b) -> [a] -> [b]
map [Char] -> [Char]
labelToCore [[Char]]
cls
  where corePathMatcher :: [Char] -> Bool
corePathMatcher = [Char] -> [Char] -> [Char] -> Bool
numberedPathMatcher [Char]
"temp" [Char]
"_label"

-- | Checks if Label refers to a core.
isLabelFromCore :: FilePath -> IO Bool
isLabelFromCore :: [Char] -> IO Bool
isLabelFromCore [Char]
p = do [Char]
a <- [Char] -> IO [Char]
readFile [Char]
p
                       Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> IO Bool) -> Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
take Int
4 [Char]
a [Char] -> [[Char]] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [[Char]
"Core", [Char]
"Tdie", [Char]
"Tctl"]

-- | Transform a path to Label to a path to core-temperature.
labelToCore :: FilePath -> FilePath
labelToCore :: [Char] -> [Char]
labelToCore = ([Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"input") ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char]
forall a. [a] -> [a]
reverse ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
drop Int
5 ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char]
forall a. [a] -> [a]
reverse

-- | Reads core-temperatures as data from the system.
cTData :: Maybe String -> IO [Float]
cTData :: Maybe [Char] -> IO [Float]
cTData Maybe [Char]
p = do [[Char]]
fps <- Maybe [Char] -> IO [[Char]]
corePaths Maybe [Char]
p
              ([Char] -> IO Float) -> [[Char]] -> IO [Float]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse [Char] -> IO Float
readSingleFile [[Char]]
fps
  where readSingleFile :: FilePath -> IO Float
        readSingleFile :: [Char] -> IO Float
readSingleFile [Char]
s = do [Char]
a <- [Char] -> IO [Char]
readFile [Char]
s
                              Float -> IO Float
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Float -> IO Float) -> Float -> IO Float
forall a b. (a -> b) -> a -> b
$ [Char] -> Float
parseContent [Char]
a
          where parseContent :: String -> Float
                parseContent :: [Char] -> Float
parseContent = [Char] -> Float
forall a. Read a => [Char] -> a
read ([Char] -> Float) -> ([Char] -> [Char]) -> [Char] -> Float
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Char]] -> [Char]
forall a. HasCallStack => [a] -> a
head ([[Char]] -> [Char]) -> ([Char] -> [[Char]]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [[Char]]
lines

-- | Transforms data of temperatures into temperatures of degree Celsius.
parseCT :: CTOpts -> IO [Float]
parseCT :: CTOpts -> IO [Float]
parseCT CTOpts
opts = do [Float]
rawCTs <- Maybe [Char] -> IO [Float]
cTData (CTOpts -> Maybe [Char]
hwMonitorPath CTOpts
opts)
                  let normalizedCTs :: [Float]
normalizedCTs = (Float -> Float) -> [Float] -> [Float]
forall a b. (a -> b) -> [a] -> [b]
map (Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
1000) [Float]
rawCTs :: [Float]
                  [Float] -> IO [Float]
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return [Float]
normalizedCTs

-- | Performs calculation for maximum and average.
-- Sets up Bars and Values to be printed.
formatCT :: CTOpts -> [Float] -> Monitor [String]
formatCT :: CTOpts -> [Float] -> Monitor [[Char]]
formatCT CTOpts
opts [Float]
cTs = do let CTOpts { mintemp :: CTOpts -> Float
mintemp = Float
minT
                                  , maxtemp :: CTOpts -> Float
maxtemp = Float
maxT } = CTOpts
opts
                           domainT :: Float
domainT = Float
maxT Float -> Float -> Float
forall a. Num a => a -> a -> a
- Float
minT
                           maxCT :: Float
maxCT = [Float] -> Float
forall a. Ord a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum [Float]
cTs
                           avgCT :: Float
avgCT = [Float] -> Float
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum [Float]
cTs Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Int -> Float
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([Float] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Float]
cTs)
                           calcPc :: Float -> Float
calcPc Float
t = (Float
t Float -> Float -> Float
forall a. Num a => a -> a -> a
- Float
minT) Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
domainT
                           maxCTPc :: Float
maxCTPc = Float -> Float
calcPc Float
maxCT
                           avgCTPc :: Float
avgCTPc = Float -> Float
calcPc Float
avgCT

                       [[Char]]
cs <- (Float -> ReaderT MConfig IO [Char]) -> [Float] -> Monitor [[Char]]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse Float -> ReaderT MConfig IO [Char]
showTempWithColors [Float]
cTs

                       [Char]
m <- Float -> ReaderT MConfig IO [Char]
showTempWithColors Float
maxCT
                       [Char]
mp <- [Char] -> Float -> ReaderT MConfig IO [Char]
forall a.
(Num a, Ord a) =>
[Char] -> a -> ReaderT MConfig IO [Char]
showWithColors' (IconPattern
forall a. Show a => a -> [Char]
show (Float -> Int
forall b. Integral b => Float -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (Float
100Float -> Float -> Float
forall a. Num a => a -> a -> a
*Float
maxCTPc) :: Int)) Float
maxCT
                       [Char]
mb <- Float -> Float -> ReaderT MConfig IO [Char]
showPercentBar Float
maxCT Float
maxCTPc
                       [Char]
mv <- Float -> Float -> ReaderT MConfig IO [Char]
showVerticalBar Float
maxCT Float
maxCTPc
                       [Char]
mi <- Maybe IconPattern -> Float -> ReaderT MConfig IO [Char]
showIconPattern (CTOpts -> Maybe IconPattern
maxIconPattern CTOpts
opts) Float
maxCTPc

                       [Char]
a <- Float -> ReaderT MConfig IO [Char]
showTempWithColors Float
avgCT
                       [Char]
ap <- [Char] -> Float -> ReaderT MConfig IO [Char]
forall a.
(Num a, Ord a) =>
[Char] -> a -> ReaderT MConfig IO [Char]
showWithColors' (IconPattern
forall a. Show a => a -> [Char]
show (Float -> Int
forall b. Integral b => Float -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (Float
100Float -> Float -> Float
forall a. Num a => a -> a -> a
*Float
avgCTPc) :: Int)) Float
avgCT
                       [Char]
ab <- Float -> Float -> ReaderT MConfig IO [Char]
showPercentBar Float
avgCT Float
avgCTPc
                       [Char]
av <- Float -> Float -> ReaderT MConfig IO [Char]
showVerticalBar Float
avgCT Float
avgCTPc
                       [Char]
ai <- Maybe IconPattern -> Float -> ReaderT MConfig IO [Char]
showIconPattern (CTOpts -> Maybe IconPattern
avgIconPattern CTOpts
opts) Float
avgCTPc

                       let ms :: [[Char]]
ms = [ [Char]
m , [Char]
mp , [Char]
mb , [Char]
mv , [Char]
mi ]
                           as :: [[Char]]
as = [ [Char]
a , [Char]
ap , [Char]
ab , [Char]
av , [Char]
ai ]

                       [[Char]] -> Monitor [[Char]]
forall a. a -> ReaderT MConfig IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([[Char]]
ms [[Char]] -> [[Char]] -> [[Char]]
forall a. [a] -> [a] -> [a]
++ [[Char]]
as [[Char]] -> [[Char]] -> [[Char]]
forall a. [a] -> [a] -> [a]
++ [[Char]]
cs)
  where showTempWithColors :: Float -> Monitor String
        showTempWithColors :: Float -> ReaderT MConfig IO [Char]
showTempWithColors = (Float -> [Char]) -> Float -> ReaderT MConfig IO [Char]
forall a.
(Num a, Ord a) =>
(a -> [Char]) -> a -> ReaderT MConfig IO [Char]
showWithColors (IconPattern
forall a. Show a => a -> [Char]
show IconPattern -> (Float -> Int) -> Float -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Float -> Int
forall b. Integral b => Float -> b
forall a b. (RealFrac a, Integral b) => a -> b
round :: Float -> Int))


runCT :: [String] -> Monitor String
runCT :: [[Char]] -> ReaderT MConfig IO [Char]
runCT [[Char]]
argv = do CTOpts
opts <- IO CTOpts -> Monitor CTOpts
forall a. IO a -> Monitor a
io (IO CTOpts -> Monitor CTOpts) -> IO CTOpts -> Monitor CTOpts
forall a b. (a -> b) -> a -> b
$ [OptDescr (CTOpts -> CTOpts)] -> CTOpts -> [[Char]] -> IO CTOpts
forall opts.
[OptDescr (opts -> opts)] -> opts -> [[Char]] -> IO opts
parseOptsWith [OptDescr (CTOpts -> CTOpts)]
options CTOpts
defaultOpts [[Char]]
argv
                [Float]
cTs <- IO [Float] -> Monitor [Float]
forall a. IO a -> Monitor a
io (IO [Float] -> Monitor [Float]) -> IO [Float] -> Monitor [Float]
forall a b. (a -> b) -> a -> b
$ CTOpts -> IO [Float]
parseCT CTOpts
opts
                [[Char]]
l <- CTOpts -> [Float] -> Monitor [[Char]]
formatCT CTOpts
opts [Float]
cTs
                [[Char]] -> ReaderT MConfig IO [Char]
parseTemplate [[Char]]
l

startMultiCoreTemp :: [String] -> Int -> (String -> IO ()) -> IO ()
startMultiCoreTemp :: [[Char]] -> Int -> ([Char] -> IO ()) -> IO ()
startMultiCoreTemp [[Char]]
a = [[Char]]
-> IO MConfig
-> ([[Char]] -> ReaderT MConfig IO [Char])
-> Int
-> ([Char] -> IO ())
-> IO ()
runM [[Char]]
a IO MConfig
cTConfig [[Char]] -> ReaderT MConfig IO [Char]
runCT