blob: fcbfc253eb9e44801fbd59ea4fe5beb7369fd0e4 (
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
{- Copyright 2017 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
module Replay where
import Types
import Log
import CmdLine
import Pty
import qualified Data.ByteString as B
import System.IO
import Control.Concurrent.Async
import Control.Concurrent.Thread.Delay
replay :: ReplayOpts -> IO ()
replay opts = do
hSetBuffering stdin NoBuffering
withoutEcho $ go =<< streamLog (replayLogFile opts)
where
go [] = return ()
go (Right l:ls) = do
case loggedMessage l of
User (ActivityMessage a) -> do
_ <- realisticDelay (elapsedTime a)
`race` waitSpaceBar
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
waitSpaceBar :: IO ()
waitSpaceBar = do
c <- getChar
if c == ' '
then return ()
else waitSpaceBar
|