Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ScalaModule#console by properly inheriting streams #3500

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions main/api/src/mill/api/SystemStreams.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,32 @@ object SystemStreams {
val out = System.out
val err = System.err
try {
// If we are setting a stream back to its original value, make sure we reset
// `os.Inherit` to `os.InheritRaw` for that stream. This direct inheritance
// ensures that interactive applications involving console IO work, as the
// presence of a `PumpedProcess` would cause most interactive CLIs (e.g.
// scala console, REPL, etc.) to misbehave
val inheritIn =
if (systemStreams.in eq original.in) os.InheritRaw
else new PumpedProcessInput

val inheritOut =
if (systemStreams.out eq original.out) os.InheritRaw
else new PumpedProcessOutput(systemStreams.out)

val inheritErr =
if (systemStreams.err eq original.err) os.InheritRaw
else new PumpedProcessOutput(systemStreams.err)

System.setIn(systemStreams.in)
System.setOut(systemStreams.out)
System.setErr(systemStreams.err)
Console.withIn(systemStreams.in) {
Console.withOut(systemStreams.out) {
Console.withErr(systemStreams.err) {
os.Inherit.in.withValue(new PumpedProcessInput) {
os.Inherit.out.withValue(new PumpedProcessOutput(System.out)) {
os.Inherit.err.withValue(new PumpedProcessOutput(System.err)) {
os.Inherit.in.withValue(inheritIn) {
os.Inherit.out.withValue(inheritOut) {
os.Inherit.err.withValue(inheritErr) {
t
}
}
Expand Down
Loading