Display() of an Array type showing unwanted info

Hello

Here is a snippet that illustrates my problem:

const Asn = Array{Tuple{String,Int64},1}
Base.summary(io::IO, x::Asn) = 
    print(io, *([s[1] for s in x]...), " = ", *([s[2] for s in x]...))
Base.show(io::IO, x::Asn) = print(io, summary(x))

x = Asn([("a",1),("b",2),("c",3)]);
display(x)

The output of this code is:

abc = 6:
 ("a", 1)
 ("b", 2)
 ("c", 3)

I would like to have this shorter output instead, similar to a print(x):

abc = 6

Would you have some suggestion on how to do this?
Also, I would like to understand why the extra lines comes in the display.

Thanks,

Michel

1 Like

print(x) calls your 2-arg show method, but display calls this 3-arg method: @less show(stdout, MIME"text/plain"(), x). Which uses your summary, before printing the array contents as usual. So you need to overload Base.show(io::IO, ::MIME"text/plain", x::Asn) = ... to change that.

1 Like

Thanks! It works!