I created a command line tool which does some long actions, and I want to notify the user through print statements, like:
"10% Done"
"20% Done"
on what percentage of the operation is done. If I use println, each progress will be printed into a new line (obviously), but is there a way in swift, that I can replace the last printed text with a new one, so on the console you can read only the actual percentage, not the actual and the ones that printed before?
If the output goes to the Terminal then you can use the fact that
\r (Carriage Return) moves the "cursor" to the start of the current
line, without advancing to the next line:
print("10% done ", terminator: "\r")
print("20% done ", terminator: "\r")
print("100% done")
(But note that this does not work in the Xcode debugger console.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With