Skip to content

Commit

Permalink
Add trailing nl for display(::TextDisplay, ...) (#43787)
Browse files Browse the repository at this point in the history
Fixes #43766.
  • Loading branch information
t-bltg authored Jan 13, 2022
1 parent 89f2332 commit 49f4f78
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
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()
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])
@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

0 comments on commit 49f4f78

Please sign in to comment.