Skip to content

Instantly share code, notes, and snippets.

@period331
Created July 17, 2020 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save period331/195e86c1e72bca7b79912c62dd7dc2c6 to your computer and use it in GitHub Desktop.
Save period331/195e86c1e72bca7b79912c62dd7dc2c6 to your computer and use it in GitHub Desktop.
命令行布局管理器 Python命令行下多行刷新
# -*- 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()
print
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