Skip to content

Commit

Permalink
Treat printing as more than a nothing-return write
Browse files Browse the repository at this point in the history
As raised in <JuliaLang/julia#55198>, once
we look at AbstractString types outside of Core/Base, their print
methods can be meaningfully different to write + returning nothing.

As such, instead of delegating printing to write, we need to call
_ansi_writer asking it to use the print function.
  • Loading branch information
tecosaur committed Jul 25, 2024
1 parent 43fb018 commit 987f776
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ write(io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}) =
_ansi_writer(io, s, write)::Int

print(io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}) =
(_ansi_writer(io, s, print); nothing)

# We need to make sure that printing to an `AnnotatedIOBuffer` calls `write` not `print`
# so we get the specialised handling that `_ansi_writer` doesn't provide.
print(io::Base.AnnotatedIOBuffer, s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}) =
(write(io, s); nothing)

escape_string(io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedString}},
Expand Down

0 comments on commit 987f776

Please sign in to comment.