AshlinHarris / Spinners.jl

Command line spinners in Julia with Unicode support
MIT License
13 stars 1 forks source link

Use an external program for the spinner #4

Closed AshlinHarris closed 1 year ago

AshlinHarris commented 1 year ago

https://discourse.julialang.org/t/update-stdout-while-a-function-is-running/86285/8

AshlinHarris commented 1 year ago
function spinner()
        p = 0
        try
                c = "while true;" *
                "for i in \"\\\\|/-\";" *
                "print(\"\\b\$i\");" *
                "sleep(0.1);" *
                "end;" *
                "end"

                p = run(pipeline(` julia -e $c`, stdout), wait=false)

                s = 0
                for i in 10:17
                        s += BigInt(999)^10_000_000 % 17
                end

                return(s)

        finally
                kill(p)
                print("\b")
        end
end

println(spinner())
AshlinHarris commented 1 year ago

The \@spinner macro should edit the command c, display the corresponding spinner, and send a signal to stop when the actual work s is complete.

AshlinHarris commented 1 year ago

The following functionality now exists:

 @spinner result = f(); println(result)

Currently, the default spinner can't be changed by the user, but this is a planned feature.