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 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) | n < 1 = return () | otherwise = delay $ ceiling $ n * 1000000