添加进度条示例

This commit is contained in:
limil 2025-08-02 20:06:14 +08:00
parent b9bc422396
commit 60f0ff6b48

31
app.py
View File

@ -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():