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 2 commits
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
8 changes: 4 additions & 4 deletions stdlib/DelimitedFiles/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,10 @@ end
# issue #11484: useful error message for invalid readdlm filepath arguments
@test_throws ArgumentError readdlm(tempdir())

# displaying as text/csv
let d = TextDisplay(IOBuffer())
display(d, "text/csv", [3 1 4])
@test String(take!(d.io)) == "3,1,4\n"
# showing as text/csv
let d = TextDisplay(PipeBuffer())
show(d.io, "text/csv", [3 1 4])
t-bltg marked this conversation as resolved.
Show resolved Hide resolved
@test read(d.io, String) == "3,1,4\n"
end

@testset "complex" begin
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
13 changes: 10 additions & 3 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1877,11 +1877,10 @@ end

@testset "#14684: `display` should print associative types in full" begin
d = Dict(1 => 2, 3 => 45)
buf = IOBuffer()
td = TextDisplay(buf)
td = TextDisplay(PipeBuffer())

display(td, d)
result = String(take!(td.io))
result = read(td.io, String)
@test occursin(summary(d), result)

# Is every pair in the string?
Expand All @@ -1890,6 +1889,14 @@ end
end
end

@testset "#43766: `display` trailing newline" begin
td = TextDisplay(PipeBuffer())
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