from __future__ import print_function
import random
import time
import sys
if not sys.stdout.isatty() or sys.version_info[0] == 2:
sys.exit(2)
class PrograssBar():
index = [0] * 100
def __init__(self):
self._set_index()
self.status = 0
self.done = False
def _set_index(self):
for index, i in enumerate(PrograssBar.index):
if i == 0:
self.index = index + 2
PrograssBar.index[index] = 1
break
def write(self, precent):
print(
"\033[{index};1H{:<100}{precent:3}% identifier:{identifier:3}".format('=' * precent, index=self.index,
precent=precent,
identifier=self.index - 1))
def update(self, precent):
self.status += precent
self.status = min(100, self.status)
self.write(self.status)
if self.status == 100:
self.done = True
target = [PrograssBar() for i in range(10)]
while 1:
process = random.choice(target)
if process.done:
continue
process.update(random.randint(1, 5))
if process.done and all(map(lambda x: x.done, target)):
print('\033[{};1H'.format(len(target) + 2), end='')
break
time.sleep(0.05)