@@ -229,6 +229,17 @@ function termstyle(io::IO, face::Face, lastface::Face=getface())
229
229
ANSI_STYLE_CODES. end_reverse))
230
230
end
231
231
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
+
232
243
function _ansi_writer (string_writer:: F , io:: IO , s:: Union{<:AnnotatedString, SubString{<:AnnotatedString}} ) where {F <: Function }
233
244
# We need to make sure that the customisations are loaded
234
245
# before we start outputting any styled content.
@@ -253,8 +264,7 @@ function _ansi_writer(string_writer::F, io::IO, s::Union{<:AnnotatedString, SubS
253
264
elseif s isa AnnotatedString
254
265
string_writer (io, s. string)
255
266
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))
258
268
end
259
269
end
260
270
0 commit comments