This commit is contained in:
Giorgio Calderone 2020-04-17 20:11:36 +02:00
parent 7b0955e12a
commit 31b60d61f2

View File

@ -739,6 +739,12 @@ end
# │ PRIVATE FUNCTIONS TO MANIPULATE SESSIONS │ # │ PRIVATE FUNCTIONS TO MANIPULATE SESSIONS │
# ╰───────────────────────────────────────────────────────────────────╯ # ╰───────────────────────────────────────────────────────────────────╯
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
function enableExportThroughShow()
return (isdefined(Main, :IJulia) && Main.IJulia.inited) ||
(isdefined(Main, :Juno) && Main.Juno.isactive())
end
function reset(gp::Session) function reset(gp::Session)
delete_binaries(gp) delete_binaries(gp)
gp.datas = OrderedDict{String, Dataset}() gp.datas = OrderedDict{String, Dataset}()
@ -750,8 +756,7 @@ function reset(gp::Session)
# When running in IJulia or Juno set the unknown terminal # When running in IJulia or Juno set the unknown terminal
# (trick copied from Gaston.jl) # (trick copied from Gaston.jl)
if (isdefined(Main, :IJulia) && Main.IJulia.inited) || if enableExportThroughShow()
(isdefined(Main, :Juno) && Main.Juno.isactive())
gpexec(gp, "set term unknown") gpexec(gp, "set term unknown")
else else
(options.term != "") && gpexec(gp, "set term " * options.term) (options.term != "") && gpexec(gp, "set term " * options.term)
@ -1505,7 +1510,8 @@ end
Base.show(gp::SessionID) = nothing Base.show(gp::SessionID) = nothing
Base.show(io::IO, gp::SessionID) = nothing Base.show(io::IO, gp::SessionID) = nothing
function Base.show(io::IO, ::MIME"image/svg+xml", gp::SessionID) function Base.show(io::IO, ::MIME"image/svg+xml", gp::SessionID)
if gp.dump if gp.dump && enableExportThroughShow()
println("SVG")
tmpfile = tempname()*".svg" tmpfile = tempname()*".svg"
save(gp.sid; term=options.term_svg, output=tmpfile) save(gp.sid; term=options.term_svg, output=tmpfile)
write(io, read(tmpfile)) write(io, read(tmpfile))
@ -1514,7 +1520,8 @@ function Base.show(io::IO, ::MIME"image/svg+xml", gp::SessionID)
nothing nothing
end end
function Base.show(io::IO, ::MIME"image/png", gp::SessionID) function Base.show(io::IO, ::MIME"image/png", gp::SessionID)
if gp.dump if gp.dump && enableExportThroughShow()
println("PNG")
tmpfile = tempname()*".png" tmpfile = tempname()*".png"
save(gp.sid; term=options.term_png, output=tmpfile) save(gp.sid; term=options.term_png, output=tmpfile)
write(io, read(tmpfile)) write(io, read(tmpfile))