Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/crayon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function Base.print(io::IO, x::Crayon)
end
end

function Base.show(io::IO, x::Crayon)
function Base.show(io::IO, ::MIME"text/plain", x::Crayon)
if anyactive(x)
print(io, x)
print(io, ESCAPED_CSI)
Expand Down
1 change: 1 addition & 0 deletions src/crayon_stack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ struct CrayonStack
end

Base.print(io::IO, cs::CrayonStack) = print(io, cs.crayons[end])
Base.show(io::IO, ::MIME"text/plain", cs::CrayonStack) = show(io, MIME("text/plain"), cs.crayons[end])

function CrayonStack(; incremental::Bool = false)
CrayonStack(incremental, [Crayon(ANSIColor(0x9, COLORS_16, !incremental),
Expand Down
16 changes: 13 additions & 3 deletions src/crayon_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@ function (c::Crayon)(args::Union{CrayonWrapper,AbstractString}...)
CrayonWrapper(c, typefix.(collect(args)))
end

Base.show(io::IO, cw::CrayonWrapper) = _show(io, cw, CrayonStack(incremental = true))
Base.print(io::IO, cw::CrayonWrapper) = _print(io, cw, CrayonStack(incremental = true))
_print(io::IO, str::String, stack::CrayonStack) = print(io, str)
function _print(io::IO, cw::CrayonWrapper, stack::CrayonStack)
print(io, push!(stack, cw.c))
for obj in cw.v
_print(io, obj, stack)
end
length(stack.crayons) > 1 && print(io, pop!(stack))
return
end

Base.show(io::IO, ::MIME"text/plain", cw::CrayonWrapper) = _show(io, cw, CrayonStack(incremental = true))
_show(io::IO, str::String, stack::CrayonStack) = print(io, str)

function _show(io::IO, cw::CrayonWrapper, stack::CrayonStack)
show(io, MIME("text/plain"), cw.c)
print(io, push!(stack, cw.c))
for obj in cw.v
_show(io, obj, stack)
end
length(stack.crayons) > 1 && print(io, pop!(stack))
length(stack.crayons) > 1 && show(io, MIME("text/plain"), pop!(stack))
return
end

Expand Down