Neptune.jl icon indicating copy to clipboard operation
Neptune.jl copied to clipboard

@printf?

Open dpo opened this issue 4 years ago • 3 comments

Is there a convenient way to print in Neptune (contrary to Pluto)?

dpo avatar Sep 30 '21 21:09 dpo

using PlutoUI
with_terminal() do
	println("BLA")
end

outputs nothing at all in a fresh Neptune notebook.

dpo avatar Oct 01 '21 22:10 dpo

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.

Screen Shot 2021-11-04 at 15 42 52

Colors don't appear to be working though.

dpo avatar Nov 04 '21 19:11 dpo

@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

kpa28-git avatar Dec 16 '21 10:12 kpa28-git