Skip to content

Instantly share code, notes, and snippets.

@wkentaro
Created January 14, 2015 18:29
Show Gist options
  • Save wkentaro/a3fd2883d663f1ea428f to your computer and use it in GitHub Desktop.
Save wkentaro/a3fd2883d663f1ea428f to your computer and use it in GitHub Desktop.
perfect multi cmdline refreshing
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# multi2.py
# author: Kentaro Wada <www.kentaro.wada@gmail.com>
import curses
import time
def report_progress(filename, progress):
"""progress: 0-10"""
stdscr.addstr(0, 0, "Moving file: {0}".format(filename))
stdscr.addstr(1, 0, "Total progress: [{1:10}] {0}%".format(progress * 10, "#" * progress))
stdscr.refresh()
if __name__ == "__main__":
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
try:
for i in range(10):
report_progress("file_{0}.txt".format(i), i+1)
time.sleep(0.5)
finally:
curses.echo()
curses.nocbreak()
curses.endwin()
@wkentaro
Copy link
Author

wkentaro commented Feb 2, 2015

How to execute it.

$ git clone https://gist.github.com/wkentaro/a3fd2883d663f1ea428f multi2
$ cd multi2
$ python multi2.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment