I'm trying to create a specialized pretty-print function for a Julia struct that will output in the desired way to a Jupyter nb. My specialized show obviously works if I just blat one of the structs as the result of the nb frame, but not if I call show in code:
using Printf
struct foo
bar
end
show(io::IO, ::MIME"text/plain", f::foo) = @printf(io, "A Foo with Bar=%s!!!",f.bar)
f1=foo(1234)
show(f1) # A
f1 # B
Output (with # comments added):
foo(1234) # This comes from the inline show (A)
A Foo with Bar=1234!!! # This is the result that's just blatted out from the eval (B)
I've tried many version of this -- importing and over-riding Base.show, using print and println instead of show, and importing/overriding those, and so on and so forth. Many versions work like above. Some break in various predictable ways, but no combination that I've tried lets me output into the nb stream through my specialized fn (i.e., I want #A to look like #B). I'm sure it's simple, but I'm obviously just missing something