Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@printf? #22

Open
dpo opened this issue Sep 30, 2021 · 3 comments
Open

@printf? #22

dpo opened this issue Sep 30, 2021 · 3 comments

Comments

@dpo
Copy link

dpo commented Sep 30, 2021

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

@dpo
Copy link
Author

dpo commented Oct 1, 2021

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

outputs nothing at all in a fresh Neptune notebook.

@dpo
Copy link
Author

dpo commented Nov 4, 2021

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.

@kpa28-git
Copy link

kpa28-git commented Dec 16, 2021

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants