Open dpo opened 3 years ago
using PlutoUI
with_terminal() do
println("BLA")
end
outputs nothing at all in a fresh Neptune notebook.
Put this together recently, which does the job
using IOCapture
import HypertextLiteral: @htl
function display_output(value, output)
# parts of this scavenged from PlutoUI
t = """<div style='display: inline; white-space: normal;'><pre style="
max-height: 300px;
overflow: auto;
white-space: pre;
color: white;
background-color: black;
border-radius: 3px;
margin-top: 4px;
margin-bottom: 4px;
padding: 5px;
display: block;
font-family: monospace;
font-size: 9pt;
">"""
t *= value == nothing ? "" : "<span>$(value)<br></span>"
for line in split(output, "\n")[1:(end-1)]
t *= "<span>$(line)<br></span>"
end
t *= "</pre></div>"
ex = :(@htl($t))
ex
end
macro show_output(cmd)
return quote
c = IOCapture.capture(color = true) do
eval($cmd)
end
ex = display_output(c.value, c.output)
eval(ex)
end
end
The above allows you to print in your functions, including logging, and showing the output in the Neptune notebook with the macro @show_output
.
Colors don't appear to be working though.
@dpo Thanks for this
I'm curious why loops like
for i in 1:5
@show_output i
end
don't work? It says i
is undefined
Is there a convenient way to print in Neptune (contrary to Pluto)?