From d39d1c38ffdebae642dd415842698cbc28b503f3 Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Sat, 5 Feb 2022 16:35:46 -0500 Subject: [PATCH 1/3] shorten leaf printing --- src/interface.jl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index f20c7370..01530985 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -120,8 +120,11 @@ onevalue(λ, x::AbstractArray{T}) where T = onevalue(convert(float(T), λ), x) function Base.show(io::IO, ℓ::Leaf) # show method is mostly to hide its long type! ioc = IOContext(io, :compact => true) - print(ioc, "Leaf(", ℓ.rule, ", ") - show(ioc, ℓ.state) - print(io, ")") + printstyled(io, "Leaf("; color = :green) + show(ioc, ℓ.rule) + printstyled(", "; color = :green) + str = sprint(show, ℓ.state; context = ioc) + print(io, length(str) < 70 ? str : first(str, 50) * " … ") + printstyled(io, ")"; color = :green) end From 60d5a98a9ada70b4ca1302885935fadb492172df Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Tue, 7 Jun 2022 21:49:27 -0400 Subject: [PATCH 2/3] simpler, more green --- src/interface.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index 01530985..d2e3f85a 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -118,11 +118,10 @@ Broadcast.materialize(x::Lazy) = Broadcast.instantiate(x.bc) onevalue(λ::T, x::AbstractArray{T}) where T = map(_ -> λ, x) onevalue(λ, x::AbstractArray{T}) where T = onevalue(convert(float(T), λ), x) -function Base.show(io::IO, ℓ::Leaf) # show method is mostly to hide its long type! +function Base.show(io::IO, ℓ::Leaf) ioc = IOContext(io, :compact => true) - printstyled(io, "Leaf("; color = :green) - show(ioc, ℓ.rule) - printstyled(", "; color = :green) + str = sprint(show, ℓ.rule; context = ioc) + printstyled(io, "Leaf(", str, ", "; color = :green) str = sprint(show, ℓ.state; context = ioc) print(io, length(str) < 70 ? str : first(str, 50) * " … ") printstyled(io, ")"; color = :green) From 83f0ebf9029690614a1ad936eb06a3a10306ab80 Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Tue, 7 Jun 2022 22:00:56 -0400 Subject: [PATCH 3/3] green ... to make clearer who owns the truncation --- src/interface.jl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index d2e3f85a..d7e26f11 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -123,7 +123,12 @@ function Base.show(io::IO, ℓ::Leaf) str = sprint(show, ℓ.rule; context = ioc) printstyled(io, "Leaf(", str, ", "; color = :green) str = sprint(show, ℓ.state; context = ioc) - print(io, length(str) < 70 ? str : first(str, 50) * " … ") - printstyled(io, ")"; color = :green) + if length(str) < 80 + print(io, str) + printstyled(io, ")"; color = :green) + else + print(io, first(str, 66)) + printstyled(io, " ...)"; color = :green) + end end