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

import Types
import Log
import Pty
import CmdLine
import WebSockets
import SessionID

import Control.Concurrent.STM
import qualified Data.Text as T
import Role.Developer (processSessionStart, getUserMessage, Output(..), emitOutput)

run :: WatchOpts -> IO ()
run os = runClientApp $ clientApp (ConnectMode (T.pack (watchUrl os))) watcher

watcher :: TChan (Message Entered) -> TChan (Message Seen) -> SessionID -> IO ()
watcher _ichan ochan sid = inRawMode $ do
	st <- processSessionStart ochan nullLogger
	go st
  where
	go st = do
		(o, _msg) <- atomically $ getUserMessage ochan st
		emitOutput o
		go st