diff --git a/app.py b/app.py index 9fd7a22..ad6628e 100644 --- a/app.py +++ b/app.py @@ -23,6 +23,37 @@ class MyApp(REPLApp): else: await self.print("Congratulations! You guessed the number.") break + + @RunSync + async def do_progress(self, args): + """ + 多行进度条示例 + """ + import sys + import asyncio + + tasks = 3 + total = 30 + progresses = [0] * tasks + + # 先打印多行空进度条 + for t in range(tasks): + print(f'任务{t+1}: |{"-"*total}| 0%') + # 光标回到最上面 + print('\033[F' * tasks, end='') + + for i in range(total + 1): + for t in range(tasks): + bar = '█' * i + '-' * (total - i) + percent = int(i / total * 100) + print(f'任务{t+1}: |{bar}| {percent}%') + # 每次循环后,光标回到最上面 + print('\033[F' * tasks, end='') + await asyncio.sleep(0.1) + # 最后打印完成的进度条 + for t in range(tasks): + bar = '█' * total + print(f'任务{t+1}: |{bar}| 100%') async def mainLoop():