diff options
Diffstat (limited to 'Monitors')
| -rw-r--r-- | Monitors/Batt.hs | 21 | ||||
| -rw-r--r-- | Monitors/Common.hs | 39 | ||||
| -rw-r--r-- | Monitors/Cpu.hs | 21 | ||||
| -rw-r--r-- | Monitors/Mem.hs | 23 | ||||
| -rw-r--r-- | Monitors/Net.hs | 22 | ||||
| -rw-r--r-- | Monitors/Swap.hs | 21 | ||||
| -rw-r--r-- | Monitors/Weather.hs | 50 | 
7 files changed, 87 insertions, 110 deletions
| diff --git a/Monitors/Batt.hs b/Monitors/Batt.hs index b3890c8..fcc78fd 100644 --- a/Monitors/Batt.hs +++ b/Monitors/Batt.hs @@ -14,25 +14,18 @@  module Monitors.Batt where -import Data.IORef  import qualified Data.ByteString.Lazy.Char8 as B  import System.Posix.Files  import Monitors.Common  battConfig :: IO MConfig -battConfig =  -    do lc <- newIORef "#FF0000" -       l <- newIORef 25 -       nc <- newIORef "#FF0000" -       h <- newIORef 75 -       hc <- newIORef "#00FF00" -       t <- newIORef "Batt: <left>" -       p <- newIORef package -       u <- newIORef "" -       a <- newIORef [] -       e <- newIORef ["left"] -       return $ MC nc l lc h hc t p u a e +battConfig = newConfig +       "Batt: <left>" -- template +       package        -- package +       ""             -- usage tail? +       []             -- added args +       ["left"]       -- available replacements  fileB1 :: (String, String)  fileB1 = ("/proc/acpi/battery/BAT1/info", "/proc/acpi/battery/BAT1/state") @@ -84,4 +77,4 @@ main :: IO ()  main =      do let af = runBatt []         runMonitor battConfig af runBatt --}
\ No newline at end of file +-} diff --git a/Monitors/Common.hs b/Monitors/Common.hs index 3408122..a7c33e6 100644 --- a/Monitors/Common.hs +++ b/Monitors/Common.hs @@ -20,6 +20,7 @@ module Monitors.Common (                         , Opts (..)                         , setConfigValue                         , getConfigValue +                       , newConfig                         , runMonitor                         , runM                         , io @@ -65,11 +66,11 @@ import System.Exit  type Monitor a = ReaderT MConfig IO a  data MConfig = -    MC { normalColor :: IORef String +    MC { normalColor :: IORef (Maybe String)         , low :: IORef Int -       , lowColor :: IORef String +       , lowColor :: IORef (Maybe String)         , high :: IORef Int -       , highColor :: IORef String +       , highColor :: IORef (Maybe String)         , template :: IORef String         , packageName :: IORef String         , usageTail :: IORef String @@ -98,6 +99,24 @@ getConfigValue :: Selector a -> Monitor a  getConfigValue s =      sel s +newConfig :: String +          -> String +          -> String +          -> [OptDescr Opts] +          -> [String] +          -> IO MConfig +newConfig tmpl pkg usg args exprts = +    do lc <- newIORef Nothing +       l <- newIORef 33 +       nc <- newIORef Nothing +       h <- newIORef 66 +       hc <- newIORef Nothing +       t <- newIORef tmpl +       p <- newIORef pkg +       u <- newIORef usg +       a <- newIORef args +       e <- newIORef exprts +       return $ MC nc l lc h hc t p u a e  data Opts = Help            | Version @@ -162,9 +181,9 @@ doConfigOptions (o:oo) =           Version -> io $ versinfo pn version >> exitWith ExitSuccess           High h -> setConfigValue (read h) high >> next           Low l -> setConfigValue (read l) low >> next -         HighColor hc -> setConfigValue hc highColor >> next -         NormalColor nc -> setConfigValue nc normalColor >> next -         LowColor lc -> setConfigValue lc lowColor >> next +         HighColor hc -> setConfigValue (Just hc) highColor >> next +         NormalColor nc -> setConfigValue (Just nc) normalColor >> next +         LowColor lc -> setConfigValue (Just lc) lowColor >> next           Template t -> setConfigValue t template >> next           _ -> next @@ -279,11 +298,13 @@ stringParser :: Pos -> B.ByteString -> String  stringParser (x,y) =       flip (!!) x . map B.unpack . B.words . flip (!!) y . B.lines -setColor :: String -> Selector String -> Monitor String +setColor :: String -> Selector (Maybe String) -> Monitor String  setColor str s =      do a <- getConfigValue s -       return $ "<fc=" ++ a ++ ">" ++ -              str ++ "</fc>" +       case a of +            Nothing -> return str +            Just c -> return $ +                "<fc=" ++ c ++ ">" ++ str ++ "</fc>"  showWithColors :: (Float -> String) -> Float -> Monitor String  showWithColors f x = diff --git a/Monitors/Cpu.hs b/Monitors/Cpu.hs index 6f9b4fd..d629c14 100644 --- a/Monitors/Cpu.hs +++ b/Monitors/Cpu.hs @@ -16,21 +16,14 @@ module Monitors.Cpu where  import Monitors.Common  import qualified Data.ByteString.Lazy.Char8 as B -import Data.IORef  cpuConfig :: IO MConfig -cpuConfig =  -    do lc <- newIORef "#BFBFBF" -       l <- newIORef 2 -       nc <- newIORef "#00FF00" -       h <- newIORef 60 -       hc <- newIORef "#FF0000" -       t <- newIORef "Cpu: <total>" -       p <- newIORef package -       u <- newIORef "" -       a <- newIORef [] -       e <- newIORef ["total","user","nice","system","idle"] -       return $ MC nc l lc h hc t p u a e +cpuConfig = newConfig +       "Cpu: <total>"                           -- template +       package                                  -- package +       ""                                       -- usage tail? +       []                                       -- added args +       ["total","user","nice","system","idle"]  -- available replacements  cpuData :: IO [Float]  cpuData = do s <- B.readFile "/proc/stat" @@ -70,4 +63,4 @@ main :: IO ()  main =      do let af = runCpu []         runMonitor cpuConfig af runCpu --}
\ No newline at end of file +-} diff --git a/Monitors/Mem.hs b/Monitors/Mem.hs index 41f496d..4fd6434 100644 --- a/Monitors/Mem.hs +++ b/Monitors/Mem.hs @@ -16,21 +16,14 @@ module Monitors.Mem where  import Monitors.Common -import Data.IORef -  memConfig :: IO MConfig -memConfig =  -    do lc <- newIORef "#BFBFBF" -       l <- newIORef 300 -       nc <- newIORef "#00FF00" -       h <- newIORef 500 -       hc <- newIORef "#FF0000" -       t <- newIORef "Mem: <usedratio>% (<cache>M)" -       p <- newIORef package -       u <- newIORef "" -       a <- newIORef [] -       e <- newIORef ["total", "free", "buffer", "cache", "rest", "used", "usedratio"] -       return $ MC nc l lc h hc t p u a e +memConfig = newConfig +       "Mem: <usedratio>% (<cache>M)" -- template +       package                        -- package +       ""                             -- usage tail? +       []                             -- added args +       ["total", "free", "buffer",    -- available replacements +        "cache", "rest", "used", "usedratio"]  fileMEM :: IO String  fileMEM = readFile "/proc/meminfo" @@ -64,4 +57,4 @@ main :: IO ()  main =      do let af = runMem []         runMonitor monitorConfig af runMem --}
\ No newline at end of file +-} diff --git a/Monitors/Net.hs b/Monitors/Net.hs index addee47..646b15e 100644 --- a/Monitors/Net.hs +++ b/Monitors/Net.hs @@ -15,8 +15,6 @@  module Monitors.Net where  import Monitors.Common - -import Data.IORef  import Text.ParserCombinators.Parsec  data NetDev = NA @@ -29,18 +27,12 @@ interval :: Int  interval = 500000  netConfig :: IO MConfig -netConfig =  -    do lc <- newIORef "#BFBFBF" -       l <- newIORef 0 -       nc <- newIORef "#00FF00" -       h <- newIORef 32 -       hc <- newIORef "#FF0000" -       t <- newIORef "<dev>: <rx>|<tx>" -       p <- newIORef package -       u <- newIORef "dev" -       a <- newIORef [] -       e <- newIORef ["dev", "rx", "tx"] -       return $ MC nc l lc h hc t p u a e +netConfig = newConfig +    "<dev>: <rx>|<tx>"      -- template +    package                 -- package +    "dev"                   -- usage tail? +    []                      -- added args +    ["dev", "rx", "tx"]     -- available replacements  fileNET :: IO String  fileNET =  @@ -103,4 +95,4 @@ main :: IO ()  main =      do let f = return "No device specified"         runMonitor netConfig f runNet --}
\ No newline at end of file +-} diff --git a/Monitors/Swap.hs b/Monitors/Swap.hs index 7a69341..9fb6cc0 100644 --- a/Monitors/Swap.hs +++ b/Monitors/Swap.hs @@ -16,22 +16,15 @@ module Monitors.Swap where  import Monitors.Common -import Data.IORef  import qualified Data.ByteString.Lazy.Char8 as B  swapConfig :: IO MConfig -swapConfig =  -    do lc <- newIORef "#BFBFBF" -       l <- newIORef 30 -       nc <- newIORef "#00FF00" -       h <- newIORef 75 -       hc <- newIORef "#FF0000" -       t <- newIORef "Swap: <usedratio>%" -       p <- newIORef package -       u <- newIORef "" -       a <- newIORef [] -       e <- newIORef ["total", "used", "free", "usedratio"] -       return $ MC nc l lc h hc t p u a e +swapConfig = newConfig +        "Swap: <usedratio>"                    -- template +        package                                -- package +        ""                                     -- usage tail? +        []                                     -- added args +        ["total", "used", "free", "usedratio"] -- available replacements  fileMEM :: IO B.ByteString  fileMEM = B.readFile "/proc/meminfo" @@ -63,4 +56,4 @@ main :: IO ()  main =      do let af = runSwap []         runMonitor swapConfig af runSwap --}
\ No newline at end of file +-} diff --git a/Monitors/Weather.hs b/Monitors/Weather.hs index 63eb48e..885a9e2 100644 --- a/Monitors/Weather.hs +++ b/Monitors/Weather.hs @@ -16,8 +16,6 @@ module Monitors.Weather where  import Monitors.Common -import Data.IORef -  import System.Process  import System.Exit  import System.IO @@ -26,32 +24,26 @@ import Text.ParserCombinators.Parsec  weatherConfig :: IO MConfig -weatherConfig =  -    do lc <- newIORef "#BFBFBF" -       l <- newIORef 15 -       nc <- newIORef "#00FF00" -       h <- newIORef 27 -       hc <- newIORef "#FF0000" -       t <- newIORef "<station>: <tempC>C, rh <rh>% (<hour>)" -       p <- newIORef package -       u <- newIORef "station ID" -       a <- newIORef [] -       e <- newIORef ["station" -                     , "stationState" -                     , "year" -                     , "month" -                     , "day" -                     , "hour" -                     , "wind" -                     , "visibility" -                     , "skyCondition" -                     , "tempC" -                     , "tempF" -                     , "dewPoint" -                     , "rh" -                     ,"pressure" -                     ] -       return $ MC nc l lc h hc t p u a e +weatherConfig = newConfig +       "<station>: <tempC>C, rh <rh>% (<hour>)" -- template +       package                                  -- package +       "station ID"                             -- usage tail? +       []                                       -- added args +       ["station"                               -- available replacements +       , "stationState" +       , "year" +       , "month" +       , "day" +       , "hour" +       , "wind" +       , "visibility" +       , "skyCondition" +       , "tempC" +       , "tempF" +       , "dewPoint" +       , "rh" +       ,"pressure" +       ]  data WeatherInfo =      WI { stationPlace :: String @@ -149,4 +141,4 @@ main :: IO ()  main =      do let af = return "No station ID specified"         runMonitor weatherConfig af runWeather --}
\ No newline at end of file +-} | 
