@@ -225,8 +225,7 @@ function termstyle(io::IO, face::Face, lastface::Face=getface())
225
225
ANSI_STYLE_CODES. end_reverse))
226
226
end
227
227
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 }
230
229
# We need to make sure that the customisations are loaded
231
230
# before we start outputting any styled content.
232
231
load_customisations! ()
@@ -255,22 +254,13 @@ function _ansi_writer(io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedS
255
254
end
256
255
end
257
256
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
260
259
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 )
263
262
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 )
274
264
if get (io, :color , false ) == true
275
265
termstyle (io, getface (c), getface ())
276
266
bytes = write (io, c. char)
@@ -281,9 +271,7 @@ function Base.write(io::IO, c::AnnotatedChar)
281
271
end
282
272
end
283
273
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 )
287
275
if get (io, :color , false ) == true
288
276
out = IOBuffer ()
289
277
show (out, c. char)
@@ -296,19 +284,8 @@ function Base.show(io::IO, c::AnnotatedChar)
296
284
end
297
285
end
298
286
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
+ # End AnnotatedDisplay hooks
288
+ # ------------
312
289
313
290
"""
314
291
A mapping between ANSI named colors and 8-bit colors for use in HTML
0 commit comments