summaryrefslogtreecommitdiffhomepage
path: root/Role/Watcher.hs
blob: c13234f127a4558e06d8cf7629ca75f0dfb897c1 (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
module Role.Watcher where

import Types
import Log
import Pty
import CmdLine
import SessionID

import Control.Concurrent.STM
import Control.Concurrent.STM.TMChan
import Role.Developer (run', processSessionStart, getServerMessage, emitOutput)

run :: WatchOpts -> IO ()
run = run' watcher . watchUrl

watcher :: TMChan (Message Entered) -> TMChan LogMessage -> SessionID -> IO ()
watcher _ichan ochan _ = inRawMode $ do
	(st, startoutput) <- processSessionStart ochan nullLogger
	emitOutput startoutput
	go st
  where
	go st = do
		v <- atomically $ getServerMessage ochan st
		case v of
			Nothing -> return ()
			Just (o, _msg) -> do
				emitOutput o
				go st