Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,20 @@ function show(io::IO, c::AnnotatedChar)
end
end

function write(io::IO, aio::Base.AnnotatedIOBuffer)
if get(io, :color, false) == true
# This does introduce an overhead that technically
# could be avoided, but I'm not sure that it's currently
# worth the effort to implement an efficient version of
# writing from a AnnotatedIOBuffer with style.
# In the meantime, by converting to an `AnnotatedString` we can just
# reuse all the work done to make that work.
write(io, read(aio, AnnotatedString))
else
write(io, aio.io)
end
end

"""
A mapping between ANSI named colors and 8-bit colors for use in HTML
representations.
Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,17 @@ end
@test normal == styled == "abcdef"
end

@testset "AnnotatedIOBuffer" begin
aio = Base.AnnotatedIOBuffer()
@test write(aio, styled"{red:hey} {blue:there}") == 9
buf = IOBuffer()
@test write(buf, seekstart(aio)) == 9
@test String(take!(buf)) == "hey there"
cbuf = IOContext(buf, :color => true)
@test write(cbuf, seekstart(aio)) == 29
@test String(take!(buf)) == "\e[31mhey\e[39m \e[34mthere\e[39m"
end

@testset "Legacy" begin
@test StyledStrings.Legacy.legacy_color(:blue) == SimpleColor(:blue)
@test StyledStrings.Legacy.legacy_color(:light_blue) == SimpleColor(:bright_blue)
Expand Down