Print SUnitRange within tuple as is, not as a vector

I am wondering how to coax show etc to print a StaticArrays.SUnitRange as is, not as a vector of indices. I tried the usual suspects for options in IOContext, didn’t work. I am not even sure if this is intended or a bug.

julia> using StaticArrays: SUnitRange

julia> s1 = SUnitRange{1,2}()
SUnitRange(1,2)

julia> x = (s1,s1)
([1, 2], [1, 2])

julia> show(IOContext(stdout, :compact => false, :limit => false), x)
([1, 2], [1, 2])
julia> x[1] # I want elements printed like this
SUnitRange(1,2)

SUnitRange is not an abstract range so it will fall back to array printing. It prints like SUnitRange(1,2) in the REPL because it has an overloaded MIME"text/plain" method. I don’t think there is a way for containers to have their elements to print as MIME"text/plain.

Perhaps StaticArrays is missing a standard show method for SUnitRange?

1 Like

Just playing around:

julia> Base.show(io::IOContext{Base.TTY},s1::SUnitRange{1,2}) = display(s1)

julia> show(x)
(SUnitRange(1,2)
, SUnitRange(1,2)
)

You probably want:

function Base.show(io::IO, s::SUnitRange{Start, L}) where {Start, L}
    show(io, MIME"text/plain"(), s)
end
2 Likes

Not me, perhaps Tamas. But exactly I intended that someone builds upon it.

1 Like

Thanks, PR done.

1 Like