Skip to content

Commit

Permalink
replace REPL.TerminalMenus.terminal with type stable function (#53704)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk authored Mar 14, 2024
1 parent 612393c commit 5023ee2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions stdlib/REPL/src/TerminalMenus/AbstractMenu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/REPL/src/TerminalMenus/Pager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 4 additions & 6 deletions stdlib/REPL/src/TerminalMenus/TerminalMenus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions stdlib/REPL/test/TerminalMenus/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 5023ee2

Please sign in to comment.