Created
April 10, 2016 20:01
-
-
Save 0x09/74faf5fada63b8c93d48f55f899ddb92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Base.Display, Base.display | |
immutable iTermDisplay <: Display end | |
itshowim(x::Vector{UInt8}) = write(STDOUT, "\e]1337;File=inline=1:", base64encode(x), "\a") | |
const itmimetypes = map(MIME, ["application/pdf","application/postscript","image/tiff","image/png","image/jpeg","image/jp2","image/vnd.adobe.photoshop"]) | |
function display(::iTermDisplay, m::Union{map(typeof, itmimetypes)...}, x) | |
itshowim(reprmime(m,x)) | |
nothing | |
end | |
function display(d::iTermDisplay, x) | |
mime = findfirst(m->mimewritable(m, x), itmimetypes) | |
if mime == 0 | |
throw(MethodError(display, (d, x))) | |
end | |
display(d ,itmimetypes[mime], x) | |
end | |
if ENV["TERM_PROGRAM"] == "iTerm.app" && !(iTermDisplay() in Base.Multimedia.displays) | |
pushdisplay(iTermDisplay()) | |
end | |
nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment