Because I'm currently setting up a new server for use, I've been using a lot of command-line programs like curl and wget, and I've noticed that they do something interesting. When run in the Terminal, they print their current progress in place (e.g. 54% will become 55% in place, instead of 55% being printed on the next line - download a large file and you will see what I mean).
I've been wondering how programs can do this. Writing to stdout is nothing new to me, but I'm puzzled at how something like this would work. I've tried writing to stdout, then seeking backwards and writing again; printing backspace characters ('\b'), and printing new things; etc, but nothing seems to work.
Is there no API in Objective-C or C to do this? (C, for instance, has ungetc(), but no unputc()). Are there hacks that can achieve this?
Just something interesting I would like to know more about...
Thanks!