How to flush output of print?

629 views
Skip to first unread message

Ali Rezaee

unread,
May 8, 2015, 6:39:10 AM5/8/15
to julia...@googlegroups.com
Hi,

I would like to show the progress of my Julia code while its running. But I do not want each different percent being printed in a different line in the command line.
Is there a way to print something and then remove it before a new item is printed?

Many thanks,

René Donner

unread,
May 8, 2015, 6:40:44 AM5/8/15
to julia...@googlegroups.com
You can see such behaviour implemented in https://github.com/timholy/ProgressMeter.jl (which might already do what you want ;-)

Ali

unread,
May 8, 2015, 6:44:34 AM5/8/15
to julia...@googlegroups.com
Thanks, René. That package does answer my need.
It would still be useful to know how to flush the output, just for the reference.

Avik Sengupta

unread,
May 8, 2015, 6:52:20 AM5/8/15
to julia...@googlegroups.com
If you look at the source of that package, it uses terminal escape characters to achieve this:

    print(io, "\u1b[1G")   # go to first column
    print_with_color(color, io, s)
    print(io, "\u1b[K")    # clear the rest of the line

Ali

unread,
May 8, 2015, 6:56:36 AM5/8/15
to julia...@googlegroups.com
Great. Thanks a lot.

Tim Holy

unread,
May 8, 2015, 6:59:28 AM5/8/15
to julia...@googlegroups.com
On Friday, May 08, 2015 12:44:12 PM Ali wrote:
> Thanks, René. That package does answer my need.
> It would still be useful to know how to flush the output, just for the
> reference.

To paraphrase Avik: "Use the source, Luke!" :-) Many of julia's packages are
quite readable (or become so, if you invest the time in getting good at it).
It's also one of the best ways to learn how to become good at writing julia
code. I've been doing this for several years now, and I still learn new things
that way on a near-weekly basis.

--Tim

Ali

unread,
May 8, 2015, 7:42:47 AM5/8/15
to julia...@googlegroups.com
Good advice, Tim. Thanks.
Reply all
Reply to author
Forward
0 new messages