Skip to content

Commit 9f572b6

Browse files
authored
Ignore ANSI colour codes in printing Diagonal, etc (#47430)
1 parent 65c6bda commit 9f572b6

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
@@ -2379,6 +2379,10 @@ Base.show(io::IO, ces::⛵) = Base.print(io, '⛵')
23792379
@test Base.alignment(IOContext(IOBuffer(), :color=>true), ColoredLetter()) == (0, 1)
23802380
@test Base.alignment(IOContext(IOBuffer(), :color=>false), ColoredLetter()) == (0, 1)
23812381

2382+
# spacing around dots in Diagonal, etc:
2383+
redminusthree = sprint((io, x) -> printstyled(io, x, color=:red), "-3", context=stdout)
2384+
@test Base.replace_with_centered_mark(redminusthree) == Base.replace_with_centered_mark("-3")
2385+
23822386
# `show` implementations for `Method`
23832387
let buf = IOBuffer()
23842388

0 commit comments

Comments
 (0)