@@ -120,27 +120,54 @@ function show(io::IO, ct::CoefTable)
120120 if length (rownms) == 0
121121 rownms = [lpad (" [$i ]" ,floor (Integer, log10 (nr))+ 3 ) for i in 1 : nr]
122122 end
123+
124+ if ! (get (io, :limit , false ):: Bool )
125+ screenheight = screenwidth = typemax (Int)
126+ else
127+ sz = displaysize (io):: Tuple{Int,Int}
128+ screenheight, screenwidth = sz[1 ] - 4 , sz[2 ]
129+ end
130+
131+ sepsize = 3
132+ hdots = " \u 2026 "
123133 mat = [j == 1 ? NoQuote (rownms[i]) :
124134 j- 1 == ct. pvalcol ? NoQuote (sprint (show, PValue (cols[j- 1 ][i]))) :
125135 j- 1 in ct. teststatcol ? TestStat (cols[j- 1 ][i]) :
126136 cols[j- 1 ][i] isa AbstractString ? NoQuote (cols[j- 1 ][i]) : cols[j- 1 ][i]
127137 for i in 1 : nr, j in 1 : nc+ 1 ]
138+
128139 # Code inspired by print_matrix in Base
129140 io = IOContext (io, :compact => true , :limit => false )
130141 A = Base. alignment (io, mat, 1 : size (mat, 1 ), 1 : size (mat, 2 ),
131- typemax (Int), typemax (Int), 3 )
142+ screenwidth, screenwidth, sepsize )
132143 nmswidths = pushfirst! (length .(colnms), 0 )
133144 A = [nmswidths[i] > sum (A[i]) ? (A[i][1 ]+ nmswidths[i]- sum (A[i]), A[i][2 ]) : A[i]
134145 for i in 1 : length (A)]
135- totwidth = sum (sum .(A)) + 2 * (length (A) - 1 )
146+
147+ # remove columns that do not fit on the screen
148+ maxcols = length (A)
149+ totwidth = sum (sum .(A)) + 2 * (length (A) - 1 )+ sepsize
150+ if maxcols < nc+ 1
151+ ncols = min (nc, maxcols)
152+ mat = mat[:, 1 : ncols]
153+ colnms = colnms[1 : ncols]
154+ sepsize = length (hdots)+ 1
155+ else
156+ sepsize = 0
157+ end
158+
159+ # print table
160+ totwidth = sum (sum .(A)) + 2 * (length (A) - 1 )+ sepsize
136161 println (io, repeat (' ─' , totwidth))
137162 print (io, repeat (' ' , sum (A[1 ])))
138- for j in 1 : length (colnms)
163+ for j in 1 : maxcols - 1
139164 print (io, " " , lpad (colnms[j], sum (A[j+ 1 ])))
140165 end
166+ maxcols < nc+ 1 && print (io, lpad (hdots, sepsize))
141167 println (io, ' \n ' , repeat (' ─' , totwidth))
142168 for i in 1 : size (mat, 1 )
143169 Base. print_matrix_row (io, mat, A, i, 1 : size (mat, 2 ), " " )
170+ maxcols < nc+ 1 && print (io, lpad (hdots, sepsize))
144171 i != size (mat, 1 ) && println (io)
145172 end
146173 print (io, ' \n ' , repeat (' ─' , totwidth))
0 commit comments