diff --git a/base/strings/io.jl b/base/strings/io.jl index ba0890fe78edd..43c7b8ab156c1 100644 --- a/base/strings/io.jl +++ b/base/strings/io.jl @@ -979,18 +979,23 @@ end function print(io::IO, s::Union{<:StyledString, SubString{<:StyledString}}) if get(io, :color, false) == true - lastface = FACES[:default] + buf = IOBuffer() # Avoid the overhead in repeatadly printing to `stdout` + lastface::Face = FACES[:default] for (str, styles) in eachstyle(s) face = getface(styles) link = let idx=findfirst(==(:link) ∘ first, styles) - if !isnothing(idx) last(styles[idx]) end end - !isnothing(link) && print(io, "\e]8;;", link, "\e\\") - termstyle(io, face, lastface) - print(io, str) - !isnothing(link) && print(io, "\e]8;;\e\\") + if !isnothing(idx) + string(last(styles[idx]))::String + end end + !isnothing(link) && print(buf, "\e]8;;", link, "\e\\") + termstyle(buf, face, lastface) + print(buf, str) + !isnothing(link) && print(buf, "\e]8;;\e\\") lastface = face end - termstyle(io, FACES[:default], lastface) + termstyle(buf, FACES[:default], lastface) + write(io, take!(buf)) + nothing elseif s isa StyledString print(io, s.string) elseif s isa SubString