Skip to content
Browse files

fix #5966

showcompact() should always be compact; confine the output limit stuff to
array printing
  • Loading branch information...
1 parent 8854bad commit 2946305376278d1bf4208a58f23a3835692d504f @JeffBezanson JeffBezanson committed
Showing with 19 additions and 17 deletions.
  1. +2 −4 base/grisu.jl
  2. +17 −13 base/show.jl
View
6 base/grisu.jl
@@ -118,10 +118,8 @@ show(io::IO, x::Float16) = _show(io, x, PRECISION, 5, true)
print(io::IO, x::Float32) = _show(io, x, SHORTEST_SINGLE, 0, false)
print(io::IO, x::Float16) = _show(io, x, PRECISION, 5, false)
-showcompact(io::IO, x::Float64) =
- (Base._limit_output::Bool) ? _show(io, x, PRECISION, 6, false) : _show(io, x, SHORTEST, 0, false)
-showcompact(io::IO, x::Float32) =
- (Base._limit_output::Bool) ? _show(io, x, PRECISION, 6, false) : _show(io, x, SHORTEST_SINGLE, 0, false)
+showcompact(io::IO, x::Float64) = _show(io, x, PRECISION, 6, false)
+showcompact(io::IO, x::Float32) = _show(io, x, PRECISION, 6, false)
showcompact(io::IO, x::Float16) = _show(io, x, PRECISION, 5, false)
# normal:
View
30 base/show.jl
@@ -1,3 +1,4 @@
+
show(x) = show(STDOUT::IO, x)
function print(io::IO, s::Symbol)
@@ -84,6 +85,9 @@ end
showcompact(io::IO, x) = show(io, x)
showcompact(x) = showcompact(STDOUT::IO, x)
+showcompact_lim(io, x) = _limit_output ? showcompact(io, x) : show(io, x)
+showcompact_lim(io, x::Number) = _limit_output ? showcompact(io, x) : print(io, x)
+
macro show(exs...)
blk = Expr(:block)
for ex in exs
@@ -133,7 +137,7 @@ function show_delim_array(io::IO, itr::AbstractArray, op, delim, cl, delim_one,
x = itr[i]
multiline = isa(x,AbstractArray) && ndims(x)>1 && length(x)>0
newline && multiline && println(io)
- compact ? showcompact(io, x) : show(io, x)
+ compact ? showcompact_lim(io, x) : show(io, x)
end
i += 1
if i > l
@@ -699,22 +703,22 @@ dump(io::IO, x::DataType) = dump(io, x, 5, "")
dump(io::IO, x::TypeVar, n::Int, indent) = println(io, x.name)
-alignment(x::Any) = (0, length(sprint(showcompact, x)))
-alignment(x::Number) = (length(sprint(showcompact, x)), 0)
-alignment(x::Integer) = (length(sprint(showcompact, x)), 0)
+alignment(x::Any) = (0, length(sprint(showcompact_lim, x)))
+alignment(x::Number) = (length(sprint(showcompact_lim, x)), 0)
+alignment(x::Integer) = (length(sprint(showcompact_lim, x)), 0)
function alignment(x::Real)
- m = match(r"^(.*?)((?:[\.eE].*)?)$", sprint(showcompact, x))
- m == nothing ? (length(sprint(showcompact, x)), 0) :
+ m = match(r"^(.*?)((?:[\.eE].*)?)$", sprint(showcompact_lim, x))
+ m == nothing ? (length(sprint(showcompact_lim, x)), 0) :
(length(m.captures[1]), length(m.captures[2]))
end
function alignment(x::Complex)
- m = match(r"^(.*,)(.*)$", sprint(showcompact, x))
- m == nothing ? (length(sprint(showcompact, x)), 0) :
+ m = match(r"^(.*,)(.*)$", sprint(showcompact_lim, x))
+ m == nothing ? (length(sprint(showcompact_lim, x)), 0) :
(length(m.captures[1]), length(m.captures[2]))
end
function alignment(x::Rational)
- m = match(r"^(.*?/)(/.*)$", sprint(showcompact, x))
- m == nothing ? (length(sprint(showcompact, x)), 0) :
+ m = match(r"^(.*?/)(/.*)$", sprint(showcompact_lim, x))
+ m == nothing ? (length(sprint(showcompact_lim, x)), 0) :
(length(m.captures[1]), length(m.captures[2]))
end
@@ -761,7 +765,7 @@ function print_matrix_row(io::IO,
if isassigned(X,i,j)
x = X[i,j]
a = alignment(x)
- sx = sprint(showcompact, x)
+ sx = sprint(showcompact_lim, x)
else
a = undef_ref_alignment
sx = undef_ref_str
@@ -948,7 +952,7 @@ function print_matrix_repr(io, X::AbstractArray)
print(io, undef_ref_str)
else
el = X[i,j]
- compact ? showcompact(io, el) : show(io, el)
+ compact ? showcompact_lim(io, el) : show(io, el)
end
end
if i < size(X,1)
@@ -970,7 +974,7 @@ function showarray(io::IO, X::AbstractArray;
header && println(io, ":")
if ndims(X) == 0
if isassigned(X)
- return showcompact(io, X[])
+ return showcompact_lim(io, X[])
else
return print(io, undef_ref_str)
end

0 comments on commit 2946305

Please sign in to comment.
Something went wrong with that request. Please try again.