Skip to content

Commit 5ad4d37

Browse files
committed
Replace use of noshift constructor with unannotate
1 parent 1aafc2f commit 5ad4d37

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/io.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,17 @@ function termstyle(io::IO, face::Face, lastface::Face=getface())
229229
ANSI_STYLE_CODES.end_reverse))
230230
end
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+
232243
function _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
259269
end
260270

0 commit comments

Comments
 (0)