@@ -229,6 +229,17 @@ function termstyle(io::IO, face::Face, lastface::Face=getface())
229229 ANSI_STYLE_CODES. end_reverse))
230230end
231231
232+ @static if isdefined (Base, :unannotate )
233+ # This function uses SubString and AnnotatedString internals, but for current
234+ # and future versions, Base.unannotate is defined, and so this cannot break
235+ # in the future.
236+ const unannotate = Base. unannotate
237+ else
238+ function unannotate (s:: SubString{AnnotatedString{S}} ) where S
239+ SubString {S} (s. string. string, s. offset, s. ncodeunits, Val (:noshift ))
240+ end
241+ end
242+
232243function _ansi_writer (string_writer:: F , io:: IO , s:: Union{<:AnnotatedString, SubString{<:AnnotatedString}} ) where {F <: Function }
233244 # We need to make sure that the customisations are loaded
234245 # before we start outputting any styled content.
@@ -253,8 +264,7 @@ function _ansi_writer(string_writer::F, io::IO, s::Union{<:AnnotatedString, SubS
253264 elseif s isa AnnotatedString
254265 string_writer (io, s. string)
255266 elseif s isa SubString
256- string_writer (
257- io, SubString (s. string. string, s. offset, s. ncodeunits, Val (:noshift )))
267+ string_writer (io, unannotate (s))
258268 end
259269end
260270
0 commit comments