diff --git a/stdlib/REPL/src/TerminalMenus/AbstractMenu.jl b/stdlib/REPL/src/TerminalMenus/AbstractMenu.jl index a1f94852b38ec..ddcfc111cf962 100644 --- a/stdlib/REPL/src/TerminalMenus/AbstractMenu.jl +++ b/stdlib/REPL/src/TerminalMenus/AbstractMenu.jl @@ -176,7 +176,7 @@ Returns `selected(m)`. !!! compat "Julia 1.6" The `cursor` argument requires Julia 1.6 or later. """ -request(m::AbstractMenu; kwargs...) = request(terminal, m; kwargs...) +request(m::AbstractMenu; kwargs...) = request(default_terminal(), m; kwargs...) function request(term::REPL.Terminals.TTYTerminal, m::AbstractMenu; cursor::Union{Int, Base.RefValue{Int}}=1, suppress_output=false) if cursor isa Int @@ -252,7 +252,7 @@ end Shorthand for `println(msg); request(m)`. """ -request(msg::AbstractString, m::AbstractMenu; kwargs...) = request(terminal, msg, m; kwargs...) +request(msg::AbstractString, m::AbstractMenu; kwargs...) = request(default_terminal(), msg, m; kwargs...) function request(term::REPL.Terminals.TTYTerminal, msg::AbstractString, m::AbstractMenu; kwargs...) println(term.out_stream, msg) diff --git a/stdlib/REPL/src/TerminalMenus/Pager.jl b/stdlib/REPL/src/TerminalMenus/Pager.jl index c823a5dedd1ba..091f87801e7a4 100644 --- a/stdlib/REPL/src/TerminalMenus/Pager.jl +++ b/stdlib/REPL/src/TerminalMenus/Pager.jl @@ -39,4 +39,4 @@ function pager(terminal, object) pager = Pager(String(take!(buffer)); pagesize = div(lines, 2)) return request(terminal, pager) end -pager(object) = pager(terminal, object) +pager(object) = pager(default_terminal(), object) diff --git a/stdlib/REPL/src/TerminalMenus/TerminalMenus.jl b/stdlib/REPL/src/TerminalMenus/TerminalMenus.jl index 87869e84d9838..9fcddef2fd484 100644 --- a/stdlib/REPL/src/TerminalMenus/TerminalMenus.jl +++ b/stdlib/REPL/src/TerminalMenus/TerminalMenus.jl @@ -2,13 +2,11 @@ module TerminalMenus -terminal = nothing # The user terminal +using REPL: REPL -import REPL - -function __init__() - global terminal - terminal = REPL.Terminals.TTYTerminal(get(ENV, "TERM", Sys.iswindows() ? "" : "dumb"), stdin, stdout, stderr) +function default_terminal(; in::IO=stdin, out::IO=stdout, err::IO=stderr) + return REPL.Terminals.TTYTerminal( + get(ENV, "TERM", Sys.iswindows() ? "" : "dumb"), in, out, err) end include("util.jl") diff --git a/stdlib/REPL/test/TerminalMenus/runtests.jl b/stdlib/REPL/test/TerminalMenus/runtests.jl index c594958a36670..9455632d9f418 100644 --- a/stdlib/REPL/test/TerminalMenus/runtests.jl +++ b/stdlib/REPL/test/TerminalMenus/runtests.jl @@ -17,9 +17,9 @@ function simulate_input(menu::TerminalMenus.AbstractMenu, keys...; kwargs...) write(new_stdin, "$key") end end - TerminalMenus.terminal.in_stream = new_stdin + terminal = TerminalMenus.default_terminal(; in=new_stdin, out=devnull) - return request(menu; suppress_output=true, kwargs...) + return request(terminal, menu; suppress_output=true, kwargs...) end include("radio_menu.jl")