@@ -199,3 +199,79 @@ function _insert_annotations!(io::AnnotatedIOBuffer, annotations::Vector{RegionA
199
199
push! (io. annotations, setindex (annotations[index], start+ offset: stop+ offset, :region ))
200
200
end
201
201
end
202
+
203
+ # NOTE: This is an interim solution to the invalidations caused
204
+ # by the split styled display implementation. This should be
205
+ # replaced by a more robust solution (such as a consolidation of
206
+ # the type and method definitions) in the near future.
207
+ module AnnotatedDisplay
208
+
209
+ using .. Base: IO, SubString, AnnotatedString, AnnotatedChar, AnnotatedIOBuffer
210
+ using .. Base: eachregion, invoke_in_world, tls_world_age
211
+
212
+ # Write
213
+
214
+ ansi_write (f:: Function , io:: IO , x:: Any ) = f (io, x)
215
+
216
+ ansi_write_ (f:: Function , io:: IO , @nospecialize (x:: Any )) =
217
+ invoke_in_world (tls_world_age (), ansi_write, f, io, x)
218
+
219
+ Base. write (io:: IO , s:: Union{<:AnnotatedString, SubString{<:AnnotatedString}} ) =
220
+ ansi_write_ (write, io, s):: Int
221
+
222
+ Base. write (io:: IO , c:: AnnotatedChar ) =
223
+ ansi_write_ (write, io, c):: Int
224
+
225
+ function Base. write (io:: IO , aio:: AnnotatedIOBuffer )
226
+ if get (io, :color , false ) == true
227
+ # This does introduce an overhead that technically
228
+ # could be avoided, but I'm not sure that it's currently
229
+ # worth the effort to implement an efficient version of
230
+ # writing from a AnnotatedIOBuffer with style.
231
+ # In the meantime, by converting to an `AnnotatedString` we can just
232
+ # reuse all the work done to make that work.
233
+ ansi_write_ (write, io, read (aio, AnnotatedString)):: Int
234
+ else
235
+ write (io, aio. io)
236
+ end
237
+ end
238
+
239
+ # Print
240
+
241
+ Base. print (io:: IO , s:: Union{<:AnnotatedString, SubString{<:AnnotatedString}} ) =
242
+ (ansi_write_ (write, io, s); nothing )
243
+
244
+ Base. print (io:: IO , s:: AnnotatedChar ) =
245
+ (ansi_write_ (write, io, s); nothing )
246
+
247
+ Base. print (io:: AnnotatedIOBuffer , s:: Union{<:AnnotatedString, SubString{<:AnnotatedString}} ) =
248
+ (write (io, s); nothing )
249
+
250
+ Base. print (io:: AnnotatedIOBuffer , c:: AnnotatedChar ) =
251
+ (write (io, c); nothing )
252
+
253
+ # Escape
254
+
255
+ Base. escape_string (io:: IO , s:: Union{<:AnnotatedString, SubString{<:AnnotatedString}} ,
256
+ esc = " " ; keep = (), ascii:: Bool = false , fullhex:: Bool = false ) =
257
+ (ansi_write_ ((io, s) -> escape_string (io, s, esc; keep, ascii, fullhex), io, s); nothing )
258
+
259
+ # Show
260
+
261
+ show_annot (io:: IO , :: Any ) = nothing
262
+ show_annot (io:: IO , :: MIME , :: Any ) = nothing
263
+
264
+ show_annot_ (io:: IO , @nospecialize (x:: Any )) =
265
+ invoke_in_world (tls_world_age (), show_annot, io, x)
266
+
267
+
268
+ show_annot_ (io:: IO , m:: MIME , @nospecialize (x:: Any )) =
269
+ invoke_in_world (tls_world_age (), show_annot, io, m, x)
270
+
271
+ Base. show (io:: IO , m:: MIME"text/html" , s:: Union{<:AnnotatedString, SubString{<:AnnotatedString}} ) =
272
+ show_annot_ (io, m, s)
273
+
274
+ Base. show (io:: IO , m:: MIME"text/html" , c:: AnnotatedChar ) =
275
+ show_annot_ (io, m, c)
276
+
277
+ end
0 commit comments