Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nonebot/noneprompt
Prompt toolkit for console interaction (support async, typing)
https://github.com/nonebot/noneprompt
inquirer prompt prompt-toolkit python-inquirer
Last synced: 28 days ago
JSON representation
Prompt toolkit for console interaction (support async, typing)
- Host: GitHub
- URL: https://github.com/nonebot/noneprompt
- Owner: nonebot
- License: mit
- Created: 2022-06-21T04:57:48.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-06T09:00:12.000Z (7 months ago)
- Last Synced: 2024-10-29T23:31:10.528Z (4 months ago)
- Topics: inquirer, prompt, prompt-toolkit, python-inquirer
- Language: Python
- Homepage: https://pypi.org/project/noneprompt/
- Size: 98.6 KB
- Stars: 25
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NonePrompt
Prompt toolkit for console interaction.
**Typing** is fully supported. **Async** is also supported!
## Installation
```bash
pip install noneprompt
```## Prompt Usage
### Input
```python
from noneprompt import InputPromptInputPrompt("What is your name?", validator=lambda string: True).prompt()
await InputPrompt("What is your name?", validator=lambda string: True).prompt_async()
```### Confirm
```python
from noneprompt import ConfirmPromptConfirmPrompt("Are you sure?", default_choice=False).prompt()
await ConfirmPrompt("Are you sure?", default_choice=False).prompt_async()
```### List
```python
from noneprompt import ListPrompt, ChoiceListPrompt("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()
```### Checkbox
```python
from noneprompt import CheckboxPrompt, ChoiceCheckboxPrompt("Choose your favorite colors", choices=[Choice("Red"), Choice("Blue")]).prompt()
await CheckboxPrompt("Choose your favorite colors", choices=[Choice("Red"), Choice("Blue")]).prompt_async()
```## Choice Data
You can add data to choices. Result type can be inferred from the data type.
```python
from noneprompt import ListPrompt, Choiceresult: Choice[str] = ListPrompt(
"What is your favorite color?",
choices=[
Choice("Red", data="#FF0000"),
Choice("Blue", data="#0000FF"),
],
).prompt()
print(result.data)
```## Defaults and Cancellation
```python
from noneprompt import InputPromptresult = InputPrompt("Press Ctrl-C to cancel.").prompt(default="Cancelled")
assert result == "Cancelled"
``````python
from noneprompt import InputPrompt, CancelledErrortry:
InputPrompt("Press Ctrl-C to cancel.").prompt()
except CancelledError:
# Do something
pass
```## Style Guide
See the docstring of prompt classes for more information.
```python
from noneprompt import InputPrompt
from prompt_toolkit.styles import StyleInputPrompt("What is your name?").prompt(style=Style([("input": "#ffffff"), ("answer": "bold")]))
```Disable ansi colors:
```python
from noneprompt import InputPromptInputPrompt("What is your name?").prompt(no_ansi=True)
```## Try from command line
```bash
noneprompt -h
```