|
47 | 47 |
|
48 | 48 | function show_blocks(io, mime::MIME"text/plain", iter) |
49 | 49 | 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) |
52 | 56 | # aim to show at least 3 blocks, but not if this means that there |
53 | 57 | # 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 |
55 | 59 | for (n, (c, b)) in enumerate(iter) |
56 | 60 | n == 1 || print(io, "\n\n") |
57 | 61 | if get(io, :limit, false) |
58 | 62 | 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 |
62 | 66 | print(io, " * ", c, " => ") |
63 | 67 | newio = IOContext(io, :displaysize => (maxnumlinesperblock - 1 + 3, numcols)) |
64 | 68 | # subtract 1 line for the newline, but add 3 because of how matrices are printed |
|
0 commit comments