How to make own type explanation in Workspace for my type like HypothsisTest or GLM.
I see only type name and variable names, but for other types like GLM there are prety text output.
How to make own type explanation in Workspace for my type like HypothsisTest or GLM.
I see only type name and variable names, but for other types like GLM there are prety text output.
I assume you are talking about docstrings? If so, check out Documentation · The Julia Language
I think it’s rather pretty printing:
https://docs.julialang.org/en/v1/manual/types/#man-custom-pretty-printing-1
Hi, I am using this feature, but it leads only for changing in console output.
I try code:
struct ConfidenceInterval
lower::Real
upper::Real
estimate::Real
end
function Base.show(io::IO, ::MIME"text/plain", obj::ConfidenceInterval)
compact = get(io, :compact, false)
println(io, "Confidence interval:")
if compact
print(io, "Upper: $(obj.upper) , Lower: $(obj.lower)")
else
println(io, "Upper: ", obj.upper)
println(io, "Lower: ", obj.lower)
end
end
Docs.getdoc(obj::ConfidenceInterval) = "ConfidenceInterval $(obj.estimate)"
ci = ConfidenceInterval(2,1,3)
And this not help to get result like in green rectangle… only boring red…
You may find this code to be of interest:
I don’t know what io context the juno variable browser uses (maybe @pfitzseb can help), but the show function you defined should work if you do print(ci)
and look at the repl output
Right now you need to overload Base.show(io::IO, obj::ConfidenceInterval)
, and not the three argument form. This is consistent with what the help for show
says:
The default MIME type is
MIME"text/plain"
. There is a fallback definition fortext/plain
output that callsshow
with 2 arguments. Therefore, this case should be handled by defining a 2-argumentshow(io::IO, x::MyType)
method.
I think we can safely check for both forms though.
Thx! Its my fault:
Base.show(io::IO, obj::ConfidenceInterval)
instead of Base.show(io::IO, ::MIME"text/plain", obj::ConfidenceInterval)
works perfectly!