Skip to content

Commit fcb933a

Browse files
committed
Replace use of noshift constructor with unsafe_substring
1 parent 1aafc2f commit fcb933a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/io.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,16 @@ function termstyle(io::IO, face::Face, lastface::Face=getface())
229229
ANSI_STYLE_CODES.end_reverse))
230230
end
231231

232+
@static if isdefined(Base, :unsafe_substring)
233+
function plain_string(s::SubString{<:AnnotatedString})
234+
@inbounds Base.unsafe_substring(s.string, s.offset + 1, s.ncodeunits)
235+
end
236+
else
237+
function plain_string(s::SubString{AnnotatedString{S}}) where S
238+
SubString{S}(s.string.string, s.offset, s.ncodeunits, Val(:noshift))
239+
end
240+
end
241+
232242
function _ansi_writer(string_writer::F, io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}) where {F <: Function}
233243
# We need to make sure that the customisations are loaded
234244
# before we start outputting any styled content.
@@ -253,8 +263,7 @@ function _ansi_writer(string_writer::F, io::IO, s::Union{<:AnnotatedString, SubS
253263
elseif s isa AnnotatedString
254264
string_writer(io, s.string)
255265
elseif s isa SubString
256-
string_writer(
257-
io, SubString(s.string.string, s.offset, s.ncodeunits, Val(:noshift)))
266+
string_writer(io, plain_string(s))
258267
end
259268
end
260269

0 commit comments

Comments
 (0)