Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ef725f0
add redirect
jw3126 Oct 10, 2020
8c97e4b
fix
jw3126 Oct 10, 2020
4a02778
fix redirect: better handling of duplicate paths
jw3126 Oct 13, 2020
05a074e
fix redirect tests
jw3126 Oct 13, 2020
102e88f
add redirect to NEWS.md
jw3126 Oct 15, 2020
689fba0
Document redirect edge cases
jw3126 Oct 15, 2020
fc89b11
improve redirect docs
jw3126 Oct 15, 2020
8ed4949
minor cosmetic change
jw3126 Oct 22, 2020
98917f1
Update base/stream.jl
jw3126 Oct 24, 2020
5473a90
Update stream.jl
jw3126 Oct 24, 2020
9b9404b
Merge branch 'master' into redirect
jw3126 Nov 1, 2020
7f9bd68
Merge branch 'redirect' of github.com:jw3126/julia into redirect
jw3126 Nov 1, 2020
ff52480
Merge branch 'master' into redirect
jw3126 Nov 26, 2020
6793348
Merge branch 'master' of https://github.com/JuliaLang/julia into redi…
jw3126 Nov 26, 2020
ad97dbd
Merge branch 'master' into redirect
jw3126 Apr 23, 2021
0c3315e
fix some docstrings
jw3126 Apr 23, 2021
f213be6
Update base/stream.jl
jw3126 Apr 23, 2021
ff60dee
add a compat note to redirect
jw3126 Apr 23, 2021
c0046eb
Merge branch 'master' of https://github.com/JuliaLang/julia into redi…
jw3126 May 13, 2021
137bd60
rename redirect -> redirect_stdio
jw3126 May 13, 2021
9a82412
fix doc
jw3126 May 13, 2021
c204a35
fix redirect_stdio NEWS.md
jw3126 May 13, 2021
96c6be6
fix
jw3126 May 13, 2021
1ab7904
Update base/stream.jl
jw3126 May 25, 2021
f4eaf68
Merge branch 'master' into redirect
jw3126 May 25, 2021
c455d5c
Merge branch 'redirect' of github.com:jw3126/julia into redirect
jw3126 May 25, 2021
c7d125f
fix
jw3126 May 25, 2021
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
Prev Previous commit
Next Next commit
Merge branch 'master' into redirect
  • Loading branch information
jw3126 committed Apr 23, 2021
commit ad97dbd1b034e478775a4334ce22db9d4ab5eafb
18 changes: 7 additions & 11 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,14 @@ Build system changes
New library functions
---------------------

* New function `Base.kron!` and corresponding overloads for various matrix types for performing Kronecker product in-place ([#31069]).
* New function `Base.Threads.foreach(f, channel::Channel)` for multithreaded `Channel` consumption ([#34543]).
* New function `Base.readeach(io, T)` for iteratively performing `read(io, T)` ([#36150]).
* `Iterators.map` is added. It provides another syntax `Iterators.map(f, iterators...)`
for writing `(f(args...) for args in zip(iterators...))`, i.e. a lazy `map` ([#34352]).
* New function `sincospi` for simultaneously computing `sinpi(x)` and `cospi(x)` more
efficiently ([#35816]).
* New function `addenv` for adding environment mappings into a `Cmd` object, returning the new `Cmd` object.
* New function `insorted` for determining whether an element is in a sorted collection or not ([#37490]).
* Two argument methods `findmax(f, domain)`, `argmax(f, domain)` and the corresponding `min` versions ([#27613]).
* `isunordered(x)` returns true if `x` is value that is normally unordered, such as `NaN` or `missing`.
* New macro `Base.@invokelatest f(args...; kwargs...)` provides a convenient way to call `Base.invokelatest(f, args...; kwargs...)` ([#37971])
* New macro `Base.@invoke f(arg1::T1, arg2::T2; kwargs...)` provides an easier syntax to call `invoke(f, Tuple{T1,T2}; kwargs...)` ([#38438])
* Two arguments method `lock(f, lck)` now accepts a `Channel` as the second argument. ([#39312])
* New functor `Returns(value)`, which returns `value` for any arguments ([#39794])
* New macro `Base.@invoke f(arg1::T1, arg2::T2; kwargs...)` provides an easier syntax to call `invoke(f, Tuple{T1,T2}, arg1, arg2; kwargs...)` ([#38438])
* New function `redirect` for redirecting `stdin`, `stdout` and `stderr` ([#37978]).
* New function `Base.rest` for taking the rest of a collection, starting from a specific
iteration state, in a generic way ([#37410]).

New library features
--------------------
Expand Down
44 changes: 22 additions & 22 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,8 @@ the pipe.
!!! note
`stream` must be a compatible objects, such as an `IOStream`, `TTY`,
`Pipe`, socket, or `devnull`.

See also [`redirect`](@ref).
"""
redirect_stdout

Expand All @@ -1215,6 +1217,8 @@ Like [`redirect_stdout`](@ref), but for [`stderr`](@ref).
!!! note
`stream` must be a compatible objects, such as an `IOStream`, `TTY`,
`Pipe`, socket, or `devnull`.

See also [`redirect`](@ref).
"""
redirect_stderr

Expand All @@ -1227,10 +1231,11 @@ Note that the direction of the stream is reversed.
!!! note
`stream` must be a compatible objects, such as an `IOStream`, `TTY`,
`Pipe`, socket, or `devnull`.

See also [`redirect`](@ref).
"""
redirect_stdin


"""
redirect(;stdin=stdin, stderr=stderr, stdout=stdout)

Expand Down Expand Up @@ -1338,48 +1343,43 @@ function redirect(f; stdin=nothing, stderr=nothing, stdout=nothing)
end
end

redirect_stderr(f::Function, stream) = redirect(f, stderr=stream)
redirect_stdin(f::Function, stream) = redirect(f, stdin=stream)
redirect_stdout(f::Function, stream) = redirect(f, stdout=stream)
function (f::redirect_stdio)(thunk::Function, stream)
stdold = f.unix_fd == 0 ? stdin :
f.unix_fd == 1 ? stdout :
f.unix_fd == 2 ? stderr :
throw(ArgumentError("Not implemented to get old handle of fd except for stdio"))
f(stream)
try
return thunk()
finally
f(stdold)
end
end


"""
redirect_stdout(f::Function, stream)

Run the function `f` while redirecting [`stdout`](@ref) to `stream`.
Upon completion, [`stdout`](@ref) is restored to its prior setting.

!!! note
`stream` must be a `TTY`, a `Pipe`, or a socket.

See also [`redirect`](@ref).
"""
redirect_stdout(f::Function, stream)
redirect_stdout

"""
redirect_stderr(f::Function, stream)

Run the function `f` while redirecting [`stderr`](@ref) to `stream`.
Upon completion, [`stderr`](@ref) is restored to its prior setting.

!!! note
`stream` must be a `TTY`, a `Pipe`, or a socket.

See also [`redirect`](@ref).
"""
redirect_stderr(f::Function, stream)
redirect_stderr

"""
redirect_stdin(f::Function, stream)

Run the function `f` while redirecting [`stdin`](@ref) to `stream`.
Upon completion, [`stdin`](@ref) is restored to its prior setting.

!!! note
`stream` must be a `TTY`, a `Pipe`, or a socket.

See also [`redirect`](@ref).
"""
redirect_stdin(f::Function, stream)
redirect_stdin

mark(x::LibuvStream) = mark(x.buffer)
unmark(x::LibuvStream) = unmark(x.buffer)
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.