@@ -46,12 +46,32 @@ function foreachblock(f, t::AbstractTensorMap; scheduler = nothing)
4646end
4747
4848function show_blocks (io, mime:: MIME"text/plain" , iter)
49- first = true
50- for (c, b) in iter
51- first || print (io, " \n\n " )
52- print (io, " * " , c, " => " )
53- show (io, mime, b)
54- first = false
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 )
52+ # aim to show at least 3 blocks, but not if this means that there
53+ # 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
55+ for (n, (c, b)) in enumerate (iter)
56+ n == 1 || print (io, " \n\n " )
57+ if get (io, :limit , false )
58+ 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
62+ print (io, " * " , c, " => " )
63+ newio = IOContext (io, :displaysize => (maxnumlinesperblock - 1 + 3 , numcols))
64+ # subtract 1 line for the newline, but add 3 because of how matrices are printed
65+ show (newio, mime, b)
66+ numlinesleft -= numlinesneeded
67+ else
68+ print (io, " * " , " \u 2026 [output of " , length (iter) - n + 1 , " more block(s) truncated]" )
69+ break
70+ end
71+ else
72+ print (io, " * " , c, " => " )
73+ show (io, mime, b)
74+ end
5575 end
5676 return nothing
5777end
7393function Base. show (io:: IO , mime:: MIME"text/plain" , b:: BlockIterator )
7494 summary (io, b)
7595 println (io, " :" )
76- show_blocks (io, mime, b)
96+ (numlines, numcols) = get (io, :displaysize , displaysize (io))
97+ newio = IOContext (io, :displaysize => (numlines - 1 , numcols))
98+ show_blocks (newio, mime, b)
7799 return nothing
78100end
79101
0 commit comments