Skip to content

Commit dbeaab2

Browse files
committed
more changes and formatting
1 parent 4bbd0d1 commit dbeaab2

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/tensors/abstracttensor.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,4 +669,5 @@ function Base.show(io::IO, mime::MIME"text/plain", t::AbstractTensorMap)
669669
newio = IOContext(io, :displaysize => (numlines - 4, numcols))
670670
show_blocks(newio, mime, blocks(t))
671671
end
672+
return nothing
672673
end

src/tensors/blockiterator.jl

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ function foreachblock(f, t::AbstractTensorMap; scheduler = nothing)
4545
return nothing
4646
end
4747

48-
function show_blocks(io, mime::MIME"text/plain", iter)
49-
numlinesleft, numcols = get(io, :displaysize, displaysize(io))
50-
numlinesleft -= 2 # lines of headers have already been subtracted, but not the 2 spare lines for old and new prompts
51-
minlinesperblock = 7 # aim to have at least this many lines per printed block (= 5 lines for the actual matrix)
52-
minnumberofblocks = min(3, length(iter)) # aim to show at least this many blocks
53-
truncateblocks = sum(cb->min(size(cb[2], 1) + 2, minlinesperblock), iter; init = 0) > numlinesleft
54-
maxnumlinesperblock = max(div(numlinesleft - 2 * truncateblocks, minnumberofblocks), minlinesperblock)
55-
# aim to show at least minnumberofblocks, but not if this means that there would be less than minlinesperblock
56-
# deduct two lines for a truncation message (and newline) if needed
57-
for (n, (c, b)) in enumerate(iter)
58-
n == 1 || print(io, "\n\n")
59-
if get(io, :limit, false)
48+
function show_blocks(io, mime::MIME"text/plain", iter; maytruncate::Bool = true)
49+
if maytruncate && get(io, :limit, false)
50+
numlinesleft, numcols = get(io, :displaysize, displaysize(io))
51+
numlinesleft -= 2 # lines of headers have already been subtracted, but not the 2 spare lines for old and new prompts
52+
minlinesperblock = 7 # aim to have at least this many lines per printed block (= 5 lines for the actual matrix)
53+
minnumberofblocks = min(3, length(iter)) # aim to show at least this many blocks
54+
truncateblocks = sum(cb -> min(size(cb[2], 1) + 2, minlinesperblock), iter; init = 0) > numlinesleft
55+
maxnumlinesperblock = max(div(numlinesleft - 2 * truncateblocks, minnumberofblocks), minlinesperblock)
56+
# aim to show at least minnumberofblocks, but not if this means that there would be less than minlinesperblock
57+
# deduct two lines for a truncation message (and newline) if needed
58+
for (n, (c, b)) in enumerate(iter)
59+
n == 1 || print(io, "\n\n")
6060
numlinesneeded = min(size(b, 1) + 2, maxnumlinesperblock)
6161
if numlinesleft >= numlinesneeded + 2 * truncateblocks
6262
# we can still print at least this block, and have two lines for
@@ -70,9 +70,14 @@ function show_blocks(io, mime::MIME"text/plain", iter)
7070
print(io, " * ", " \u2026 [output of ", length(iter) - n + 1, " more block(s) truncated]")
7171
break
7272
end
73-
else
73+
end
74+
else
75+
first = true
76+
for (c, b) in iter
77+
first || print(io, "\n\n")
7478
print(io, " * ", c, " => ")
7579
show(io, mime, b)
80+
first = false
7681
end
7782
end
7883
return nothing
@@ -97,7 +102,7 @@ function Base.show(io::IO, mime::MIME"text/plain", b::BlockIterator)
97102
println(io, ":")
98103
(numlines, numcols) = get(io, :displaysize, displaysize(io))
99104
newio = IOContext(io, :displaysize => (numlines - 1, numcols))
100-
show_blocks(newio, mime, b)
105+
show_blocks(newio, mime, b; maytruncate = false)
101106
return nothing
102107
end
103108

0 commit comments

Comments
 (0)