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

Real-time printing using `with_terminal`

Open mossr opened this issue 5 years ago • 10 comments

Not sure if this is being discussed elsewhere, but I would be important to have with_terminal (or a macro version) that could print out in real-time (instead of all at once after execution).

E.g.

with_terminal() do
    for i in 1:10
        println(i)
        sleep(0.1)
    end
end

We'd want this to print 1 2 etc. every 10th of a second and not all at once.

mossr avatar Oct 03 '20 21:10 mossr

Unfortunately this is far from trivial: https://github.com/fonsp/Pluto.jl/issues/476

fonsp avatar Oct 05 '20 18:10 fonsp

That was my fear.

I'm also curious (and maybe spin out to a separate issue) about running something to mark a document as globally running with_terminal() around every cell (or something similar).

Something like:

global_with_terminal(true)

Then other cells would just proceed as normal:

println("Hello world!")

Instead of

with_terminal() do
    println("Hello world!")
end

mossr avatar Oct 05 '20 22:10 mossr

No, Pluto will probably never support side effects like the one you suggested

fonsp avatar Oct 05 '20 22:10 fonsp

We'll never support it buuuutttt... If https://github.com/fonsp/Pluto.jl/issues/476 gets implemented you could make something yourself that uses https://docs.julialang.org/en/v1/base/io-network/#Base.redirect_stdout and sends the output to the client.

This wouldnt wrap every cell in a with_terminal(), rather it would make one terminal with all the output.

dralletje avatar Oct 08 '20 01:10 dralletje

When you say

make one terminal with all the output

you mean one Pluto cell (i.e. the "with_terminal" terminal), right? That'd be really cool!

mossr avatar Oct 08 '20 02:10 mossr

Since we are discussing the global_with_terminal thing, can a UI element be added to the right, above the live docs, which emulates the terminal? Then, each cell need not be wrapped around a with_terminal?

I do not get why this would have side effects though. Isn't the output to repl stdout the same as putting it into a UI element instead? This UI element is not stored in the NB, just like LiveDocs isn't.

DhruvaSambrani avatar Nov 16 '20 18:11 DhruvaSambrani

Ok, I see how the global_with_terminal thing is problematic. But how about this? A new UI element is added(called Terminal?), which @binds with an IOStream(or io) object, and displays asynchronously everything that is in the stream in real time. with_realtime_terminal can then be added to also take in a Terminal object, and it will redirect all stdout to the stream of the Terminal object.

DhruvaSambrani avatar Nov 25 '20 18:11 DhruvaSambrani

Yep, we should make with_terminal asynchronous, but this https://github.com/fonsp/PlutoUI.jl/labels/needs%20Pluto.jl%20feature

fonsp avatar Nov 26 '20 15:11 fonsp

I should say that I am not very interested in this feature, but what I am excited about is https://github.com/fonsp/Pluto.jl/pull/437 which should solve roughly the same use case in a less vintage way. It's coming in about 2 months

fonsp avatar Nov 26 '20 15:11 fonsp

fonsp/Pluto.jl#437 seems to solve only minimalistic printing needs. For more serious printing we need vertical space.

CarloLucibello avatar Oct 20 '21 09:10 CarloLucibello