Skip to content
Snippets Groups Projects
Commit c83d79ee authored by Jens Nolte's avatar Jens Nolte
Browse files

Move pipeBlock below runPipeClient

parent 0e7c426b
No related branches found
No related tags found
No related merge requests found
...@@ -16,19 +16,19 @@ import System.IO ...@@ -16,19 +16,19 @@ import System.IO
runPipeClient :: Bool -> MainOptions -> IO () runPipeClient :: Bool -> MainOptions -> IO ()
runPipeClient enableEvents mainOptions = do runPipeClient enableEvents mainOptions = do
(output, input) <- spawn unbounded (output, input) <- spawn unbounded
hostTask <- async $ sendBlockStream (addBlock $ pipeBlock enableEvents $ fromInput input) mainOptions hostTask <- async $ sendBlockStream (addBlock $ pipeBlock $ fromInput input) mainOptions
inputTask <- async $ runEffect $ PP.stdinLn >-> toOutput output inputTask <- async $ runEffect $ PP.stdinLn >-> toOutput output
void $ waitEitherCancel hostTask inputTask void $ waitEitherCancel hostTask inputTask
-- |Special block that reads the processes stdin line-by-line and shows the latest line in the block. Must never be used in a 'server' process or when stdin/stdout is used in another way.
pipeBlock :: Bool -> Producer String BarIO () -> PushBlock
pipeBlock enableEvents source = PushMode <$ source >-> PP.map stringToState
where where
stringToState :: String -> BlockState -- |Special block that reads the processes stdin line-by-line and shows the latest line in the block. Must never be used in a 'server' process or when stdin/stdout is used in another way.
stringToState = attachHandler . mkBlockOutput . normalText . T.pack pipeBlock :: Producer String BarIO () -> PushBlock
attachHandler :: BlockOutput -> BlockState pipeBlock source = PushMode <$ source >-> PP.map stringToState
attachHandler = if enableEvents then mkBlockState' pipeBlockName handler else mkBlockState where
handler :: BlockEventHandler stringToState :: String -> BlockState
handler event = liftIO $ BSC.hPutStrLn stderr $ encode event stringToState = attachHandler . mkBlockOutput . normalText . T.pack
pipeBlockName :: Text attachHandler :: BlockOutput -> BlockState
pipeBlockName = "pipe" attachHandler = if enableEvents then mkBlockState' pipeBlockName handler else mkBlockState
handler :: BlockEventHandler
handler event = liftIO $ BSC.hPutStrLn stderr $ encode event
pipeBlockName :: Text
pipeBlockName = "pipe"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment