Skip to content

Commit 5722d21

Browse files
committed
minor modification
1 parent f574b3d commit 5722d21

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

src/rendering.jl

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using Term
22

33
const TRACE_COLORS = ("bright_green", "hot_pink", "bright_blue", "light_coral", "bright_cyan", "sandy_brown", "violet")
44

5-
Base.show(io::IO, ::MIME"text/plain", t::Union{Trace,Traces,Episode,Episodes}) = tprint(io, convert(Term.AbstractRenderable, t; width=displaysize(io)[2]) |> string)
5+
Base.show(io::IO, ::MIME"text/plain", t::Union{Trace,Traces,Episode,Episodes,Trajectory}) = tprint(io, convert(Term.AbstractRenderable, t; width=displaysize(io)[2]) |> string)
66

77
inner_convert(::Type{Term.AbstractRenderable}, s::String; style="gray1", width=88) = Panel(s, width=width, style=style, justify=:center)
88
inner_convert(t::Type{Term.AbstractRenderable}, x::Union{Symbol,Number}; kw...) = inner_convert(t, string(x); kw...)
@@ -63,7 +63,8 @@ function Base.convert(::Type{Term.AbstractRenderable}, t::Traces; width=88)
6363
style="yellow3",
6464
subtitle="$N traces in total",
6565
subtitle_justify=:right,
66-
width=width
66+
width=width,
67+
fit=true
6768
)
6869
end
6970

@@ -74,7 +75,8 @@ function Base.convert(::Type{Term.AbstractRenderable}, e::Episode; width=88)
7475
style="green_yellow",
7576
subtitle=e[] ? "Episode END" : "Episode growing...",
7677
subtitle_justify=:right,
77-
width=width
78+
width=width,
79+
fit=true
7880
)
7981
end
8082

@@ -99,6 +101,35 @@ function Base.convert(::Type{Term.AbstractRenderable}, e::Episodes; width=88)
99101
subtitle="$n episodes in total",
100102
subtitle_justify=:right,
101103
width=width,
104+
fit=true,
102105
style="wheat1"
103106
)
104-
end
107+
end
108+
109+
function Base.convert(r::Type{Term.AbstractRenderable}, t::Trajectory; width=88)
110+
Panel(
111+
convert(r, t.container; width=width - 8) /
112+
Panel(convert(Term.Tree, t.sampler); title="sampler", style="yellow3", fit=true, width=width - 8) /
113+
Panel(convert(Term.Tree, t.controler); title="controler", style="yellow3", fit=true, width=width - 8);
114+
title="Trajectory",
115+
style="yellow3",
116+
width=width,
117+
fit=true
118+
)
119+
end
120+
121+
# general converter
122+
123+
Base.convert(::Type{Term.Tree}, x) = Tree(to_tree_body(x); title=to_tree_title(x))
124+
Base.convert(::Type{Term.Tree}, x::Tree) = x
125+
126+
function to_tree_body(x)
127+
pts = propertynames(x)
128+
if length(pts) > 0
129+
Dict("$p => $(summary(getproperty(x, p)))" => to_tree_body(getproperty(x, p)) for p in pts)
130+
else
131+
x
132+
end
133+
end
134+
135+
to_tree_title(x) = "$(summary(x))"

0 commit comments

Comments
 (0)