Skip to content

Commit

Permalink
stop showing shortcut tips in REPL for everyt stacktrace/methodlist (J…
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC authored Aug 25, 2020
1 parent 3d04d15 commit e859188
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 70 deletions.
50 changes: 19 additions & 31 deletions stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,27 +204,31 @@ end
==(a::REPLDisplay, b::REPLDisplay) = a.repl === b.repl

function display(d::REPLDisplay, mime::MIME"text/plain", x)
with_methodtable_hint(d.repl) do io
io = IOContext(io, :limit => true, :module => Main)
get(io, :color, false) && write(io, answer_color(d.repl))
if isdefined(d.repl, :options) && isdefined(d.repl.options, :iocontext)
# this can override the :limit property set initially
io = foldl(IOContext, d.repl.options.iocontext, init=io)
end
show(io, mime, x)
println(io)
linfos = Tuple{String,Int}[]
io = IOContext(outstream(d.repl), :limit => true, :module => Main, :last_shown_line_infos => linfos)
get(io, :color, false) && write(io, answer_color(d.repl))
if isdefined(d.repl, :options) && isdefined(d.repl.options, :iocontext)
# this can override the :limit property set initially
io = foldl(IOContext, d.repl.options.iocontext, init=io)
end
nothing
show(io, mime, x)
println(io)
if !isempty(linfos)
repl.last_shown_line_infos = linfos
end
return nothing
end
display(d::REPLDisplay, x) = display(d, MIME("text/plain"), x)

function print_response(repl::AbstractREPL, @nospecialize(response), show_value::Bool, have_color::Bool)
repl.waserror = response[2]
with_methodtable_hint(repl) do io
io = IOContext(io, :module => Main)
print_response(io, response, show_value, have_color, specialdisplay(repl))
linfos = Tuple{String,Int}[]
io = IOContext(outstream(repl), :module => Main, :last_shown_line_infos => linfos)
print_response(io, response, show_value, have_color, specialdisplay(repl))
if !isempty(linfos)
repl.last_shown_line_infos = linfos
end
nothing
return nothing
end
function print_response(errio::IO, @nospecialize(response), show_value::Bool, have_color::Bool, specialdisplay=nothing)
Base.sigatomic_begin()
Expand Down Expand Up @@ -507,22 +511,6 @@ function complete_line(c::LatexCompletions, s)
return unique!(map(completion_text, ret)), partial[range], should_complete
end

with_methodtable_hint(f, repl) = f(outstream(repl))
function with_methodtable_hint(f, repl::LineEditREPL)
linfos = Tuple{String,Int}[]
io = IOContext(outstream(repl), :last_shown_line_infos => linfos)
f(io)
if !isempty(linfos)
repl.last_shown_line_infos = linfos
println(
io,
"\nTo edit a specific method, type the corresponding number into the " *
"REPL and press Ctrl+Q",
)
end
nothing
end

mutable struct REPLHistoryProvider <: HistoryProvider
history::Vector{String}
history_file::Union{Nothing,IO}
Expand Down Expand Up @@ -1146,7 +1134,7 @@ function setup_interface(
str = String(take!(LineEdit.buffer(s)))
n = tryparse(Int, str)
n === nothing && @goto writeback
if n <= 0 || n > length(linfos) || startswith(linfos[n][1], "./REPL")
if n <= 0 || n > length(linfos) || startswith(linfos[n][1], "REPL[")
@goto writeback
end
InteractiveUtils.edit(linfos[n][1], linfos[n][2])
Expand Down
40 changes: 1 addition & 39 deletions stdlib/REPL/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ let exename = Base.julia_cmd()

output = readuntil(ptm, ' ', keep=true)
if Sys.iswindows()
# Our fake pty is actually a pipe, and thus lacks the input echo feature of posix
# Our fake pty is actually a pipe, and thus lacks the input echo feature of posix
@test output == "1\n\njulia> "
else
@test output == "1\r\nexit()\r\n1\r\n\r\njulia> "
Expand Down Expand Up @@ -1251,41 +1251,3 @@ Base.wait(frontend_task)
macro throw_with_linenumbernode(err)
Expr(:block, LineNumberNode(42, Symbol("test.jl")), :(() -> throw($err)))
end

@testset "last shown line infos" begin
out_stream = IOBuffer()
term = REPL.TTYTerminal("dumb", IOBuffer(), out_stream, IOBuffer())
repl = REPL.LineEditREPL(term, false)
repl.specialdisplay = REPL.REPLDisplay(repl)

REPL.print_response(repl, (methods(+), false), true, false)
seekstart(out_stream)
@test count(
contains(
"To edit a specific method, type the corresponding number into the REPL and " *
"press Ctrl+Q"
),
eachline(out_stream),
) == 1
take!(out_stream)

err = ErrorException("Foo")
bt = try
@throw_with_linenumbernode(err)()
catch
Base.catch_stack()
end

repl.backendref = REPL.REPLBackendRef(Channel(1), Channel(1))
put!(repl.backendref.response_channel, (bt, true))

REPL.print_response(repl, (bt, true), true, false)
seekstart(out_stream)
@test count(
contains(
"To edit a specific method, type the corresponding number into the REPL and " *
"press Ctrl+Q"
),
eachline(out_stream),
) == 1
end

0 comments on commit e859188

Please sign in to comment.