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

allow redirecting standard streams to IOContext #36688

Merged
merged 1 commit into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ New library functions
New library features
--------------------

* The `redirect_*` functions can now be called on `IOContext` objects.

Standard library changes
------------------------
Expand Down
6 changes: 6 additions & 0 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,12 @@ for (x, writable, unix_fd, c_symbol) in
$x = devnull
return devnull
end
function ($f)(io::IOContext)
io2, _dict = unwrapcontext(io)
($f)(io2)
global $x = io
return io
end
end
end

Expand Down
5 changes: 5 additions & 0 deletions test/spawn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ end
@test "Hello World\n" == read(fname, String)
@test OLD_STDOUT === stdout
rm(fname)

col = get(stdout, :color, false)
redirect_stdout(IOContext(stdout, :color=>!col))
@test get(stdout, :color, col) == !col
redirect_stdout(OLD_STDOUT)
end
end

Expand Down