Reputation: 307
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
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
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