Skip to main content

用于控制台交互的提示工具包

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sorampt-0.1.6.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

sorampt-0.1.6-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file sorampt-0.1.6.tar.gz.

File metadata

  • Download URL: sorampt-0.1.6.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for sorampt-0.1.6.tar.gz
Algorithm Hash digest
SHA256 1aee3b7984af3574569d506defc1ed66f3df12608329a3f986d6cc3f37e75c87
MD5 c9c2555962c755916fa0ddfaa9c01d38
BLAKE2b-256 a1cb97aafc1beb2c20c9869a47b98444d3ee8bec76712f14722d4608421788db

See more details on using hashes here.

File details

Details for the file sorampt-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: sorampt-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for sorampt-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 cc56c5ed5f74bfe25c4c889eba9dfe066a394569c6ce1e958ea00331a222c6c6
MD5 8349bcc5cbd05da61dddbcdfd4f578ce
BLAKE2b-256 a7bbfd70a55b89242fd8615db2e6607896080ca4e9c0161113f5921c3657bddf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page