Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support display of arbitrary textual MIME types in REPL #19993

Merged
merged 1 commit into from
Jan 21, 2017

Conversation

stevengj
Copy link
Member

By default, the REPL displays objects in text/plain format, but if you explicitly call display("text/foo", x) then this PR allows it to print.

e.g. it was noted by @cstjean on discourse that the inability to do display("text/csv", matrix) was annoying. This now works.

Also as noted by @cstjean, the exception thrown by display("text/foo", x) was somewhat confusing if the problem is the lack of a show method for text/foo. After this PR, it throws the expected MethodError for show (rather than a MethodError for display).

… error if show(io, MIME, x) is not defined during display
@stevengj stevengj added the io Involving the I/O subsystem: libuv, read, write, etc. label Jan 12, 2017
@cstjean
Copy link
Contributor

cstjean commented Jan 12, 2017

Thanks!

By default, the REPL displays objects in text/plain format

Interestingly, display("text/plain", rand(40, 2)) prints the whole array in IJulia, but it gets abridged at the REPL. If that's not the proper way of displaying the whole array, what is? "text/csv"? writedlm?

stevengj added a commit to JuliaLang/IJulia.jl that referenced this pull request Jan 12, 2017
@stevengj
Copy link
Member Author

stevengj commented Jan 12, 2017

show(STDOUT, "text/plain", x) will do it.

Seems like we should support a 2-arg version show("text/plain", x) via

show(m::MIME, x) = show(STDOUT, m, x)
show(m::AbstractString, x) = show(MIME(m), x)

@stevengj
Copy link
Member Author

(I fixed the IJulia inconsistency in JuliaLang/IJulia.jl@8f92249, thanks.)

@kshyatt kshyatt added display and printing Aesthetics and correctness of printed representations of objects. REPL Julia's REPL (Read Eval Print Loop) labels Jan 12, 2017
@stevengj
Copy link
Member Author

Should be ready to merge.

@stevengj stevengj merged commit 8950cf8 into JuliaLang:master Jan 21, 2017
@stevengj stevengj deleted the textdisplay branch January 21, 2017 20:30
@stevengj
Copy link
Member Author

@StefanKarpinski, yes, I ran into this in JuliaPy/PyPlot.jl#281 as well. I'm thinking that maybe the REPL display should override displayable so that it only returns true for text/plain. If you explicitly call display("text/html", x) then it will still work (printing the HTML text), however.

@tlnagy
Copy link
Contributor

tlnagy commented Feb 23, 2017

So this change breaks Compose.jl on v0.6 since we depend on the @try_display macro.

import Base.Multimedia: @try_display, xdisplayable

function display(p::Context)
    displays = Base.Multimedia.displays
    for i = length(displays):-1:1
        m = default_mime()
        if xdisplayable(displays[i], m, p)
             @try_display return display(displays[i], m, p)
        end

        if xdisplayable(displays[i], p)
            @try_display return display(displays[i], p)
        end
    end
    invoke(display, Tuple{Any}, p)
end

https://github.com/GiovineItalia/Compose.jl/blob/master/src/Compose.jl#L227-L242

How to you recommend doing this with this change?

@stevengj
Copy link
Member Author

stevengj commented Feb 23, 2017

@tlnagy, you shouldn't be overriding display in the first place. Override show.

The only reason to override display is if you are defining a new Display type, which is not the case in Compose.

@stevengj
Copy link
Member Author

@tlnagy
Copy link
Contributor

tlnagy commented Feb 23, 2017

I'm not sure why we have that in the Compose codebase. It looks like Daniel added that 3 years ago. I'll try and strip it out and see what happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects. io Involving the I/O subsystem: libuv, read, write, etc. REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants