@@ -13,7 +13,12 @@ module StackTest.Repl
13
13
import Control.Exception (SomeException , catch , displayException , finally )
14
14
import Control.Monad (unless , when )
15
15
import Control.Monad.IO.Class (liftIO )
16
+ import Control.Monad.Trans (lift )
17
+ import Control.Monad.Trans.Reader
18
+ import Control.Monad.Trans.State qualified as State
16
19
import Data.Maybe (fromMaybe )
20
+ import Data.Foldable (toList )
21
+ import Data.Sequence as Seq (Seq (Empty ), (|>) , fromList )
17
22
import GHC.Stack (HasCallStack )
18
23
import System.Directory (removeFile )
19
24
import System.Environment (lookupEnv )
@@ -24,10 +29,6 @@ import System.IO
24
29
, openTempFile
25
30
, withFile
26
31
)
27
-
28
- import Control.Monad.Trans (lift )
29
- import Control.Monad.Trans.Reader
30
- import Control.Monad.Trans.State qualified as State
31
32
import System.Process
32
33
( CreateProcess (std_err , std_in , std_out )
33
34
, StdStream (CreatePipe , UseHandle )
@@ -54,15 +55,15 @@ replGetLine :: Repl String
54
55
replGetLine = ask >>= liftIO . hGetLine . replStdout
55
56
56
57
nextPrompt :: Repl ()
57
- nextPrompt = State. evalStateT poll " " where
58
+ nextPrompt = State. evalStateT poll Seq. Empty where
58
59
poll = do
59
60
c <- lift (asks replStdout) >>= liftIO . hGetChar
60
- State. modify (++ [c]) -- FIXME crap perf
61
+ State. modify (|> c)
61
62
when (c == ' \n ' ) $ do
62
- State. get >>= liftIO . putStr . (" ghci> " <> )
63
- State. put " "
63
+ State. get >>= liftIO . putStr . (" ghci> " ++ ) . toList
64
+ State. put Seq. Empty
64
65
buf <- State. get
65
- unless (buf == " ghci> " )
66
+ unless (buf == Seq. fromList " ghci> " )
66
67
poll
67
68
68
69
runRepl
0 commit comments