module Role.Watcher where import Types import Log import Pty import CmdLine import SessionID import Role.Developer import Control.Concurrent.STM import Control.Concurrent.STM.TMChan import Data.Time.Clock.POSIX run :: WatchOpts -> IO () run = run' watcher . watchUrl watcher :: TMVar (TVar DeveloperState) -> TMChan (Message Entered) -> TMChan AnyMessage -> SessionID -> IO () watcher dsv _ichan ochan _ = inRawMode $ do (st, startoutput) <- processSessionStart ochan nullLogger dsv emitOutput startoutput go st where go st = do ts <- getPOSIXTime v <- atomically $ getServerMessage ochan st ts case v of Nothing -> return () Just (o, _msg) -> do emitOutput o go st