Sorampt
用于控制台交互的提示工具包。
完全支持打字。 还支持异步!
安装
pip install sorampt
用法
输入
from sorampt import InputPrompt
InputPrompt("What is your name?", validator=lambda string: True).prompt()
await InputPrompt("What is your name?", validator=lambda string: True).prompt_async()
确认
from sorampt import ConfirmPrompt
ConfirmPrompt("Are you sure?", default_choice=False).prompt()
await ConfirmPrompt("Are you sure?", default_choice=False).prompt_async()
列表
from sorampt import ListPrompt, Choice
ListPrompt("What is your favorite color?", choices=[Choice("Red"), Choice("Blue")]).prompt()
await ListPrompt("What is your favorite color?", choices=[Choice("Red"), Choice("Blue")]).prompt_async()
复选
from sorampt import CheckboxPrompt, Choice
CheckboxPrompt("Choose your favorite colors", choices=[Choice("Red"), Choice("Blue")]).prompt()
await CheckboxPrompt("Choose your favorite colors", choices=[Choice("Red"), Choice("Blue")]).prompt_async()
选择数据
您可以将数据添加到选项中。 结果类型可以从数据类型推断出来。
from sorampt import ListPrompt, Choice
result: Choice[str] = ListPrompt(
"What is your favorite color?",
choices=[
Choice("Red", data="#FF0000"),
Choice("Blue", data="#0000FF"),
],
).prompt()
print(result.data)
默认和取消
from sorampt import InputPrompt
result = InputPrompt("Press Ctrl-C to cancel.").prompt(default="Cancelled")
assert result == "Cancelled"
from sorampt import InputPrompt, CancelledError
try:
InputPrompt("Press Ctrl-C to cancel.").prompt()
except CancelledError:
# Do something
pass
样式指南
有关更多信息,请参阅提示类的文档字符串。
from sorampt import InputPrompt
from prompt_toolkit.styles import Style
InputPrompt("What is your name?").prompt(style=Style([("input": "#ffffff"), ("answer": "bold")]))
禁用 ansi 颜色:
from sorampt import InputPrompt
InputPrompt("What is your name?").prompt(no_ansi=True)
从命令行尝试
sorampt -h
Metadata
Release files for sorampt 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sorampt-0.1.6.tar.gz | 10.8 kB | Without provenance | Details for sorampt-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sorampt-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for sorampt-0.1.6-py3-none-any.whl |
Total release size: 28.8 kB
Release files / sorampt-0.1.6.tar.gz
| Download URL | sorampt-0.1.6.tar.gz |
|---|---|
| Size | 10.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1aee3b7984af3574569d506defc1ed66f3df12608329a3f986d6cc3f37e75c87
|
|
BLAKE2b-256 checksum How to use checksums |
a1cb97aafc1beb2c20c9869a47b98444d3ee8bec76712f14722d4608421788db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / sorampt-0.1.6-py3-none-any.whl
| Download URL | sorampt-0.1.6-py3-none-any.whl |
|---|---|
| Size | 18.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cc56c5ed5f74bfe25c4c889eba9dfe066a394569c6ce1e958ea00331a222c6c6
|
|
BLAKE2b-256 checksum How to use checksums |
a7bbfd70a55b89242fd8615db2e6607896080ca4e9c0161113f5921c3657bddf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for sorampt 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.