diff --git a/src/show.jl b/src/show.jl index b7dae03..98b919d 100644 --- a/src/show.jl +++ b/src/show.jl @@ -3,19 +3,25 @@ const DECIMALS = 4 # the maximum number of decimals to show const PADDING = 2 # number of spaces minimum between fields const SHOWINT = false # whether to format integer columns without decimals -import Base: isinteger, strwidth, rpad, summary -rpad(s::Symbol, n::Int)::String = rpad(string(s), n) -isinteger(::String)::Bool = false -isinteger(::Symbol)::Bool = false -isinteger(::Char)::Bool = false -isinteger(::Date)::Bool = false -isinteger(::DateTime)::Bool = false -isinteger(::Function)::Bool = false -strwidth(s::Symbol)::Int = strwidth(string(s)) -strwidth(n::Number)::Int = strwidth(string(n)) -strwidth(f::Function)::Int = strwidth(string(f)) -strwidth(b::Bool)::Int = b ? 4 : 5 -strwidth(c::Char)::Int = 1 +# rpad(s::Symbol, n::Int)::String = rpad(string(s), n) +# isinteger(::String)::Bool = false +# isinteger(::Symbol)::Bool = false +# isinteger(::Char)::Bool = false +# isinteger(::Date)::Bool = false +# isinteger(::DateTime)::Bool = false +# isinteger(::Function)::Bool = false +# strwidth(s::Symbol)::Int = strwidth(string(s)) +# strwidth(n::Number)::Int = strwidth(string(n)) +# strwidth(f::Function)::Int = strwidth(string(f)) +# strwidth(b::Bool)::Int = b ? 4 : 5 +# strwidth(c::Char)::Int = 1 + +str_width(s::AbstractString)::Int = strwidth(string(s)) +str_width(s::Symbol)::Int = strwidth(string(s)) +str_width(n::Number)::Int = strwidth(string(s)) +str_width(f::Function)::Int = strwidth(string(s)) +str_width(b::Bool)::Int = b ? 4 : 5 +str_width(c::Char)::Int = 1 function print_summary{V,T}(io::IO, x::TS{V,T})::Int if isempty(x) @@ -39,16 +45,16 @@ function getshowrows{V,T}(io::IO, x::TS{V,T})::Tuple{Vector{Int},Vector{Int}} end function getwidths{V,T}(io::IO, x::TS{V,T})::Vector{Int} - widths = [T==Date?10:19; strwidth.(x.fields)] + widths = [T==Date?10:19; str_width.(x.fields)] toprows, botrows = getshowrows(io, x) vals = [x.values[toprows,:]; x.values[botrows,:]] if V <: Number @inbounds for j in 1:size(x,2) - widths[j+1] = max(widths[j+1], maximum(strwidth.(round.(vals[:,j],DECIMALS)))) + widths[j+1] = max(widths[j+1], maximum(str_width.(round.(vals[:,j],DECIMALS)))) end else @inbounds for j in 1:size(x,2) - widths[j+1] = max(widths[j+1], maximum(strwidth.(vals[:,j]))) + widths[j+1] = max(widths[j+1], maximum(str_width.(vals[:,j]))) end end return widths @@ -62,7 +68,7 @@ function getnegs(io::IO, x::TS)::Vector{Bool} return [hasnegs(x.values[:,j]) for j in 1:size(x,2)] end -print_header(x::TS, widths::Vector{Int}, negs::Vector{Bool})::String = prod(rpad.(["Index"; lpad.(string.(x.fields), strwidth.(x.fields).+negs)], widths)) +print_header(x::TS, widths::Vector{Int}, negs::Vector{Bool})::String = prod(rpad.(["Index"; lpad.(string.(x.fields), str_width.(x.fields).+negs)], widths)) function print_row{V,T}(x::TS{V,T}, row::Int, widths::Vector{Int}, negs::Vector{Bool})::String if V <: Number