summaryrefslogtreecommitdiffhomepage
path: root/Replay.hs
blob: 8d2e3ae355d01266996c96674731e0e757ac4c6d (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
module Replay where

import Types
import Log
import CmdLine

import qualified Data.ByteString as B
import System.IO
import Control.Concurrent.Thread.Delay

replay :: ReplayOpts -> IO ()
replay opts = go =<< streamLog (replayLogFile opts)
  where
	go [] = return ()
	go (Right l:ls) = do
		case loggedMessage l of
			User (ActivityMessage a) -> do
				maybe (return ()) realisticDelay (elapsedTime a)
				B.hPut stdout $ val $ seenData $ activity a
				hFlush stdout
			User (ControlMessage _) -> return ()
			Developer _ -> return ()
		go ls
	go (Left l:_) = error $ "Failed to parse a line of the log: " ++ l

realisticDelay :: ElapsedTime -> IO ()
realisticDelay (ElapsedTime n) = delay $ ceiling $ n * 1000000