diff --git a/Project.toml b/Project.toml index 8e4f4ac..5226f4c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "TeeStreams" uuid = "c24d529b-c83e-40e0-9fc3-05832c05a0ba" -version = "1.1.0" +version = "1.1.1" [compat] julia = "1.5" diff --git a/src/TeeStreams.jl b/src/TeeStreams.jl index b450aa9..7118502 100644 --- a/src/TeeStreams.jl +++ b/src/TeeStreams.jl @@ -122,12 +122,23 @@ end # Adapted from Logging2.jl (MIT License: Copyright (c) 2020 Chris Foster) # https://github.com/JuliaLogging/Logging2.jl/blob/094eb6619aeaa8815585dbe7f33b4972f9a4ce6b/src/Logging2.jl#L12-L37 -function (redirect_func::Base.RedirectStdStream)(f::Function, io::TeeStream) - prev_stream = - redirect_func.unix_fd == 1 ? stdout : - redirect_func.unix_fd == 2 ? stderr : - throw(ArgumentError("Can only redirect stdout and stderr to TeeStream.")) +if VERSION >= v"1.7.0-DEV.254" + function (redirect_func::Base.RedirectStdStream)(f::Function, io::TeeStream) + prev_stream = + redirect_func.unix_fd == 1 ? stdout : + redirect_func.unix_fd == 2 ? stderr : + throw(ArgumentError("Can only redirect stdout and stderr to TeeStream.")) + return _redirect_internal(f, io, redirect_func, prev_stream) + end +else + Base.redirect_stdout(f::Function, io::TeeStream) = + _redirect_internal(f, io, redirect_stdout, stdout) + Base.redirect_stderr(f::Function, io::TeeStream) = + _redirect_internal(f, io, redirect_stderr, stderr) +end + +function _redirect_internal(f, io, redirect_func, prev_stream) result = nothing rd, rw = redirect_func()