Skip to content

Commit 4e1934f

Browse files
committed
WIP fix for handling stdin with gren run
1 parent b54f034 commit 4e1934f

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/Main.gren

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ type Msg
173173
| CompilerInitialized { quiet : Bool, backendStreams : ChildProcess.StreamIO, encodedCommand : Bytes }
174174
| CompilerRan Int
175175
| CompiledForRun { path : Path, exitCode : Int }
176-
| RunStarted Process.Id
176+
| RunStarted { processId : Process.Id, streams : Maybe ChildProcess.StreamIO }
177177
| RunExited Int
178178
| RedirectTerminalIO
179179
(Result
@@ -288,7 +288,7 @@ update msg model =
288288
, fsPermission = model.fsPermission
289289
, pathToString = model.pathToString
290290
, path = path
291-
, onInit = \{ processId } -> RunStarted processId
291+
, onInit = RunStarted
292292
, onExit = RunExited
293293
}
294294
|> Task.onError
@@ -303,8 +303,18 @@ update msg model =
303303
else
304304
Task.execute <| Node.exitWithCode exitCode
305305

306-
RunStarted _ ->
307-
Cmd.none
306+
RunStarted { streams } ->
307+
when streams is
308+
Nothing ->
309+
Debug.todo "Handle missing streams on run"
310+
311+
Just { input, output, error } ->
312+
[ Task.succeed { source = output, target = model.stdout }
313+
, Task.succeed { source = model.stdin, target = input }
314+
, Task.succeed { source = error, target = model.stderr }
315+
]
316+
|> Array.map (Task.attempt RedirectTerminalIO)
317+
|> Cmd.batch
308318

309319
RunExited exitCode ->
310320
Task.execute <| Node.exitWithCode exitCode
@@ -328,6 +338,7 @@ update msg model =
328338
Cmd.none
329339

330340
_ ->
341+
-- TODO: This is no longer only used for comms with the compiler backend. Need better error message.
331342
Stream.Log.line model.stderr ("Something went wrong when communicating with compiler backend: " ++ Stream.errorToString error)
332343
|> Task.andThen (\_ -> Node.exitWithCode 1)
333344
|> Task.execute

src/Terminal/Run.gren

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ run config =
208208

209209
runWith command =
210210
ChildProcess.defaultSpawnOptions config.onInit config.onExit
211+
|> (\opts -> { opts | connection = ChildProcess.External })
211212
|> ChildProcess.spawn config.cpPermission command [ path ]
212213
|> Task.succeed
213214
in

0 commit comments

Comments
 (0)