Modify show for custom type - for tuples


#1

I have a function which returns a 2-tuple. One of the elements of the tuple is an ‘instance’ of a custom type.
For this type I have overloaded the show function.
But when I run the function which returns a tuple, it falls back to the ‘default show’

Can someone help me with this?

See my MWE

mutable struct Mine
    x::Int64
    secret::Int64
end

m=Mine(2,3)

m #->ouput is Mine(2,3) as expected

function Base.show(io::IO, t::MIME"text/plain",x::Mine)
    #this is be my custom show function
    println(io,x.x)
end

m # terminal shows  2
#I successfully modified show, as intended

#a meaningless function
function do_something(x::Mine)
    y=deepcopy(x)    
    return "some string",y
end

a=do_something(m)
#here a is printed as ("some string", Mine(2, 3))
#I want it to be printed as ("some string", 2)

#I tried to look at these, but could not solve my problem
#@which show(m)
#@which show(("asd",m))


#2

I don’t really understand this Mime stuff, but I believe that what you want is to also overload Base.show(io::IO, x:: Mine) with the one-like printed version of your type.