Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trailing nl for display(::TextDisplay, ...) #43787

Merged
merged 3 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 0 additions & 1 deletion base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ function eval_user_input(errio, @nospecialize(ast), show_value::Bool)
@error "Evaluation succeeded, but an error occurred while displaying the value" typeof(value)
rethrow()
end
println()
t-bltg marked this conversation as resolved.
Show resolved Hide resolved
end
end
break
Expand Down
4 changes: 2 additions & 2 deletions base/multimedia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ objects are printed in the Julia REPL.)
struct TextDisplay <: AbstractDisplay
io::IO
end
display(d::TextDisplay, M::MIME"text/plain", @nospecialize x) = show(d.io, M, x)
display(d::TextDisplay, M::MIME"text/plain", @nospecialize x) = (show(d.io, M, x); println(d.io))
display(d::TextDisplay, @nospecialize x) = display(d, MIME"text/plain"(), x)

# if you explicitly call display("text/foo", x), it should work on a TextDisplay:
displayable(d::TextDisplay, M::MIME) = istextmime(M)
function display(d::TextDisplay, M::MIME, @nospecialize x)
displayable(d, M) || throw(MethodError(display, (d, M, x)))
show(d.io, M, x)
show(d.io, M, x); println(d.io)
end

import Base: close, flush
Expand Down
4 changes: 2 additions & 2 deletions test/missing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ end
@test sprint(show, [1 missing]) == "$(Union{Int, Missing})[1 missing]"
b = IOBuffer()
display(TextDisplay(b), [missing])
@test String(take!(b)) == "1-element Vector{$Missing}:\n missing"
@test String(take!(b)) == "1-element Vector{$Missing}:\n missing\n"
b = IOBuffer()
display(TextDisplay(b), [1 missing])
@test String(take!(b)) == "1×2 Matrix{$(Union{Int, Missing})}:\n 1 missing"
@test String(take!(b)) == "1×2 Matrix{$(Union{Int, Missing})}:\n 1 missing\n"
end

@testset "arrays with missing values" begin
Expand Down
9 changes: 9 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,15 @@ end
end
end

@testset "#43766: `display` trailing newline" begin
buf = PipeBuffer()
td = TextDisplay(buf)
display(td, 1)
@test read(td.io, String) == "1\n"
show(td.io, 1)
@test read(td.io, String) == "1"
end

function _methodsstr(f)
buf = IOBuffer()
show(buf, methods(f))
Expand Down