Skip to content

Commit e82fcbf

Browse files
mcabbottKristofferC
authored and
KristofferC
committed
Ignore ANSI colour codes in printing Diagonal, etc (#47430)
(cherry picked from commit 9f572b6)
1 parent 6a09343 commit e82fcbf

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

base/arrayshow.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ centered cdot, used in printing of structural zeros of structured matrices.
4040
Accept keyword args `c` for alternate single character marker.
4141
"""
4242
function replace_with_centered_mark(s::AbstractString;c::AbstractChar = '')
43-
N = length(s)
43+
N = textwidth(ANSIIterator(s))
4444
return join(setindex!([" " for i=1:N],string(c),ceil(Int,N/2)))
4545
end
4646

test/show.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,3 +2368,7 @@ Base.show(io::IO, ces::⛵) = Base.print(io, '⛵')
23682368
@test Base.alignment(stdout, ()) == (0, 2)
23692369
@test Base.alignment(IOContext(IOBuffer(), :color=>true), ColoredLetter()) == (0, 1)
23702370
@test Base.alignment(IOContext(IOBuffer(), :color=>false), ColoredLetter()) == (0, 1)
2371+
2372+
# spacing around dots in Diagonal, etc:
2373+
redminusthree = sprint((io, x) -> printstyled(io, x, color=:red), "-3", context=stdout)
2374+
@test Base.replace_with_centered_mark(redminusthree) == Base.replace_with_centered_mark("-3")

0 commit comments

Comments
 (0)