Skip to content

Commit 0bd3975

Browse files
authored
Merge pull request #348 from gren-lang/run-stdin-fix
2 parents b918d17 + e1b4334 commit 0bd3975

File tree

2 files changed

+23
-29
lines changed

2 files changed

+23
-29
lines changed

src/Main.gren

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,14 @@ type Msg
170170
, downloadResult : Result (HttpClient.Error Bytes) (HttpClient.Response Bytes)
171171
}
172172
| CompilerInstalled (Result FileSystem.Error Path)
173-
| CompilerInitialized { quiet : Bool, backendStreams : ChildProcess.StreamIO, encodedCommand : Bytes }
173+
| CompilerInitialized { headless : 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
180-
{ error : Stream.Error
181-
, source : Stream.Readable Bytes
182-
, target : Stream.Writable Bytes
183-
}
180+
Stream.Error
184181
{ source : Stream.Readable Bytes
185182
, target : Stream.Writable Bytes
186183
}
@@ -257,19 +254,22 @@ update msg model =
257254
CompilerInstalled (Ok compilerPath) ->
258255
parseUserArgs model compilerPath
259256

260-
CompilerInitialized { backendStreams, encodedCommand, quiet } ->
257+
CompilerInitialized { backendStreams, encodedCommand, headless } ->
261258
Cmd.batch
262-
[ Stream.write encodedCommand backendStreams.input
263-
|> Task.map (\_ -> { source = model.stdin, target = backendStreams.input })
264-
|> Task.mapError
265-
(\err ->
266-
{ error = err
267-
, source = model.stdin
268-
, target = backendStreams.input
269-
}
270-
)
271-
|> Task.attempt RedirectTerminalIO
272-
, if quiet then
259+
[ if headless then
260+
Stream.write encodedCommand backendStreams.input
261+
|> Task.map (\_ -> {})
262+
|> Task.onError
263+
(\e ->
264+
Stream.Log.line model.stderr (Stream.errorToString e)
265+
|> Task.andThen (\_ -> Node.exitWithCode 1)
266+
)
267+
|> Task.execute
268+
else
269+
Stream.write encodedCommand backendStreams.input
270+
|> Task.map (\_ -> { source = model.stdin, target = backendStreams.input })
271+
|> Task.attempt RedirectTerminalIO
272+
, if headless then
273273
Cmd.none
274274
else
275275
Task.succeed { source = backendStreams.output, target = model.stdout }
@@ -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
@@ -313,16 +313,9 @@ update msg model =
313313
Stream.read streams.source
314314
|> Task.andThen (\str -> Stream.write str streams.target)
315315
|> Task.map (\_ -> streams)
316-
|> Task.mapError
317-
(\err ->
318-
{ error = err
319-
, source = streams.source
320-
, target = streams.target
321-
}
322-
)
323316
|> Task.attempt RedirectTerminalIO
324317

325-
RedirectTerminalIO (Err { error, source, target }) ->
318+
RedirectTerminalIO (Err error) ->
326319
when error is
327320
Stream.Closed ->
328321
Cmd.none
@@ -391,7 +384,7 @@ parseUserArgs model compilerPath =
391384
Just streams ->
392385
CompilerInitialized
393386
{ backendStreams = streams
394-
, quiet = False
387+
, headless = False
395388
, encodedCommand =
396389
Compiler.Backend.encodeCommand
397390
{ interactiveSession = model.interactive
@@ -544,7 +537,7 @@ parseUserArgs model compilerPath =
544537
CompilerInitialized
545538
{ backendStreams = streams
546539
, encodedCommand = encodedCommand
547-
, quiet = True
540+
, headless = True
548541
}
549542
)
550543
, onCompiled =

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.Integrated })
211212
|> ChildProcess.spawn config.cpPermission command [ path ]
212213
|> Task.succeed
213214
in

0 commit comments

Comments
 (0)