Skip to content

Commit 68bf7b1

Browse files
committed
Switch to new AnnotatedDisplay printstyled proxy
Continuing 3fe829f, we also want to position our `printstyled` implementation behind an inference barrier to reduce invalidations.
1 parent 1aafc2f commit 68bf7b1

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/io.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ end
291291
Base.AnnotatedDisplay.show_annot(io::IO, ::MIME"text/html", s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}) =
292292
show_html(io, s)
293293

294+
# Also see `legacy.jl:126` for `styled_write`.
295+
294296
# End AnnotatedDisplay hooks
295297
# ------------
296298

src/legacy.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,14 @@ function load_env_colors!()
123123
end
124124
end
125125

126-
function Base.printstyled(io::AnnotatedIOBuffer, msg...;
127-
bold::Bool=false, italic::Bool=false, underline::Bool=false,
128-
blink::Bool=false, reverse::Bool=false, hidden::Bool=false,
129-
color::Union{Symbol, Int}=:normal)
126+
# Part of the inference barrier around `Base.printstyled`
127+
function Base.AnnotatedDisplay.styled_print(io::AnnotatedIOBuffer, @nospecialize(msg::Tuple), @nospecialize(kwargs::Base.Pairs))
130128
str = annotatedstring(msg...)
131-
bold && face!(str, :bold)
132-
italic && face!(str, :italic)
133-
underline && face!(str, :underline)
134-
reverse && face!(str, :inverse)
129+
for attr in (:bold, :italic, :underline)
130+
get(kwargs, attr, false)::Bool && face!(str, attr)
131+
end
132+
get(kwargs, :reverse, false)::Bool && face!(str, :inverse)
133+
color = get(kwargs, :color, :normal)::Symbol
135134
color !== :normal && face!(str, Face(foreground=legacy_color(color)))
136135
write(io, str)
137136
nothing

0 commit comments

Comments
 (0)