From 60f0ff6b48dcf1f62f78c1d43a0d3a11a0990ba6 Mon Sep 17 00:00:00 2001 From: limil Date: Sat, 2 Aug 2025 20:06:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BF=9B=E5=BA=A6=E6=9D=A1?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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():