summaryrefslogtreecommitdiffhomepage
path: root/Role/Watcher.hs
blob: a4328f84f9634488c0933328f2874ed7008eac05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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