diff --git a/NEWS.md b/NEWS.md index 6e8c8402e8fded..b9295e6c9c48de 100644 --- a/NEWS.md +++ b/NEWS.md @@ -57,6 +57,7 @@ New library functions New library features -------------------- +* The `redirect_*` functions can now be called on `IOContext` objects. Standard library changes ------------------------ diff --git a/base/stream.jl b/base/stream.jl index 93614b21a24382..b0864409d7ea25 100644 --- a/base/stream.jl +++ b/base/stream.jl @@ -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 diff --git a/test/spawn.jl b/test/spawn.jl index 8a73394d8ae476..d7b685eaf32c1f 100644 --- a/test/spawn.jl +++ b/test/spawn.jl @@ -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