Skip to content

Commit

Permalink
show: fix double-width char display (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
iblislin committed Jul 10, 2019
1 parent 7447c93 commit 020214f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/timearray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function print_time_array(io::IO, ta::TimeArray{T}, short=false) where T
## e.g. | Open | High | Low | Close |
print(io, "", " "^(spacetime + 2))
for (name, w) in zip(colnames(ta)[p], colwidth[p])
print(io, "", rpad(name, w + 1))
print(io, "", _rpad(name, w + 1))
end
println(io, "")
## e.g. ├───────┼───────┼───────┼────────┤
Expand All @@ -278,7 +278,7 @@ function print_time_array(io::IO, ta::TimeArray{T}, short=false) where T
println(io)
print(io, "", ts[i], " ")
for j in p
print(io, "", rpad(strs[i, j], colwidth[j] + 1))
print(io, "", _rpad(strs[i, j], colwidth[j] + 1))
end
print(io, "")
end
Expand All @@ -290,7 +290,7 @@ function print_time_array(io::IO, ta::TimeArray{T}, short=false) where T
println(io)
print(io, "", ts[i], " ")
for j in p
print(io, "", rpad(strs[i, j], colwidth[j] + 1))
print(io, "", _rpad(strs[i, j], colwidth[j] + 1))
end
print(io, "")
end
Expand All @@ -300,7 +300,7 @@ function print_time_array(io::IO, ta::TimeArray{T}, short=false) where T
println(io)
print(io, "", ts[i], " ")
for j in p
print(io, "", rpad(strs[i, j], colwidth[j] + 1))
print(io, "", _rpad(strs[i, j], colwidth[j] + 1))
end
print(io, "")
end
Expand Down
11 changes: 11 additions & 0 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,14 @@ findcol(ta::AbstractTimeSeries, s::Symbol) = findcol(colnames(ta), s)
(i === nothing) && throw(KeyError(s))
i
end

"""
Unicode friendly rpad
"""
function _rpad(s::AbstractString, n::Integer)
x = n - textwidth(s)
(x 0) && return s
s * (" "^x)
end

_rpad(s::Symbol, n::Integer) = _rpad(string(s), n::Integer)

0 comments on commit 020214f

Please sign in to comment.