Skip to content

Commit d87b7ed

Browse files
committed
Don't redirect stdin when running headless.
Fixes #341
1 parent b54f034 commit d87b7ed

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

src/Main.gren

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ 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
@@ -257,19 +257,29 @@ update msg model =
257257
CompilerInstalled (Ok compilerPath) ->
258258
parseUserArgs model compilerPath
259259

260-
CompilerInitialized { backendStreams, encodedCommand, quiet } ->
260+
CompilerInitialized { backendStreams, encodedCommand, headless } ->
261261
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
262+
[ if headless then
263+
Stream.write encodedCommand backendStreams.input
264+
|> Task.map (\_ -> {})
265+
|> Task.onError
266+
(\e ->
267+
Stream.Log.line model.stderr (Stream.errorToString e)
268+
|> Task.andThen (\_ -> Node.exitWithCode 1)
269+
)
270+
|> Task.execute
271+
else
272+
Stream.write encodedCommand backendStreams.input
273+
|> Task.map (\_ -> { source = model.stdin, target = backendStreams.input })
274+
|> Task.mapError
275+
(\err ->
276+
{ error = err
277+
, source = model.stdin
278+
, target = backendStreams.input
279+
}
280+
)
281+
|> Task.attempt RedirectTerminalIO
282+
, if headless then
273283
Cmd.none
274284
else
275285
Task.succeed { source = backendStreams.output, target = model.stdout }
@@ -288,7 +298,7 @@ update msg model =
288298
, fsPermission = model.fsPermission
289299
, pathToString = model.pathToString
290300
, path = path
291-
, onInit = \{ processId } -> RunStarted processId
301+
, onInit = RunStarted
292302
, onExit = RunExited
293303
}
294304
|> Task.onError
@@ -391,7 +401,7 @@ parseUserArgs model compilerPath =
391401
Just streams ->
392402
CompilerInitialized
393403
{ backendStreams = streams
394-
, quiet = False
404+
, headless = False
395405
, encodedCommand =
396406
Compiler.Backend.encodeCommand
397407
{ interactiveSession = model.interactive
@@ -544,7 +554,7 @@ parseUserArgs model compilerPath =
544554
CompilerInitialized
545555
{ backendStreams = streams
546556
, encodedCommand = encodedCommand
547-
, quiet = True
557+
, headless = True
548558
}
549559
)
550560
, 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)