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

Have less() display output in pager

Open jlumpe opened this issue 5 years ago • 5 comments

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.

jlumpe avatar Dec 28 '19 00:12 jlumpe

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.

stevengj avatar Dec 31 '19 18:12 stevengj

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...

stevengj avatar Dec 31 '19 18:12 stevengj

I guess IJulia could just define its own Main.less and Main.@less functions to replace those in InteractiveUtils

stevengj avatar Dec 31 '19 18:12 stevengj

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?

jlumpe avatar Jan 01 '20 01:01 jlumpe

@Carreau, do you know what the plans are for the Jupyter pager?

stevengj avatar Jan 01 '20 14:01 stevengj