Skip to content

Commit 0af21d0

Browse files
committed
printstyled specialisation for AnnotatedIOBuffer
This allows for providing an AnnotatedIOBuffer to various IO-accepting printing functions (e.g. show, showerror) and obtaining the annotations that would be formed from straightforwardly switching to StyledStrings.
1 parent a1b2ae2 commit 0af21d0

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/legacy.jl

+15-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
module Legacy
88

9-
using ..StyledStrings: SimpleColor, Face, loadface!
9+
using ..StyledStrings: SimpleColor, Face, loadface!, face!
1010

1111
"""
1212
A mapping from 256-color codes indicies to 8-bit colours.
@@ -112,4 +112,18 @@ function load_env_colors!()
112112
end
113113
end
114114

115+
function Base.printstyled(io::Base.AnnotatedIOBuffer, msg...;
116+
bold::Bool=false, italic::Bool=false, underline::Bool=false,
117+
blink::Bool=false, reverse::Bool=false, hidden::Bool=false,
118+
color::Union{Symbol, Int}=:normal)
119+
str = Base.annotatedstring(msg...)
120+
bold && face!(str, :bold)
121+
italic && face!(str, :italic)
122+
underline && face!(str, :underline)
123+
reverse && face!(str, Face(inverse=true))
124+
color !== :normal && face!(str, Face(foreground=legacy_color(color)))
125+
write(io, str)
126+
nothing
127+
end
128+
115129
end

0 commit comments

Comments
 (0)