From 9fd4dff0f42ffe5be94697d0ca274361907bd52c Mon Sep 17 00:00:00 2001 From: Richard Plevin Date: Mon, 20 May 2019 17:13:23 -0700 Subject: [PATCH] Alternate `show` methods for `print` and for REPL results. --- src/core/model.jl | 52 +++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/core/model.jl b/src/core/model.jl index a977b4c5c..6d5d049a8 100644 --- a/src/core/model.jl +++ b/src/core/model.jl @@ -400,33 +400,41 @@ function Base.run(m::Model; ntimesteps::Int=typemax(Int), nothing end -function Base.show(io::IO, obj::Model) - print(io, "Model\n") +function _show(io::IO, obj::Model, which::Symbol) + + println(io, "Mimi.Model") md = obj.md mi = obj.mi - print(io, " Module: $(md.module_name)\n") - print(io, " Dimensions:\n") - for (k, v) in md.dimensions - print(io, " $k => $v\n") - end - - print(io, " Components:\n") + println(io, " Module: $(md.module_name)") + + println(io, " Components:") for comp in values(md.comp_defs) - print(io, " $(comp.comp_id)\n") + println(io, " $(comp.comp_id)") end - - print(io, " Internal Connections:\n") - for conn in md.internal_param_conns - print(io, " $(conn)\n") + + if which == :full + println(io, " Dimensions:") + for (k, v) in md.dimensions + println(io, " $k => $v") + end + + println(io, " Internal Connections:") + for conn in md.internal_param_conns + println(io, " $(conn)") + end + + println(io, " External Connections:") + for conn in md.external_param_conns + println(io, " $(conn)") + end + + println(io, " Backups: $(md.backups)") + println(io, " Number type: $(md.number_type)") end + println(io, " Built: $(mi !== nothing)") +end - print(io, " External Connections:\n") - for conn in md.external_param_conns - print(io, " $(conn)\n") - end +Base.show(io::IO, obj::Model) = _show(io, obj, :full) - print(io, " Backups: $(md.backups)\n") - print(io, " Number type: $(md.number_type)\n") - print(io, " Built: $(mi !== nothing)\n") -end +Base.show(io::IO, ::MIME"text/plain", obj::Model) = _show(io, obj, :short)