Skip to content

Commit

Permalink
Ignore ANSI colour codes in printing Diagonal, etc (#47430)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9f572b6)
  • Loading branch information
mcabbott authored and KristofferC committed Dec 14, 2022
1 parent 6a09343 commit e82fcbf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/arrayshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ centered cdot, used in printing of structural zeros of structured matrices.
Accept keyword args `c` for alternate single character marker.
"""
function replace_with_centered_mark(s::AbstractString;c::AbstractChar = '')
N = length(s)
N = textwidth(ANSIIterator(s))
return join(setindex!([" " for i=1:N],string(c),ceil(Int,N/2)))
end

Expand Down
4 changes: 4 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2368,3 +2368,7 @@ Base.show(io::IO, ces::⛵) = Base.print(io, '⛵')
@test Base.alignment(stdout, ()) == (0, 2)
@test Base.alignment(IOContext(IOBuffer(), :color=>true), ColoredLetter()) == (0, 1)
@test Base.alignment(IOContext(IOBuffer(), :color=>false), ColoredLetter()) == (0, 1)

# spacing around dots in Diagonal, etc:
redminusthree = sprint((io, x) -> printstyled(io, x, color=:red), "-3", context=stdout)
@test Base.replace_with_centered_mark(redminusthree) == Base.replace_with_centered_mark("-3")

0 comments on commit e82fcbf

Please sign in to comment.