# Overload show and keep default Juno rendering

**URL:** <https://discourse.julialang.org/t/overload-show-and-keep-default-juno-rendering/14312>\
**Category:** General Usage\
**Tags:** juno\
**Created:** [August 30, 2018, 12:25pm UTC](https://discourse.julialang.org/t/overload-show-and-keep-default-juno-rendering/14312 "2018-08-30T12:25:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![saschatimme](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/saschatimme/32/10313_2.png) [@saschatimme](https://discourse.julialang.org/u/saschatimme)\
**Post date:** [August 30, 2018, 12:25pm UTC](https://discourse.julialang.org/t/overload-show-and-keep-default-juno-rendering/14312/1 "2018-08-30T12:25:33Z")

</div>

Assume I have custom type

```julia
struct Foo
    x::Int
end

```

for which I want do define pretty printing. If I overload `Base.show(io, x)`

```julia
Base.show(io::IO, foo::Foo) = print(io, "Foo with value $(foo.x)")

```

everything works great, but I loose the default tree view rendering in Juno.  
If I instead just define

```julia
Base.show(io::IO, ::MIME"text/plain", foo::Foo) = print(io, "Foo with value $(foo.x)")

```

then I still have the nice inline tree view in Juno, but now the printing doesn’t work anymore e.g. in tuple

```julia
julia> (Foo(2),)
(Foo(2),)

```

Now I obviously could use `TreeViews.jl` to define my custom logic but this is quite tedious. Is there a way to keep the default inline rendering in Juno while I overload `Base.show(io, x)`?

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [August 30, 2018, 1:37pm UTC](https://discourse.julialang.org/t/overload-show-and-keep-default-juno-rendering/14312/2 "2018-08-30T13:37:12Z")

</div>

See the Juno docs:  
[http://docs.junolab.org/latest/man/info\_developer.html#Custom-Inline-Display-1](http://docs.junolab.org/latest/man/info_developer.html#Custom-Inline-Display-1)

Edit: Hm, didn’t read the end of your post 🙂

So, it should be sufficient to define `TreeViews.hastreeview(::Foo) = true`.  
I guess we could also special case `show(io::IO, ::MIME"application/juno+inline", ...)` as an alias for `text/plain` in Juno.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [August 30, 2018, 2:17pm UTC](https://discourse.julialang.org/t/overload-show-and-keep-default-juno-rendering/14312/3 "2018-08-30T14:17:50Z")

</div>

Okay, so I’ve gone ahead and added something like that [here](https://github.com/JunoLab/Atom.jl/commit/093e36d51f3654a579ab27e4614efbc715c2fc67).

Basically, you can now define a `show(io::IO, ::MIME"application/juno+inline", ::Foo)` method, which has a lower priority than the `TreeViews.jl` stuff, but a higher priority than `show(io::IO, MIME"text/plain", ::Foo)`. If you just print to `io` in that method then we’ll display that as we would `text/plain`, but if you return a object (which isn’t `nothing`) you’ll get the default Juno rendering for that object. This is a bit of an abuse of the display system, but w/e.

For your example you’d want

```julia
struct Foo
  x
end

Base.show(io::IO, ::Foo) = print(io, "Foo!")
Base.show(io::IO, ::MIME"application/juno+inline", x::Foo) = x

```

and get nice printing both in Juno and the REPL.
