Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ function termstyle(io::IO, face::Face, lastface::Face=getface())
ANSI_STYLE_CODES.end_reverse))
end

@static if isdefined(Base, :unannotate)
# This function uses SubString and AnnotatedString internals, but for current
# and future versions, Base.unannotate is defined, and so this cannot break
# in the future.
const unannotate = Base.unannotate
else
function unannotate(s::SubString{AnnotatedString{S}}) where S
SubString{S}(s.string.string, s.offset, s.ncodeunits, Val(:noshift))
end
end

function _ansi_writer(string_writer::F, io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}) where {F <: Function}
# We need to make sure that the customisations are loaded
# before we start outputting any styled content.
Expand All @@ -253,8 +264,7 @@ function _ansi_writer(string_writer::F, io::IO, s::Union{<:AnnotatedString, SubS
elseif s isa AnnotatedString
string_writer(io, s.string)
elseif s isa SubString
string_writer(
io, SubString(s.string.string, s.offset, s.ncodeunits, Val(:noshift)))
string_writer(io, unannotate(s))
end
end

Expand Down
Loading