KristofferC / Crayons.jl

Colored and styled strings for terminals.
Other
150 stars 14 forks source link

overriding `Base.show` with Crayon act differently than `printstyled` #61

Closed YongHee-Kim closed 2 years ago

YongHee-Kim commented 2 years ago

This was what I've been doing

using Printf
struct Foo
       val
end
function Base.show(io::IO, x::Foo)
    print(io, "Foo=")
    printstyled(io,x.val; color=:yellow)
end

julia>string(Foo(10))
"Foo=10"

And I tired to replace printstyled with Crayons

using Crayons 
struct Foo
       val
end

function Base.show(io::IO, x::Foo)
       print(io, "Foo=", Crayon(forecround=:yellow), x.val)
end
julia>string(Foo(10))
"Foo=\e[33m10"

Is there way for me to make string conversion work as before? without overriding the string method

YongHee-Kim commented 2 years ago

I'm closing this because it's duplicate of https://github.com/KristofferC/Crayons.jl/issues/47