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

propagate the terminal's displaysize to the IOContext used by the REPL #55499

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I don't get about this is that io is already initialized to outstream(d.repl), so this should not be necessary. Is something else adding a :displaysize key here that's overriding it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the actual problem is in arrayshow.jl:

            sx = sprint(show, "text/plain", x, context=io, sizehint=0)

in print_matrix_row. It tries to inherit the context but the displaysize is not included.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will try that then.

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