Skip to content

Commit

Permalink
Merge pull request JuliaLang#16651 from JuliaLang/jb/fix16649
Browse files Browse the repository at this point in the history
implement output limiting for single-line array showing
  • Loading branch information
JeffBezanson committed May 31, 2016
2 parents b6962b4 + e16f5dd commit 0919d71
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
44 changes: 33 additions & 11 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1442,24 +1442,46 @@ end
`print_matrix_repr(io, X)` prints matrix X with opening and closing square brackets.
"""
function print_matrix_repr(io, X::AbstractArray)
limit = get(io, :limit, false)::Bool
compact, prefix = array_eltype_show_how(X)
if compact && !haskey(io, :compact)
io = IOContext(io, :compact => compact)
end
nr, nc = size(X,1), size(X,2)
rdots, cdots = false, false
rr1, rr2 = 1:nr, 1:0
cr1, cr2 = 1:nc, 1:0
if limit
if nr > 4
rr1, rr2 = 1:2, nr-1:nr
rdots = true
end
if nc > 4
cr1, cr2 = 1:2, nc-1:nc
cdots = true
end
end
print(io, prefix, "[")
for i=1:size(X,1)
for j=1:size(X,2)
j > 1 && print(io, " ")
if !isassigned(X,i,j)
print(io, undef_ref_str)
else
el = X[i,j]
show(io, el)
for rr in (rr1, rr2)
for i in rr
for cr in (cr1, cr2)
for j in cr
j > first(cr) && print(io, " ")
if !isassigned(X,i,j)
print(io, undef_ref_str)
else
el = X[i,j]
show(io, el)
end
end
if last(cr) == nc
i < nr && print(io, "; ")
elseif cdots
print(io, " \u2026 ")
end
end
end
if i < size(X,1)
print(io, "; ")
end
last(rr) != nr && rdots && print(io, "\u2026 ; ")
end
print(io, "]")
end
Expand Down
4 changes: 4 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,7 @@ end
# parameter names.
@test string(Array) == "Array{T,N}"
@test string(Tuple{Array}) == "Tuple{Array}"

# PR #16651
@test !contains(repr(ones(10,10)), "\u2026")
@test contains(sprint((io,x)->show(IOContext(io,:limit=>true), x), ones(30,30)), "\u2026")

0 comments on commit 0919d71

Please sign in to comment.