I'm trying to implement a progress bar for a command line application, e.g.
[##### ] 50% complete
I know I can just backspace to the start of the line and overwrite, but that seems so gross. I'd rather use the carriage return to put the cursor at the first column and then overwrite.
The problem is that the J engine appears to not render the carriage return character, instead rendering a newline+carriage return.
Here is what I have tried:
echo 'hi',(10{a.),'world'
(where 10{a.
is ASCII 10, i.e. carriage return) which prints
hi
world
echo 'hi',(13{a.),'world'
(newline) which prints
hi
world
shell 'printf "%s\r%s" hi world'
which prints
hi
world
shell 'printf "%s\n%s" hi world'
which prints
hi
world
Finally, I tried all of the above in JHS instead of Jconsole, with identical results.
From this, three things are apparent:
Any help?
Ugly but works:
0$ stdout shell 'printf "99 problems\rno"'
no problems
Nicer to avoid calling printf
from the shell:
0$stdout 'hi world',(13{a.),'12'
12 world
Thanks to a comment from @Eelvex
0$stdout 'hi world',CR,'12'
12 world