diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/Monitors.hs | 33 | 
1 files changed, 33 insertions, 0 deletions
diff --git a/src/lib/Monitors.hs b/src/lib/Monitors.hs index 15900e5..fb51893 100644 --- a/src/lib/Monitors.hs +++ b/src/lib/Monitors.hs @@ -2,6 +2,39 @@ module Monitors where  import Xmobar  import Config +import Control.Concurrent +import Control.Concurrent.Async (async) +import Control.Concurrent.STM + +data CombinedMonitor a b = CombinedMonitor a b (String -> String -> String) + +instance (Show a, Show b) => Show (CombinedMonitor a b) where +  show (CombinedMonitor a b _) = "Alt (" ++ show a ++ ") (" ++ show b ++ ")" + +instance (Read a, Read b) => Read (CombinedMonitor a b) where +  readsPrec _ = undefined + +instance (Exec a, Exec b) => Exec (CombinedMonitor a b) where +  alias (CombinedMonitor a b _) = (alias a) ++ "_" ++ (alias b) +  rate (CombinedMonitor a b _) = min (rate a) (rate b) +  start (CombinedMonitor a b comb) cb +    = startMonitors a b (\s t -> cb $ comb s t) + +startMonitors a b cmb =  do +    sta <- atomically $ newTVar "" +    stb <- atomically $ newTVar "" +    _ <- async $ start a (\x -> atomically $ writeTVar sta x) +    _ <- async $ start b (\x -> atomically $ writeTVar stb x) +    go sta stb cmb +      where go sta' stb' cmb' = do +              s <- atomically $ readTVar sta' +              t <- atomically $ readTVar stb' +              cmb' s t +              tenthSeconds $ min (rate b) (rate a) +              go sta' stb' cmb' + +altMonitor a b = CombinedMonitor a b (\s t -> if null s then t else s) +concatMonitor sep a b = CombinedMonitor a b (\s t -> s ++ sep ++ t)  topProc p = TopProc (p <~> ["-t" , "<mboth3>  <mboth2>  <mboth1> \                                     \ยท <both3>  <both2>  <both1>"  | 
