@@ -225,8 +225,7 @@ function termstyle(io::IO, face::Face, lastface::Face=getface())
225225 ANSI_STYLE_CODES. end_reverse))
226226end
227227
228- function _ansi_writer (io:: IO , s:: Union{<:AnnotatedString, SubString{<:AnnotatedString}} ,
229- string_writer:: F ) where {F <: Function }
228+ function _ansi_writer (string_writer:: F , io:: IO , s:: Union{<:AnnotatedString, SubString{<:AnnotatedString}} ) where {F <: Function }
230229 # We need to make sure that the customisations are loaded
231230 # before we start outputting any styled content.
232231 load_customisations! ()
@@ -255,22 +254,13 @@ function _ansi_writer(io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedS
255254 end
256255end
257256
258- Base . write (io :: IO , s :: Union{<:AnnotatedString, SubString{<:AnnotatedString}} ) =
259- _ansi_writer (io, s, write) :: Int
257+ # ------------
258+ # Hook into the AnnotatedDisplay invalidation barrier
260259
261- Base. print ( io:: IO , s:: Union{<:AnnotatedString, SubString{<:AnnotatedString}} ) =
262- ( _ansi_writer (io, s, print); nothing )
260+ Base. AnnotatedDisplay . ansi_write (f :: F , io:: IO , s:: Union{<:AnnotatedString, SubString{<:AnnotatedString}} ) where {F <: Function } =
261+ _ansi_writer (f, io, s )
263262
264- # We need to make sure that printing to an `AnnotatedIOBuffer` calls `write` not `print`
265- # so we get the specialised handling that `_ansi_writer` doesn't provide.
266- Base. print (io:: AnnotatedIOBuffer , s:: Union{<:AnnotatedString, SubString{<:AnnotatedString}} ) =
267- (write (io, s); nothing )
268-
269- Base. escape_string (io:: IO , s:: Union{<:AnnotatedString, SubString{<:AnnotatedString}} ,
270- esc = " " ; keep = (), ascii:: Bool = false , fullhex:: Bool = false ) =
271- (_ansi_writer (io, s, (io, s) -> escape_string (io, s, esc; keep, ascii, fullhex)); nothing )
272-
273- function Base. write (io:: IO , c:: AnnotatedChar )
263+ function Base. AnnotatedDisplay. ansi_write (:: typeof (write), io:: IO , c:: AnnotatedChar )
274264 if get (io, :color , false ) == true
275265 termstyle (io, getface (c), getface ())
276266 bytes = write (io, c. char)
@@ -281,9 +271,7 @@ function Base.write(io::IO, c::AnnotatedChar)
281271 end
282272end
283273
284- Base. print (io:: IO , c:: AnnotatedChar ) = (write (io, c); nothing )
285-
286- function Base. show (io:: IO , c:: AnnotatedChar )
274+ function Base. AnnotatedDisplay. show_annot (io:: IO , c:: AnnotatedChar )
287275 if get (io, :color , false ) == true
288276 out = IOBuffer ()
289277 show (out, c. char)
@@ -296,19 +284,11 @@ function Base.show(io::IO, c::AnnotatedChar)
296284 end
297285end
298286
299- function Base. write (io:: IO , aio:: AnnotatedIOBuffer )
300- if get (io, :color , false ) == true
301- # This does introduce an overhead that technically
302- # could be avoided, but I'm not sure that it's currently
303- # worth the effort to implement an efficient version of
304- # writing from a AnnotatedIOBuffer with style.
305- # In the meantime, by converting to an `AnnotatedString` we can just
306- # reuse all the work done to make that work.
307- write (io, read (aio, AnnotatedString))
308- else
309- write (io, aio. io)
310- end
311- end
287+ Base. AnnotatedDisplay. show_annot (io:: IO , :: MIME"text/html" , s:: Union{<:AnnotatedString, SubString{<:AnnotatedString}} ) =
288+ show_html (io, s)
289+
290+ # End AnnotatedDisplay hooks
291+ # ------------
312292
313293"""
314294A mapping between ANSI named colors and 8-bit colors for use in HTML
@@ -447,7 +427,7 @@ function htmlstyle(io::IO, face::Face, lastface::Face=getface())
447427 print (io, " \" >" )
448428end
449429
450- function Base . show (io:: IO , :: MIME"text/html" , s:: Union{<:AnnotatedString, SubString{<:AnnotatedString}} )
430+ function show_html (io:: IO , s:: Union{<:AnnotatedString, SubString{<:AnnotatedString}} )
451431 # We need to make sure that the customisations are loaded
452432 # before we start outputting any styled content.
453433 load_customisations! ()
0 commit comments