Skip to content

Commit

Permalink
allow redirecting standard streams to IOContext (#36688)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Jul 16, 2020
1 parent 81d34c5 commit ad4b1ec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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

2 comments on commit ad4b1ec

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.