InkPen
InkPen

Reputation: 307

Go back to start of the line in the REPL

Is it possible to include code in my script that will set the cursor back to the start of the current line as it prints output in the REPL? (i.e. so that what the user sees gets updated). I tried \r in @printf but it seems to do the same as \n.

So far the only solution I found is to @printf several \b characters:

julia> @printf("one\ntwo\rthree")
one
two
three
julia> @printf("one\ntwo\b\bhree")
one
three
julia>

Is there a better way to set the cursor to the beginning of the current line? I am on a Windows system.

Upvotes: 3

Views: 383

Answers (2)

Erik Schnetter
Erik Schnetter

Reputation: 482

You might have encountered a bug in the @printf macro. I just tried your example, and it now works fine -- i.e. it works as you expected it to work, the output two is now overwritten by three: julia> @printf "one\ntwo\rthree" one three

Upvotes: 2

Michael Ohlrogge
Michael Ohlrogge

Reputation: 10980

This works on a mac and linux. Not sure though about windows.

for idx = 1:10
    sleep(1)
    @printf("\tSeconds Passed =%d%s", idx, '\r')
end

The @printf help says that it uses C style formatting, so this response was based on that. The \t at the beginning is just to make the output a bit easier to see.

Upvotes: 1

Related Questions