命令行布局管理器 Python命令行下多行刷新
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf8 -*- | |
import time,sys | |
def progressbar(): | |
print 'Loading...' | |
print "[+] start to build...." | |
height = 4 | |
for i in range(0, 100): | |
if i > 0: | |
sys.stdout.write(u'\u001b[1A') | |
time.sleep(0.1) | |
width = (i + 1) / 4 | |
bar = '[' + '#' * width + ' ' * (25 - width) + ']' | |
sys.stdout.write(u'\u001b[1000D\u001b[2K' + ' | -> ' + bar + '\n') | |
sys.stdout.write(u'\u001b[1000D\u001b[2K' + ' | -> ' + bar) | |
sys.stdout.flush() | |
sys.stdout.write(u'\u001b[1A') | |
sys.stdout.write(u'\u001b[1A') | |
sys.stdout.write(u'\u001b[1000D') | |
sys.stdout.write(u'\u001b[J') | |
sys.stdout.write('[-] Finish build') | |
sys.stdout.flush() | |
progressbar() | |
# https://v2ex.com/t/690665#reply13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment