Skip to content

Commit 5e48a37

Browse files
committed
some more finetuning and code improvement
1 parent 7364ef3 commit 5e48a37

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/tensors/blockiterator.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,22 @@ end
4747

4848
function show_blocks(io, mime::MIME"text/plain", iter)
4949
numlinesleft, numcols = get(io, :displaysize, displaysize(io))
50-
# lines of headers should already have been subtracted, but not the 3 spare lines for old and new prompts
51-
maxnumlinesperblock = max(div(numlinesleft - 4, min(3, length(iter))), 7)
50+
numlinesleft -= 2
51+
# lines of headers should already have been subtracted, but not the 2 spare lines for old and new prompts
52+
minlinesperblock = 7
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)
5256
# aim to show at least 3 blocks, but not if this means that there
5357
# would be less than 7 lines per block (= 5 lines for the actual matrix)
54-
# we deduct 4 lines to leave space for a truncation message and prompts
58+
# we deduct a line for a truncation message depending on truncateblocks
5559
for (n, (c, b)) in enumerate(iter)
5660
n == 1 || print(io, "\n\n")
5761
if get(io, :limit, false)
5862
numlinesneeded = min(size(b, 1) + 2, maxnumlinesperblock)
59-
if numlinesleft >= numlinesneeded + 4
60-
# we can still print at least this block, and have one line
61-
# for the truncation message and 3 more lines for old and new prompts
63+
if numlinesleft >= numlinesneeded + 2 * truncateblocks
64+
# we can still print at least this block, and have two lines for
65+
# the truncation message (and its newline) if it is required
6266
print(io, " * ", c, " => ")
6367
newio = IOContext(io, :displaysize => (maxnumlinesperblock - 1 + 3, numcols))
6468
# subtract 1 line for the newline, but add 3 because of how matrices are printed

0 commit comments

Comments
 (0)