Skip to content

Commit

Permalink
propagate the terminals displaysize to the IOContext used by the REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Sep 12, 2024
1 parent 67c1723 commit ac10640
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion base/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,12 @@ function show(
get(io, :limit, false)::Bool || return show(io, str)
limit = max(20, displaysize(io)[2])
# one line in collection, seven otherwise
get(io, :typeinfo, nothing) === nothing && (limit *= 7)
if get(io, :typeinfo, nothing) === nothing
limit *= 7
else
# strings in collections are typically indented one space
limit -= 1
end
end

# early out for short strings
Expand Down
1 change: 1 addition & 0 deletions stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ function display(d::REPLDisplay, mime::MIME"text/plain", x)
# this can override the :limit property set initially
io = foldl(IOContext, d.repl.options.iocontext, init=io)
end
io = IOContext(io, :displaysize => displaysize(outstream(d.repl)))
show_repl(io, mime, x[])
println(io)
end
Expand Down
2 changes: 1 addition & 1 deletion test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ end
@test r == repr("x"^271) * " ⋯ 459 bytes ⋯ " * repr("x"^270)
r = replstr(["x"^1000])
@test length(r) < 120
@test r == "1-element Vector{String}:\n " * repr("x"^31) * "939 bytes ⋯ " * repr("x"^30)
@test r == "1-element Vector{String}:\n " * repr("x"^30) * "940 bytes ⋯ " * repr("x"^30)
end
end

Expand Down

0 comments on commit ac10640

Please sign in to comment.