Skip to content

Commit 331cb3f

Browse files
rfourquetKristofferC
authored andcommitted
fix: give access to displaysize when displaying at REPL (#58121)
In #53959, an new `LimitIO` object was defined to display at the REPL, but it hid the displaysize of the underlying `io`. This patch just forwards this information. Before: ``` julia> Dict(1 => fill(UInt(0), 4)) Dict{Int64, Vector{UInt64}} with 1 entry: 1 => [0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x000000000… ``` After: ``` Dict{Int64, Vector{UInt64}} with 1 entry: 1 => [0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000] ``` (cherry picked from commit 35bfba9)
1 parent e01179c commit 331cb3f

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

stdlib/REPL/src/REPL.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ function Base.showerror(io::IO, e::LimitIOException)
474474
print(io, "$LimitIOException: aborted printing after attempting to print more than $(Base.format_bytes(e.maxbytes)) within a `LimitIO`.")
475475
end
476476

477+
Base.displaysize(io::LimitIO) = _displaysize(io.io)
478+
477479
function Base.write(io::LimitIO, v::UInt8)
478480
io.n > io.maxbytes && throw(LimitIOException(io.maxbytes))
479481
n_bytes = write(io.io, v)

stdlib/REPL/test/repl.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,9 @@ end
19481948
@test output == "…[printing stopped after displaying 0 bytes; $hint]"
19491949
@test sprint(io -> show(REPL.LimitIO(io, 5), "abc")) == "\"abc\""
19501950
@test_throws REPL.LimitIOException(1) sprint(io -> show(REPL.LimitIO(io, 1), "abc"))
1951+
1952+
# displaying objects at the REPL sometimes needs access to displaysize, like Dict
1953+
@test displaysize(IOContext(REPL.LimitIO(stdout, 100), stdout)) == displaysize(stdout)
19511954
finally
19521955
REPL.SHOW_MAXIMUM_BYTES = previous
19531956
end

0 commit comments

Comments
 (0)