diff --git a/src/show.jl b/src/show.jl index 4788d4c..a51910e 100644 --- a/src/show.jl +++ b/src/show.jl @@ -5,7 +5,7 @@ abstract NULL Base.showcompact(io::IO, ::Type{NULL}) = show(io, NULL) Base.show(io::IO, ::Type{NULL}) = print(io, "#NULL") -Base.alignment(::Type{NULL}) = (5,0) +Base.alignment(io::IO, ::Type{NULL}) = (5,0) function Base.show(io::IO, X::NullableArray) print(io, typeof(X)) @@ -25,7 +25,7 @@ function Base.show_delim_array(io::IO, X::NullableArray, op, delim, cl, multiline = false else x = X.isnull[i] ? NULL : X.values[i] - multiline = isa(x,AbstractArray) && ndims(x)>1 && length(x)>0 + multiline = isa(x, AbstractArray) && ndims(x) > 1 && length(x) > 0 newline && multiline && println(io) if !isbits(x) && is(x, X) print(io, "#= circular reference =#") @@ -54,7 +54,7 @@ function Base.show_delim_array(io::IO, X::NullableArray, op, delim, cl, end function Base.alignment{T,N,U<:NullableArray}( - X::SubArray{T,N,U}, + io::IO, X::SubArray{T,N,U}, rows::AbstractVector, cols::AbstractVector, cols_if_complete::Integer, cols_otherwise::Integer, sep::Integer ) @@ -62,11 +62,11 @@ function Base.alignment{T,N,U<:NullableArray}( for j in cols l = r = 0 for i in rows - if isassigned(X,i,j) + if isassigned(X, i, j) if isnull(X, i, j) - aij = alignment(NULL) + aij = alignment(io, NULL) else - aij = alignment(values(X, i,j)) + aij = alignment(io, values(X, i, j)) end else aij = undef_ref_alignment @@ -75,13 +75,13 @@ function Base.alignment{T,N,U<:NullableArray}( r = max(r, aij[2]) end push!(a, (l, r)) - if length(a) > 1 && sum(map(sum,a)) + sep*length(a) >= cols_if_complete + if length(a) > 1 && sum(map(sum, a)) + sep*length(a) >= cols_if_complete pop!(a) break end end - if 1 < length(a) < size(X,2) - while sum(map(sum,a)) + sep*length(a) >= cols_otherwise + if 1 < length(a) < size(X, 2) + while sum(map(sum, a)) + sep*length(a) >= cols_otherwise pop!(a) end end @@ -89,7 +89,7 @@ function Base.alignment{T,N,U<:NullableArray}( end function Base.alignment( - X::Union{NullableArray, NullableMatrix}, + io::IO, X::Union{NullableArray, NullableMatrix}, rows::AbstractVector, cols::AbstractVector, cols_if_complete::Integer, cols_otherwise::Integer, sep::Integer ) @@ -97,11 +97,11 @@ function Base.alignment( for j in cols l = r = 0 for i in rows - if isassigned(X,i,j) + if isassigned(X, i, j) if isnull(X, i, j) - aij = alignment(NULL) + aij = alignment(io, NULL) else - aij = alignment(values(X, i,j)) + aij = alignment(io, values(X, i, j)) end else aij = undef_ref_alignment @@ -115,32 +115,51 @@ function Base.alignment( break end end - if 1 < length(a) < size(X,2) - while sum(map(sum,a)) + sep*length(a) >= cols_otherwise + if 1 < length(a) < size(X, 2) + while sum(map(sum, a)) + sep*length(a) >= cols_otherwise pop!(a) end end return a end -function Base.print_matrix_row{T,N,P<:NullableArray}(io::IO, - X::SubArray{T,N,P}, A::Vector, +function Base.print_matrix_row{T,N,P<:NullableArray}( + io::IO, X::SubArray{T,N,P}, A::Vector, i::Integer, cols::AbstractVector, sep::AbstractString ) - for k = 1:length(A) - j = cols[k] - if isassigned(X,i,j) - x = isnull(X,i,j) ? NULL : values(X,i,j) - a = alignment(x) - sx = sprint(showcompact_lim, x) - else - a = undef_ref_alignment - sx = undef_ref_str - end - l = repeat(" ", A[k][1]-a[1]) - r = repeat(" ", A[k][2]-a[2]) - print(io, l, sx, r) - if k < length(A); print(io, sep); end + if VERSION < v"0.5.0-dev+1936" # compat issues from + # https://github.com/JuliaLang/julia/pull/13825 + for k = 1:length(A) + j = cols[k] + if isassigned(X, i, j) + x = isnull(X, i, j) ? NULL : values(X, i, j) + a = alignment(x) + sx = sprint(showcompact_lim, x) + else + a = undef_ref_alignment + sx = undef_ref_str + end + l = repeat(" ", A[k][1]-a[1]) + r = repeat(" ", A[k][2]-a[2]) + print(io, l, sx, r) + if k < length(A); print(io, sep); end + end + else + for k = 1:length(A) + j = cols[k] + if isassigned(X, i, j) + x = isnull(X, i, j) ? NULL : values(X, i, j) + a = alignment(io, x) + sx = sprint(showcompact_lim, x) + else + a = undef_ref_alignment + sx = undef_ref_str + end + l = repeat(" ", A[k][1]-a[1]) + r = repeat(" ", A[k][2]-a[2]) + print(io, l, sx, r) + if k < length(A); print(io, sep); end + end end end @@ -148,19 +167,111 @@ function Base.print_matrix_row(io::IO, X::Union{NullableVector, NullableMatrix}, A::Vector, i::Integer, cols::AbstractVector, sep::AbstractString ) - for k = 1:length(A) - j = cols[k] - if isassigned(X,i,j) - x = isnull(X,i,j) ? NULL : values(X,i,j) - a = alignment(x) - sx = sprint(showcompact_lim, x) - else - a = undef_ref_alignment - sx = undef_ref_str - end - l = repeat(" ", A[k][1]-a[1]) - r = repeat(" ", A[k][2]-a[2]) - print(io, l, sx, r) - if k < length(A); print(io, sep); end + if VERSION < v"0.5.0-dev+1936" # compat issues from + # https://github.com/JuliaLang/julia/pull/13825 + for k = 1:length(A) + j = cols[k] + if isassigned(X, i, j) + x = isnull(X, i, j) ? NULL : values(X, i, j) + a = alignment(x) + sx = sprint(showcompact_lim, x) + else + a = undef_ref_alignment + sx = undef_ref_str + end + l = repeat(" ", A[k][1]-a[1]) + r = repeat(" ", A[k][2]-a[2]) + print(io, l, sx, r) + if k < length(A); print(io, sep); end + end + else + for k = 1:length(A) + j = cols[k] + if isassigned(X, i, j) + x = isnull(X, i, j) ? NULL : values(X, i, j) + a = alignment(io, x) + sx = sprint(showcompact_lim, x) + else + a = undef_ref_alignment + sx = undef_ref_str + end + l = repeat(" ", A[k][1]-a[1]) + r = repeat(" ", A[k][2]-a[2]) + print(io, l, sx, r) + if k < length(A); print(io, sep); end + end + end +end + +# Methods for compatibility issues for VERSION < 0.5.0-dev+1936 stemming +# from https://github.com/JuliaLang/julia/pull/13825 + +Base.alignment(::Type{NULL}) = (5,0) +function Base.alignment{T,N,U<:NullableArray}( + X::SubArray{T,N,U}, + rows::AbstractVector, cols::AbstractVector, + cols_if_complete::Integer, cols_otherwise::Integer, sep::Integer +) + a = [] + for j in cols + l = r = 0 + for i in rows + if isassigned(X, i, j) + if isnull(X, i, j) + aij = alignment(NULL) + else + aij = alignment(values(X, i, j)) + end + else + aij = undef_ref_alignment + end + l = max(l, aij[1]) + r = max(r, aij[2]) + end + push!(a, (l, r)) + if length(a) > 1 && sum(map(sum, a)) + sep*length(a) >= cols_if_complete + pop!(a) + break + end + end + if 1 < length(a) < size(X, 2) + while sum(map(sum, a)) + sep*length(a) >= cols_otherwise + pop!(a) + end + end + return a +end +function Base.alignment( + X::Union{NullableArray, NullableMatrix}, + rows::AbstractVector, cols::AbstractVector, + cols_if_complete::Integer, cols_otherwise::Integer, sep::Integer +) + a = [] + for j in cols + l = r = 0 + for i in rows + if isassigned(X, i, j) + if isnull(X, i, j) + aij = alignment(NULL) + else + aij = alignment(values(X, i, j)) + end + else + aij = undef_ref_alignment + end + l = max(l, aij[1]) + r = max(r, aij[2]) + end + push!(a, (l, r)) + if length(a) > 1 && sum(map(sum,a)) + sep*length(a) >= cols_if_complete + pop!(a) + break + end end + if 1 < length(a) < size(X, 2) + while sum(map(sum, a)) + sep*length(a) >= cols_otherwise + pop!(a) + end + end + return a end