又一个终端微调器
项目描述
yaspin : Y et A other Terminal Spinner for Python
Yaspin提供了一个功能齐全的终端微调器,用于显示长时间挂起操作的进度。
通过将其用作上下文管理器 或函数装饰器,可以轻松地将其集成到现有代码库中:
import time
from yaspin import yaspin
# Context manager:
with yaspin():
time.sleep(3) # time consuming code
# Function decorator:
@yaspin(text="Loading...")
def some_operations():
time.sleep(3) # time consuming code
some_operations()
Yaspin还提供了一个直观而强大的 API。例如,您可以轻松召唤鲨鱼:
import time
from yaspin import yaspin
with yaspin().white.bold.shark.on_blue as sp:
sp.text = "White bold shark in a blue sea"
time.sleep(5)
特征
在所有主要CPython版本(3.7、3.8、3.9、3.10)、PyPy上运行
支持来自cli-spinners 的所有 (70+) 微调器
支持来自termcolor库的所有颜色、高光、属性和它们的混合
易于与其他命令行库结合,例如prompt-toolkit
灵活的 API,易于与现有代码集成
用于处理 POSIX信号的用户友好 API
安全管道和重定向:
$ python script_that_uses_yaspin.py > script.log
$ python script_that_uses_yaspin.py | grep ERROR
安装
从PyPI使用pip包管理器:
pip install --upgrade yaspin
或者从 GitHub 安装最新的源代码:
pip install https://github.com/pavdmyt/yaspin/archive/master.zip
用法
基本示例