Skip to content

Commit

Permalink
bettter fix for #36575 (#37203)
Browse files Browse the repository at this point in the history
* better fix for #36575
  • Loading branch information
KristofferC authored Aug 26, 2020
1 parent bf32ea4 commit d84cd4d
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function repl_backend_loop(backend::REPLBackend)
end
eval_user_input(ast, backend)
end
nothing
return nothing
end

struct REPLDisplay{R<:AbstractREPL} <: AbstractDisplay
Expand All @@ -204,29 +204,25 @@ end
==(a::REPLDisplay, b::REPLDisplay) = a.repl === b.repl

function display(d::REPLDisplay, mime::MIME"text/plain", x)
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
show(io, mime, x)
println(io)
if !isempty(linfos)
repl.last_shown_line_infos = linfos
with_repl_linfo(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)
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]
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
with_repl_linfo(repl) do io
io = IOContext(io, :module => Main)
print_response(io, response, show_value, have_color, specialdisplay(repl))
end
return nothing
end
Expand Down Expand Up @@ -511,6 +507,17 @@ function complete_line(c::LatexCompletions, s)
return unique!(map(completion_text, ret)), partial[range], should_complete
end

with_repl_linfo(f, repl) = f(outstream(repl))
function with_repl_linfo(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
end
nothing
end

mutable struct REPLHistoryProvider <: HistoryProvider
history::Vector{String}
history_file::Union{Nothing,IO}
Expand Down

0 comments on commit d84cd4d

Please sign in to comment.