mosaic icon indicating copy to clipboard operation
mosaic copied to clipboard

Intercept stdout so rogue `println`s still work correctly

Open JakeWharton opened this issue 10 months ago • 3 comments

JakeWharton avatar Feb 06 '25 03:02 JakeWharton

I think we'll do this as part of raw mode, since that will screw up your trailing newlines on a println anyway (you need a full CRLF).

On JVM we capture stdout and replace with our own thing. Flip back on close.

On native POSIX I think we can do a freopen to a pipe that we also read. Not quite sure how to flip back.

On native Windows we can SetStdHandle to an anonymous pipe. Flip back on close.

JakeWharton avatar Feb 07 '25 19:02 JakeWharton

Probably blocked on doing this until we fix #508 since reads from these will need to flow into static logs.

JakeWharton avatar Feb 07 '25 20:02 JakeWharton

What happens when you write hello\nworld (note the lack of trailing newline)? Do we output "hello\n" and then just wait for a newline before writing "world\n" some frame later?

JakeWharton avatar Mar 04 '25 18:03 JakeWharton

Answer: yes. JVM can do this sometimes, as newline causes a flush. Also not worth optimizing for anyway.

JakeWharton avatar Sep 09 '25 02:09 JakeWharton