@@ -161,6 +161,7 @@ type Msg
161
161
| CompiledForRun { path : String, exitCode : Int }
162
162
| RunStarted { processId : Process.Id, streams : ChildProcess.StreamIO }
163
163
| RunExited Int
164
+ | RedirectTerminalIO (Result Stream.Error { source : Stream.Readable Bytes, target : Stream.Writable Bytes })
164
165
165
166
166
167
port completeStaticBuild : String -> Cmd msg
@@ -235,36 +236,18 @@ update msg model =
235
236
parseUserArgs model compilerPath
236
237
237
238
CompilerInitialized { backendStreams, encodedCommand, quiet } ->
238
- -- TODO: prompts from the backend no longer works, which will probably block the repl
239
- Stream.write encodedCommand backendStreams.input
240
- |> Task.andThen (\_ -> Stream.closeWritable backendStreams.input)
241
- |> Task.onError
242
- (\streamErr ->
243
- Stream.Log.line model.stderr ("Failed to send command to compiler backend due to error: " ++ Stream.errorToString streamErr)
244
- )
245
- |> Task.andThen
246
- (\_ ->
247
- if quiet then
248
- Task.succeed model.stdout
249
- else
250
- backendStreams.output
251
- |> Stream.awaitAndPipeThrough Stream.textDecoder
252
- |> Task.andThen Stream.Extra.consumeString
253
- |> Task.andThen (\str -> Stream.writeStringAsBytes str model.stdout)
254
- )
255
- |> Task.andThen
256
- (\_ ->
257
- backendStreams.error
258
- |> Stream.awaitAndPipeThrough Stream.textDecoder
259
- |> Task.andThen Stream.Extra.consumeString
260
- |> Task.andThen (\str -> Stream.writeStringAsBytes str model.stderr)
261
- )
262
- |> Task.map (\_ -> {})
263
- |> Task.onError
264
- (\streamErr ->
265
- Stream.Log.line model.stderr ("Something went wrong when reading from backend: " ++ Stream.errorToString streamErr)
266
- )
267
- |> Task.execute
239
+ Cmd.batch
240
+ [ Stream.write encodedCommand backendStreams.input
241
+ |> Task.map (\_ -> { source = model.stdin, target = backendStreams.input })
242
+ |> Task.attempt RedirectTerminalIO
243
+ , if quiet then
244
+ Cmd.none
245
+ else
246
+ Task.succeed { source = backendStreams.output, target = model.stdout }
247
+ |> Task.attempt RedirectTerminalIO
248
+ , Task.succeed { source = backendStreams.error, target = model.stderr }
249
+ |> Task.attempt RedirectTerminalIO
250
+ ]
268
251
269
252
CompilerRan exitCode ->
270
253
Node.exitWithCode exitCode
@@ -293,6 +276,16 @@ update msg model =
293
276
294
277
RunExited exitCode ->
295
278
Node.exitWithCode exitCode
279
+
280
+ RedirectTerminalIO (Ok streams) ->
281
+ Stream.read streams.source
282
+ |> Task.andThen (\str -> Stream.write str streams.target)
283
+ |> Task.map (\_ -> streams)
284
+ |> Task.attempt RedirectTerminalIO
285
+
286
+ RedirectTerminalIO (Err err) ->
287
+ Stream.Log.line model.stderr ("Something went wrong when communicating with compiler backend: " ++ Stream.errorToString err)
288
+ |> Task.execute
296
289
}
297
290
298
291
0 commit comments