JuliaPluto / PlutoUI.jl

https://featured.plutojl.org/basic/plutoui.jl
The Unlicense
302 stars 55 forks source link

Real-time printing using `with_terminal` #49

Open mossr opened 4 years ago

mossr commented 4 years ago

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.

fonsp commented 4 years ago

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

mossr commented 4 years ago

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
fonsp commented 4 years ago

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

dralletje commented 4 years ago

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.

mossr commented 4 years ago

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!

DhruvaSambrani commented 3 years ago

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 commented 3 years ago

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.

fonsp commented 3 years ago

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

fonsp commented 3 years ago

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

CarloLucibello commented 3 years ago

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