Here is something i have looked for a long time: printing on the stdout without make use of the new line (\n).
With this purpose i created a simple ascii progress bar.
Here is the code:
import sys, time def main(argv): width = int(argv[1]) length = width - 6 for i in range(1, length + 1): percentage = "%3d%%" % (i*100/length) buff = "[" + "="*i + " "*(length - i) + "]" + percentage + "\r" sys.stdout.write(buff) sys.stdout.flush() time.sleep(0.1) print "" if __name__ == '__main__': main(sys.argv)
Just save it as progressbar.py, and execute it with:
$ python progressbar.py "$COLUMNS" [===================================> ] 75%