# Add custom method to Base.show

**URL:** https://discourse.julialang.org/t/add-custom-method-to-base-show/82007
**Category:** New to Julia
**Created:** [May 31, 2022, 5:53pm UTC](https://discourse.julialang.org/t/add-custom-method-to-base-show/82007 "2022-05-31T17:53:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Brian1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brian1/32/49250_2.png) [@Brian1](https://discourse.julialang.org/u/Brian1)
#### Post date: [May 31, 2022, 5:53pm UTC](https://discourse.julialang.org/t/add-custom-method-to-base-show/82007/1 "2022-05-31T17:53:40Z")

</div>

I have a struct named A:

```julia
struct A
    dict::Dict
end

dict=Dict(:a=>1,:b=>2)

#show a dict in REPL(notebook in vscode)
Dict{Symbol, Int64} with 2 entries:
  :a => 1
  :b => 2

a=A(dict)

```

Then, I add a method to Base.show to show struct A:

```julia
Base.show(io::IO,a::A)=println(a.dict)

a
#show struct A in REPL
 Dict(:a => 1, :b => 2)

```

Here show A as :` Dict(:a => 1, :b => 2)`, but I would like to show A like the original show of a Dict:

```julia

Dict{Symbol, Int64} with 2 entries:
  :a => 1
  :b => 2

```

How can I change the `Base.show` method to do this?

---

<div class="post-metadata">

### Author: ![StevenWhitaker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevenwhitaker/32/9749_2.png) [@StevenWhitaker](https://discourse.julialang.org/u/StevenWhitaker)
#### Post date: [May 31, 2022, 6:21pm UTC](https://discourse.julialang.org/t/add-custom-method-to-base-show/82007/2 "2022-05-31T18:21:25Z")

</div>

Using `display` instead of `println` is one way, though I would probably do something like

```julia
julia> Base.show(io::IO, a::A) = show(io, a.dict) # For one-line printing

julia> Base.show(io::IO, ::MIME"text/plain", a::A) = show(io, "text/plain", a.dict) # For multiline printing

```

(And I would also make sure the printed information explains that `a` is _not_ a `Dict`, but wraps one.)

See [Custom pretty-printing](https://docs.julialang.org/en/v1/manual/types/#man-custom-pretty-printing) for more details.

---

<div class="post-metadata">

### Author: ![Brian1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brian1/32/49250_2.png) [@Brian1](https://discourse.julialang.org/u/Brian1)
#### Post date: [June 1, 2022, 1:28am UTC](https://discourse.julialang.org/t/add-custom-method-to-base-show/82007/3 "2022-06-01T01:28:43Z")

</div>

Yes, thanks, it works fine. The argument `text/plain` for `Base.show` is automattically turned to a `MIME` type, weird and amazing to me.
