Skip to content

Commit

Permalink
make sure to pass :compact context in show (#813)
Browse files Browse the repository at this point in the history
* make sure to pass :compact context in show

* no indexing changes
  • Loading branch information
rafaqz authored Oct 2, 2024
1 parent 79b2f87 commit 5bbe353
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/Dimensions/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ show_compact(io::IO, mime, dim::Dimension{Colon}) = print_dimname(io, dim)
function show_compact(io::IO, mime, dim::Dimension)
# Print to a buffer and count lengths
buf = IOBuffer()
print_dimname(buf, dim)
ctx = IOContext(buf, :compact => true)
print_dimname(ctx, dim)
nchars = length(String(take!(buf)))
print_dimval(buf, mime, parent(dim), nchars)
print_dimval(ctx, mime, parent(dim), nchars)
nvalchars = length(String(take!(buf)))
# Actually print to IO
print_dimname(io, dim)
Expand Down
8 changes: 5 additions & 3 deletions src/array/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ function print_dims_block(io, mime, dims; displaywidth, blockwidth, label="dims"
printed = false
new_blockwidth = blockwidth
else
ctx = IOContext(io, :dim_brackets=>false)
dim_lines = split(sprint(print_dims, mime, dims; context=ctx), '\n')
new_blockwidth = max(blockwidth, min(displaywidth - 2, maximum(textwidth, dim_lines)))
ctx = IOContext(io, :compact => true, :dim_brackets => false)
new_blockwidth = 100
printed=false
dim_width = maximum(textwidth, split(sprint(print_dims, mime, dims; context=ctx), '\n'))
new_blockwidth = max(blockwidth, min(displaywidth - 2, dim_width))
lines += print_block_top(ctx, label, blockwidth, new_blockwidth)
lines += print_dims(ctx, mime, dims; kw...)
println(io)
Expand Down

0 comments on commit 5bbe353

Please sign in to comment.