ronisbr / TerminalPager.jl

Pure Julia implementation of the command less
MIT License
115 stars 8 forks source link

Paging during the command execution #36

Open astrozot opened 2 weeks ago

astrozot commented 2 weeks ago

I am not sure this is possible, but it would be extremely useful to have TerminalPager work during the execution of a slow command. That would allow one, for example, to monitor the execution of slow scripts on remote servers.

ronisbr commented 2 weeks ago

Hi @astrozot !

This feature would be awesome, indeed! I think we can do this by using tasks and stdout redirection. Do you have an example of such slow process by any change so I can use it to test?

astrozot commented 2 weeks ago

Hi @ronisbr ,

thank you for your quick reply! Sure, here is a very simple function for your tests:

function f(n)
    for i in 1:n
        println(i)
        sleep(1)
    end
    println("done")
end

Ideally, one would like to see the output of @stdout_to_pager f(5) immediately, rather than after 5 seconds.

Thank you again and let me know if I can help any further.

ronisbr commented 2 weeks ago

The problem with that code is that it yields during println and sleep. For some other workload that does not yield, the task with TerminalPager will be locked. I will investigate if there is some workaround.