@@ -503,7 +503,9 @@ function xdump(fn::Function, io::IO, x::Array{Any}, n::Int, indent)
503
503
end
504
504
xdump (fn:: Function , io:: IO , x:: Symbol , n:: Int , indent) = println (io, typeof (x), " " , x)
505
505
xdump (fn:: Function , io:: IO , x:: Function , n:: Int , indent) = println (io, x)
506
- xdump (fn:: Function , io:: IO , x:: Array , n:: Int , indent) = println (io, " Array($(eltype (x)) ,$(size (x)) )" , " " , x)
506
+ xdump (fn:: Function , io:: IO , x:: Array , n:: Int , indent) =
507
+ (print (io, " Array($(eltype (x)) ,$(size (x)) ) " );
508
+ show (io, x); println (io))
507
509
508
510
# Types
509
511
xdump (fn:: Function , io:: IO , x:: UnionType , n:: Int , indent) = println (io, x)
@@ -579,15 +581,17 @@ xdump(fn::Function, io::IO, x, n::Int) = xdump(xdump, io, x, n, "")
579
581
xdump (fn:: Function , io:: IO , args... ) = error (" invalid arguments to xdump" )
580
582
xdump (fn:: Function , args... ) = xdump (fn, STDOUT:: IO , args... )
581
583
xdump (io:: IO , args... ) = xdump (xdump, io, args... )
582
- xdump (args... ) = xdump (xdump, STDOUT:: IO , args... )
584
+ xdump (args... ) = with_output_limit (() -> xdump (xdump, STDOUT:: IO , args... ), true )
583
585
584
586
# Here are methods specifically for dump:
585
587
dump (io:: IO , x, n:: Int ) = dump (io, x, n, " " )
586
588
dump (io:: IO , x) = dump (io, x, 5 , " " ) # default is 5 levels
587
- dump (io:: IO , x:: String , n:: Int , indent) = println (io, typeof (x), " \" " , x, " \" " )
589
+ dump (io:: IO , x:: String , n:: Int , indent) =
590
+ (print (io, typeof (x), " " );
591
+ show (io, x); println (io))
588
592
dump (io:: IO , x, n:: Int , indent) = xdump (dump, io, x, n, indent)
589
593
dump (io:: IO , args... ) = error (" invalid arguments to dump" )
590
- dump (args... ) = dump (STDOUT:: IO , args... )
594
+ dump (args... ) = with_output_limit (() -> dump (STDOUT:: IO , args... ), true )
591
595
592
596
function dump (io:: IO , x:: Dict , n:: Int , indent)
593
597
println (typeof (x), " len " , length (x))
@@ -854,10 +858,17 @@ function show{T}(io::IO, x::AbstractArray{T,0})
854
858
print (io, sx)
855
859
end
856
860
861
+ # global flag for limiting output
862
+ # TODO : this should be replaced with a better mechanism. currently it is only
863
+ # for internal use in showing arrays.
864
+ _limit_output = false
865
+
857
866
# NOTE: this is a possible, so-far-unexported function, providing control of
858
867
# array output. Not sure I want to do it this way.
859
868
showarray (X:: AbstractArray ; kw... ) = showarray (STDOUT, X; kw... )
860
- function showarray (io:: IO , X:: AbstractArray ; header= true , limit= true , rows= tty_rows ()- 4 , cols= tty_cols ())
869
+ function showarray (io:: IO , X:: AbstractArray ;
870
+ header:: Bool = true , limit:: Bool = _limit_output,
871
+ rows = tty_rows ()- 4 , cols = tty_cols ())
861
872
header && print (io, summary (X))
862
873
if ! isempty (X)
863
874
header && println (io, " :" )
@@ -879,12 +890,48 @@ show(io::IO, X::AbstractArray) = showarray(io, X)
879
890
880
891
print (io:: IO , X:: AbstractArray ) = writedlm (io, X)
881
892
893
+ function with_output_limit (thk, lim= true )
894
+ global _limit_output
895
+ last = _limit_output
896
+ _limit_output = lim
897
+ try
898
+ thk ()
899
+ finally
900
+ _limit_output = last
901
+ end
902
+ end
903
+
882
904
showall (x) = showall (STDOUT, x)
883
- showall (io:: IO , x) = show (io, x)
884
- showall (io:: IO , x:: AbstractArray ) = showarray (io, x, limit= false )
905
+ function showall (io:: IO , x)
906
+ if _limit_output== false
907
+ show (io, x)
908
+ else
909
+ with_output_limit (false ) do
910
+ show (io, x)
911
+ end
912
+ end
913
+ end
914
+
915
+ showlimited (x) = showlimited (STDOUT, x)
916
+ function showlimited (io:: IO , x)
917
+ if _limit_output== true
918
+ show (io, x)
919
+ else
920
+ with_output_limit (true ) do
921
+ show (io, x)
922
+ end
923
+ end
924
+ end
885
925
886
926
function show_vector (io:: IO , v, opn, cls)
887
- show_delim_array (io, v, opn, " ," , cls, false )
927
+ if _limit_output && length (v) > 20
928
+ show_delim_array (io, v[1 : 10 ], opn, " ," , " " , false )
929
+ print (io, " \u 2026 " )
930
+ show_delim_array (io, v[end - 9 : end ], " " , " ," , cls, false )
931
+ # print_matrix(io, X, 1, tty_cols(), opn, ", ", cls, " \u2026 ", "\u22ee", " \u22f1 ", 5, 5)
932
+ else
933
+ show_delim_array (io, v, opn, " ," , cls, false )
934
+ end
888
935
end
889
936
890
937
show (io:: IO , v:: AbstractVector{Any} ) = show_vector (io, v, " {" , " }" )
0 commit comments