Skip to main content

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)

Source distribution for sorampt 0.1.6
File Size Uploaded
sorampt-0.1.6.tar.gz 10.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sorampt 0.1.6
File Interpreter ABI Platform
sorampt-0.1.6-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page