IJulia.jl
IJulia.jl copied to clipboard
Have less() display output in pager
Currently the less
function and @less
macro just print to stdout
and display their output in the cell directly. This can significantly slow down the browser if the source file is large. It would be great if InteractiveUtils.page(file, line)
could be redefined to display in the Notebook/Lab's pager like the %page
magic in IPython.
Looks like it should be straightforward, since there is a pager "payload" message defined in the messaging spec: https://jupyter-client.readthedocs.io/en/stable/messaging.html#payloads-deprecated
It is listed as "deprecated", but this seems to have been the case for many years now, and it's not clear any replacement is in sight, so we might as well use it.
On the Julia side, I'm not sure of the best way to replace the default implementation in InteractiveUtils.less
… might require a patch to InteractiveUtils to make this pluggable...
I guess IJulia could just define its own Main.less
and Main.@less
functions to replace those in InteractiveUtils
Huh, well using that link I managed to get something working in the single-page notebook view:
function page(mimebundle::Dict{String,String}, line::Int=1)
push!(IJulia.execute_payloads, Dict(
"source" => "page",
"data" => mimebundle,
"start" => line,
))
return nothing
end
page(mime::MIME, data, line::Int=1) = page(Dict(string(mime) => data), line)
page(str::String, line::Int=1) = page(MIME"text/plain"(), str, line)
s = join(["line $i" for i in 1:500], "\n")
page(s, 200)
but I didn't realize that the pager is no longer supported for the Lab, so it just prints it in the cell output anyway. Is there a way to achieve a similar effect in the Lab?
@Carreau, do you know what the plans are for the Jupyter pager?