Skip to content

Commit

Permalink
Merge pull request #91 from fonsp/ijulia-display-fix
Browse files Browse the repository at this point in the history
IJulia & Juno display fix
  • Loading branch information
cormullion authored Jun 14, 2020
2 parents 619895d + c28076c commit 1f67cb3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/drawings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,21 @@ current_bufferdata() = getfield(CURRENTDRAWING[1], :bufferdata)
# are shortcuts to file-based drawings.) When a drawing is
# finished, you go `finish()` (that's the last line of the
# @... macros.). Then, if you want to actually see it, you
# go `preview()`.
# go `preview()`, which returns the current drawing.

# Then the code has to decide where you're working, and what
# type of file it is, then sends it to the right place,
# depending on the OS.

function Base.show(io::IO, ::MIME"text/plain", d::Drawing)
returnvalue = d.filename
# IJulia and Juno call the `show` function twice: once for
# the image MIME and a second time for the text/plain MIME.
# We check if this is such a 'second call':
if (get(io, :jupyter, false) || Juno.isactive()) && (d.surfacetype == :svg || d.surfacetype == :png)
return
end
# otherwise, we open the image file
if Sys.isapple()
run(`open $(returnvalue)`)
elseif Sys.iswindows()
Expand All @@ -98,8 +105,6 @@ function Base.show(io::IO, ::MIME"text/plain", d::Drawing)
elseif Sys.isunix()
run(`xdg-open $(returnvalue)`)
end
# print(io, returnvalue)
nothing
end

function tidysvg(m::MIME"image/svg+xml", fname)
Expand Down Expand Up @@ -547,7 +552,7 @@ macro draw(body, width=600, height=600)
sethue("black")
$(esc(body))
finish()
CURRENTDRAWING[1]
preview()
end
end

Expand Down

0 comments on commit 1f67cb3

Please sign in to comment.