From 0af21d06e79f6e77e5dcfad5166a5b4cb7b2921a Mon Sep 17 00:00:00 2001 From: TEC Date: Thu, 26 Oct 2023 19:25:17 +0800 Subject: [PATCH] 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. --- src/legacy.jl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/legacy.jl b/src/legacy.jl index 46fb31ac..e7c56692 100644 --- a/src/legacy.jl +++ b/src/legacy.jl @@ -6,7 +6,7 @@ module Legacy -using ..StyledStrings: SimpleColor, Face, loadface! +using ..StyledStrings: SimpleColor, Face, loadface!, face! """ A mapping from 256-color codes indicies to 8-bit colours. @@ -112,4 +112,18 @@ function load_env_colors!() end end +function Base.printstyled(io::Base.AnnotatedIOBuffer, msg...; + bold::Bool=false, italic::Bool=false, underline::Bool=false, + blink::Bool=false, reverse::Bool=false, hidden::Bool=false, + color::Union{Symbol, Int}=:normal) + str = Base.annotatedstring(msg...) + bold && face!(str, :bold) + italic && face!(str, :italic) + underline && face!(str, :underline) + reverse && face!(str, Face(inverse=true)) + color !== :normal && face!(str, Face(foreground=legacy_color(color))) + write(io, str) + nothing +end + end