<div align="center">
<p>
<a href="https://github.com/Eusen/inquirer_console/blob/master/README.zh.md">δΈζ</a> |
<a href="/">English</a>
</p>
<h1>π£inquirer_console</h1>
<p>An elegant interactive command line interface tool library</p>
<p>
<a href="https://github.com/Eusen/inquirer_console/blob/master/README.md#-installation"><strong>Installation</strong></a> β’
<a href="https://github.com/Eusen/inquirer_console/blob/master/README.md#-features"><strong>Features</strong></a> β’
<a href="https://github.com/Eusen/inquirer_console/blob/master/README.md#-usage-examples"><strong>Usage Examples</strong></a> β’
<a href="https://github.com/Eusen/inquirer_console/blob/master/README.md#-api-documentation"><strong>API Docs</strong></a> β’
<a href="https://github.com/Eusen/inquirer_console/blob/master/README.md#-contributing"><strong>Contributing</strong></a>
</p>
<p>
<img alt="Python Version" src="https://img.shields.io/badge/Python-3.12%2B-blue?style=flat-square&logo=python">
<img alt="License" src="https://img.shields.io/badge/License-MIT-green?style=flat-square">
<img alt="PRs Welcome" src="https://img.shields.io/badge/PRs-welcome-brightgreen?style=flat-square">
</p>
</div>
## π Introduction
inquirer_console is a Python implementation of [Inquirer.js](https://github.com/SBoudrias/Inquirer.js), providing a set of well-designed interactive command line interface components that allow developers to easily create beautiful, user-friendly command line applications.
## β¨ Features
- **Cross-platform compatibility** - Perfect support for Windows, macOS, and various Linux/Unix systems
- **Elegant interrupt handling** - Intelligent handling of Ctrl+C, ensuring a smooth user experience
- **Powerful input validation** - Easily validate user input through custom validate functions
- **Flexible data transformation** - Transform user input in real-time through filter functions
- **Chainable API** - Provides a fluent API similar to Inquirer.js, simplifying complex interactions
- **Fully type-annotated** - Comprehensive type hints to enhance development experience
- **Zero external dependencies** - Implemented with pure Python standard library, no additional installations required
## π§© Prompt Types
inquirer_console currently implements the following prompt types:
| Type | Description | Preview |
|------|-----------------------------------|---------|
| **Input** | Text input prompt | `> Please enter your name:` |
| **Confirm** | Confirmation prompt (yes/no) | `> Continue? (Y/n):` |
| **Radio** | Radio prompt (single choice) | `> Select an option: ⯠Option1 ⬑ Option2 ⬑ Option3` |
| **Checkbox** | Checkbox prompt (multiple choice) | `> Select multiple options: β― [X] Option1 [ ] Option2 [X] Option3` |
| **Password** | Password input prompt | `> Please enter a password: ******` |
| **Text** | Multi-line text input prompt | `> Please enter a description: (Press Enter twice to finish)` |
## π Installation
Currently in development stage, you can install it via:
```bash
# Install from PyPI
pip install inquirer_console
# Install directly from GitHub
pip install git+https://github.com/Eusen/inquirer_console.git
# Or clone the repository and use
git clone https://github.com/Eusen/inquirer_console.git
cd inquirer_console
pip install -e .
```
## π Usage Examples
### Using Each Prompt Type Individually
```python
from inquirer_console import Input, Confirm, Radio, Checkbox, Password, Text
# Input prompt
name = Input(
message="What is your name",
validate=lambda val: True if val else "Name cannot be empty!"
).prompt()
# Confirm prompt
likes_python = Confirm(
message="Do you like Python",
default=True
).prompt()
# Radio prompt
favorite_lang = Radio(
message="What is your favorite programming language",
choices=[
{'name': 'Python', 'value': 'python'},
{'name': 'JavaScript', 'value': 'js'},
{'name': 'Rust', 'value': 'rust'}
]
).prompt()
# Checkbox prompt
languages = Checkbox(
message="Which programming languages do you use",
choices=[
{'name': 'Python', 'value': 'python', 'checked': True},
{'name': 'JavaScript', 'value': 'js'},
{'name': 'Rust', 'value': 'rust'}
]
).prompt()
# Password prompt
password = Password(
message="Please enter a password",
validate=lambda val: True if len(val) >= 6 else "Password must be at least 6 characters!"
).prompt()
# Multi-line text prompt (finish by pressing Enter twice)
description = Text(
message="Please enter a project description"
).prompt()
```
### Using inquirer Chain Calls
```python
from inquirer_console import inquirer
# Define a select of questions
questions = [
{
'type': 'input',
'name': 'name',
'message': 'What is your name',
'validate': lambda val: True if val else "Name cannot be empty!"
},
{
'type': 'confirm',
'name': 'likes_python',
'message': 'Do you like Python',
'default': True
},
{
'type': 'radio',
'name': 'favorite_lang',
'message': 'What is your favorite programming language',
'choices': [
{'name': 'Python', 'value': 'python'},
{'name': 'JavaScript', 'value': 'js'},
{'name': 'Rust', 'value': 'rust'}
]
},
{
'type': 'text',
'name': 'bio',
'message': 'Please enter your bio',
'help_text': 'Press Enter twice to finish input'
}
]
# Execute the prompt chain
answers = inquirer.prompt(questions)
print(f"Hello, {answers['name']}!")
if answers['likes_python']:
print("Great, I like Python too!")
print(f"Your favorite language is: {answers['favorite_lang']}")
print(f"Your bio:\n{answers['bio']}")
```
### Gracefully Handling Interruptions
```python
from inquirer_console import inquirer, ExitPromptError
try:
answers = inquirer.prompt([
{
'type': 'input',
'name': 'name',
'message': 'What is your name'
}
])
print(f"Hello, {answers['name']}!")
except ExitPromptError:
print("\nUser canceled the operation, gracefully exiting...")
```
## π§ Advanced Usage
### Validation and Filtering
```python
from inquirer_console import Input
def validate_age(val):
try:
age = int(val)
if age <= 0:
return "Age must be a positive integer!"
elif age > 120:
return "Age cannot exceed 120 years!"
return True
except ValueError:
return "Please enter a valid number!"
def filter_age(val):
try:
return int(val)
except ValueError:
return val
age = Input(
message="What is your age",
validate=validate_age,
filter=filter_age
).prompt()
print(f"Your age is: {age} (type: {type(age).__name__})")
```
### Multi-line Text Input
```python
from inquirer_console import Text
# Basic usage - finish by pressing Enter twice
description = Text(
message="Please enter a project description"
).prompt()
# Supports both double Enter and END text to finish
bio = Text(
message="Please enter your bio",
end_text="END" # Besides double Enter, can also finish by typing END
).prompt()
# Multi-line text input with validation
def validate_code(code):
if "def main" not in code:
return "Code must include a main function!"
return True
code = Text(
message="Please enter a Python code example",
help_text="Press Enter twice to finish input (code must include main function)",
validate=validate_code
).prompt()
```
## π API Documentation
For detailed API documentation, please visit our [official documentation website](https://example.com/docs).
### Basic Prompt Properties
All prompt types inherit from `BasePrompt` and support the following common parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| `message` | `str` | The prompt message displayed to the user |
| `name` | `str` | The name of the prompt, used to store the answer in the answers dictionary |
| `default` | `Any` | Default value, used when the user doesn't provide input |
| `validate` | `Callable` | Validation function, returns True or an error message |
| `filter` | `Callable` | Filter function, used to process/transform user input |
For specific parameters for each prompt type, please refer to the complete documentation.
## π§ͺ Testing
### Running Tests
The project uses pytest for testing. To run tests, execute the following commands:
```bash
# Run all tests
pytest
# Run a specific test file
pytest tests/test_input.py
# Run a specific test case
pytest tests/test_input.py::test_input_validation
# Run with verbose output
pytest -v
# Generate coverage report
pytest --cov=packages
```
### Adding New Tests
When adding new features, please also add corresponding tests. Test files should be placed in the `tests/` directory and should start with `test_`.
```python
# tests/test_example.py
def test_new_feature():
# Prepare test data
# Execute the feature being tested
# Verify the results meet expectations
assert result == expected
```
### Test Coverage Goals
Our goal is to maintain at least 90% test coverage. Before submitting a PR, please ensure your code changes have adequate test coverage.
## π€ Contributing
We welcome all forms of contributions, whether they are new features, documentation improvements, or bug fixes. Please check our [contribution guidelines](CONTRIBUTING.md) to learn how to participate in the project.
### Development Environment Setup
```bash
# Clone the repository
git clone https://github.com/Eusen/inquirer_console.git
cd inquirer_console
# Create and activate a virtual environment
python -m venv venv
source venv/bin/activate # Unix/macOS
# or
venv\Scripts\activate # Windows
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
```
## π License
This project is licensed under the [MIT License](https://github.com/Eusen/inquirer_console/blob/master/LICENSE).
## π Support the Project
If you like this project, you can support us by:
- β Starring us on GitHub
- π£ Sharing the project on social media
- π Submitting issues or PRs
- π Improving documentation
---
<p align="center">Made with β€οΈ</p>
Raw data
{
"_id": null,
"home_page": null,
"name": "inquirer-console",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3",
"maintainer_email": "Eusen <179530591@qq.com>",
"keywords": "cli, command-line, console, inquirer, interactive, prompt, tui",
"author": null,
"author_email": "Eusen <179530591@qq.com>",
"download_url": "https://files.pythonhosted.org/packages/b4/fe/3bae20f34aa8c318455ea7fc55e819722207fb7caa5977124ebbbd40910f/inquirer_console-1.1.0.tar.gz",
"platform": null,
"description": "<div align=\"center\">\n <p>\n <a href=\"https://github.com/Eusen/inquirer_console/blob/master/README.zh.md\">\u4e2d\u6587</a> | \n <a href=\"/\">English</a>\n </p>\n \n <h1>\ud83d\udc23inquirer_console</h1>\n <p>An elegant interactive command line interface tool library</p>\n \n <p>\n <a href=\"https://github.com/Eusen/inquirer_console/blob/master/README.md#-installation\"><strong>Installation</strong></a> \u2022\n <a href=\"https://github.com/Eusen/inquirer_console/blob/master/README.md#-features\"><strong>Features</strong></a> \u2022\n <a href=\"https://github.com/Eusen/inquirer_console/blob/master/README.md#-usage-examples\"><strong>Usage Examples</strong></a> \u2022\n <a href=\"https://github.com/Eusen/inquirer_console/blob/master/README.md#-api-documentation\"><strong>API Docs</strong></a> \u2022\n <a href=\"https://github.com/Eusen/inquirer_console/blob/master/README.md#-contributing\"><strong>Contributing</strong></a>\n </p>\n \n <p>\n <img alt=\"Python Version\" src=\"https://img.shields.io/badge/Python-3.12%2B-blue?style=flat-square&logo=python\">\n <img alt=\"License\" src=\"https://img.shields.io/badge/License-MIT-green?style=flat-square\">\n <img alt=\"PRs Welcome\" src=\"https://img.shields.io/badge/PRs-welcome-brightgreen?style=flat-square\">\n </p>\n</div>\n\n## \ud83d\udcd6 Introduction\n\ninquirer_console is a Python implementation of [Inquirer.js](https://github.com/SBoudrias/Inquirer.js), providing a set of well-designed interactive command line interface components that allow developers to easily create beautiful, user-friendly command line applications.\n\n## \u2728 Features\n\n- **Cross-platform compatibility** - Perfect support for Windows, macOS, and various Linux/Unix systems\n- **Elegant interrupt handling** - Intelligent handling of Ctrl+C, ensuring a smooth user experience\n- **Powerful input validation** - Easily validate user input through custom validate functions\n- **Flexible data transformation** - Transform user input in real-time through filter functions\n- **Chainable API** - Provides a fluent API similar to Inquirer.js, simplifying complex interactions\n- **Fully type-annotated** - Comprehensive type hints to enhance development experience\n- **Zero external dependencies** - Implemented with pure Python standard library, no additional installations required\n\n## \ud83e\udde9 Prompt Types\n\ninquirer_console currently implements the following prompt types:\n\n| Type | Description | Preview |\n|------|-----------------------------------|---------|\n| **Input** | Text input prompt | `> Please enter your name:` |\n| **Confirm** | Confirmation prompt (yes/no) | `> Continue? (Y/n):` |\n| **Radio** | Radio prompt (single choice) | `> Select an option: \u276f Option1 \u2b21 Option2 \u2b21 Option3` |\n| **Checkbox** | Checkbox prompt (multiple choice) | `> Select multiple options: \u276f [X] Option1 [ ] Option2 [X] Option3` |\n| **Password** | Password input prompt | `> Please enter a password: ******` |\n| **Text** | Multi-line text input prompt | `> Please enter a description: (Press Enter twice to finish)` |\n\n## \ud83d\ude80 Installation\n\nCurrently in development stage, you can install it via:\n\n```bash\n# Install from PyPI\npip install inquirer_console\n\n# Install directly from GitHub\npip install git+https://github.com/Eusen/inquirer_console.git\n\n# Or clone the repository and use\ngit clone https://github.com/Eusen/inquirer_console.git\ncd inquirer_console\npip install -e .\n```\n\n## \ud83d\udcdd Usage Examples\n\n### Using Each Prompt Type Individually\n\n```python\nfrom inquirer_console import Input, Confirm, Radio, Checkbox, Password, Text\n\n# Input prompt\nname = Input(\n message=\"What is your name\",\n validate=lambda val: True if val else \"Name cannot be empty!\"\n).prompt()\n\n# Confirm prompt\nlikes_python = Confirm(\n message=\"Do you like Python\",\n default=True\n).prompt()\n\n# Radio prompt\nfavorite_lang = Radio(\n message=\"What is your favorite programming language\",\n choices=[\n {'name': 'Python', 'value': 'python'},\n {'name': 'JavaScript', 'value': 'js'},\n {'name': 'Rust', 'value': 'rust'}\n ]\n).prompt()\n\n# Checkbox prompt\nlanguages = Checkbox(\n message=\"Which programming languages do you use\",\n choices=[\n {'name': 'Python', 'value': 'python', 'checked': True},\n {'name': 'JavaScript', 'value': 'js'},\n {'name': 'Rust', 'value': 'rust'}\n ]\n).prompt()\n\n# Password prompt\npassword = Password(\n message=\"Please enter a password\",\n validate=lambda val: True if len(val) >= 6 else \"Password must be at least 6 characters!\"\n).prompt()\n\n# Multi-line text prompt (finish by pressing Enter twice)\ndescription = Text(\n message=\"Please enter a project description\"\n).prompt()\n```\n\n### Using inquirer Chain Calls\n\n```python\nfrom inquirer_console import inquirer\n\n# Define a select of questions\nquestions = [\n {\n 'type': 'input',\n 'name': 'name',\n 'message': 'What is your name',\n 'validate': lambda val: True if val else \"Name cannot be empty!\"\n },\n {\n 'type': 'confirm',\n 'name': 'likes_python',\n 'message': 'Do you like Python',\n 'default': True\n },\n {\n 'type': 'radio',\n 'name': 'favorite_lang',\n 'message': 'What is your favorite programming language',\n 'choices': [\n {'name': 'Python', 'value': 'python'},\n {'name': 'JavaScript', 'value': 'js'},\n {'name': 'Rust', 'value': 'rust'}\n ]\n },\n {\n 'type': 'text',\n 'name': 'bio',\n 'message': 'Please enter your bio',\n 'help_text': 'Press Enter twice to finish input'\n }\n]\n\n# Execute the prompt chain\nanswers = inquirer.prompt(questions)\n\nprint(f\"Hello, {answers['name']}!\")\nif answers['likes_python']:\n print(\"Great, I like Python too!\")\nprint(f\"Your favorite language is: {answers['favorite_lang']}\")\nprint(f\"Your bio:\\n{answers['bio']}\")\n```\n\n### Gracefully Handling Interruptions\n\n```python\nfrom inquirer_console import inquirer, ExitPromptError\n\ntry:\n answers = inquirer.prompt([\n {\n 'type': 'input',\n 'name': 'name',\n 'message': 'What is your name'\n }\n ])\n print(f\"Hello, {answers['name']}!\")\nexcept ExitPromptError:\n print(\"\\nUser canceled the operation, gracefully exiting...\")\n```\n\n## \ud83d\udd27 Advanced Usage\n\n### Validation and Filtering\n\n```python\nfrom inquirer_console import Input\n\ndef validate_age(val):\n try:\n age = int(val)\n if age <= 0:\n return \"Age must be a positive integer!\"\n elif age > 120:\n return \"Age cannot exceed 120 years!\"\n return True\n except ValueError:\n return \"Please enter a valid number!\"\n\ndef filter_age(val):\n try:\n return int(val)\n except ValueError:\n return val\n\nage = Input(\n message=\"What is your age\",\n validate=validate_age,\n filter=filter_age\n).prompt()\n\nprint(f\"Your age is: {age} (type: {type(age).__name__})\")\n```\n\n### Multi-line Text Input\n\n```python\nfrom inquirer_console import Text\n\n# Basic usage - finish by pressing Enter twice\ndescription = Text(\n message=\"Please enter a project description\"\n).prompt()\n\n# Supports both double Enter and END text to finish\nbio = Text(\n message=\"Please enter your bio\",\n end_text=\"END\" # Besides double Enter, can also finish by typing END\n).prompt()\n\n# Multi-line text input with validation\ndef validate_code(code):\n if \"def main\" not in code:\n return \"Code must include a main function!\"\n return True\n\ncode = Text(\n message=\"Please enter a Python code example\",\n help_text=\"Press Enter twice to finish input (code must include main function)\",\n validate=validate_code\n).prompt()\n```\n\n## \ud83d\udcda API Documentation\n\nFor detailed API documentation, please visit our [official documentation website](https://example.com/docs).\n\n### Basic Prompt Properties\n\nAll prompt types inherit from `BasePrompt` and support the following common parameters:\n\n| Parameter | Type | Description |\n|-----------|------|-------------|\n| `message` | `str` | The prompt message displayed to the user |\n| `name` | `str` | The name of the prompt, used to store the answer in the answers dictionary |\n| `default` | `Any` | Default value, used when the user doesn't provide input |\n| `validate` | `Callable` | Validation function, returns True or an error message |\n| `filter` | `Callable` | Filter function, used to process/transform user input |\n\nFor specific parameters for each prompt type, please refer to the complete documentation.\n\n## \ud83e\uddea Testing\n\n### Running Tests\n\nThe project uses pytest for testing. To run tests, execute the following commands:\n\n```bash\n# Run all tests\npytest\n\n# Run a specific test file\npytest tests/test_input.py\n\n# Run a specific test case\npytest tests/test_input.py::test_input_validation\n\n# Run with verbose output\npytest -v\n\n# Generate coverage report\npytest --cov=packages\n```\n\n### Adding New Tests\n\nWhen adding new features, please also add corresponding tests. Test files should be placed in the `tests/` directory and should start with `test_`.\n\n```python\n# tests/test_example.py\ndef test_new_feature():\n # Prepare test data\n # Execute the feature being tested\n # Verify the results meet expectations\n assert result == expected\n```\n\n### Test Coverage Goals\n\nOur goal is to maintain at least 90% test coverage. Before submitting a PR, please ensure your code changes have adequate test coverage.\n\n## \ud83e\udd1d Contributing\n\nWe welcome all forms of contributions, whether they are new features, documentation improvements, or bug fixes. Please check our [contribution guidelines](CONTRIBUTING.md) to learn how to participate in the project.\n\n### Development Environment Setup\n\n```bash\n# Clone the repository\ngit clone https://github.com/Eusen/inquirer_console.git\ncd inquirer_console\n\n# Create and activate a virtual environment\npython -m venv venv\nsource venv/bin/activate # Unix/macOS\n# or\nvenv\\Scripts\\activate # Windows\n\n# Install development dependencies\npip install -e \".[dev]\"\n\n# Run tests\npytest\n```\n\n## \ud83d\udcc4 License\n\nThis project is licensed under the [MIT License](https://github.com/Eusen/inquirer_console/blob/master/LICENSE).\n\n## \ud83d\udc96 Support the Project\n\nIf you like this project, you can support us by:\n\n- \u2b50 Starring us on GitHub\n- \ud83d\udce3 Sharing the project on social media\n- \ud83d\udc1b Submitting issues or PRs\n- \ud83d\udcdd Improving documentation\n\n---\n\n<p align=\"center\">Made with \u2764\ufe0f</p> ",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Elegant interactive command-line interface tool library, Python implementation of Inquirer.js",
"version": "1.1.0",
"project_urls": {
"Bug Tracker": "https://github.com/Eusen/inquirer_console/issues",
"Documentation": "https://github.com/Eusen/inquirer_console#readme",
"Homepage": "https://github.com/Eusen/inquirer_console",
"Release notes": "https://github.com/Eusen/inquirer_console/releases"
},
"split_keywords": [
"cli",
" command-line",
" console",
" inquirer",
" interactive",
" prompt",
" tui"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "a874a626de6a3c4e37308557c6860e119bebc2de9af08e37605fae025a8a4042",
"md5": "4f4c146494d70022f149c4c203b765a8",
"sha256": "9b29d00ac169069e3c2d65e26c5d876f7ef4f036a8d81155660f502f9952da0e"
},
"downloads": -1,
"filename": "inquirer_console-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4f4c146494d70022f149c4c203b765a8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3",
"size": 22611,
"upload_time": "2025-03-31T10:54:02",
"upload_time_iso_8601": "2025-03-31T10:54:02.645966Z",
"url": "https://files.pythonhosted.org/packages/a8/74/a626de6a3c4e37308557c6860e119bebc2de9af08e37605fae025a8a4042/inquirer_console-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "b4fe3bae20f34aa8c318455ea7fc55e819722207fb7caa5977124ebbbd40910f",
"md5": "e8a6c7067c60b172e4928156d0275a37",
"sha256": "dfe69c4c7c0827b912c277070afd24eca83f185137520cffbba8ed22f0f152b3"
},
"downloads": -1,
"filename": "inquirer_console-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "e8a6c7067c60b172e4928156d0275a37",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3",
"size": 48812,
"upload_time": "2025-03-31T10:54:06",
"upload_time_iso_8601": "2025-03-31T10:54:06.218845Z",
"url": "https://files.pythonhosted.org/packages/b4/fe/3bae20f34aa8c318455ea7fc55e819722207fb7caa5977124ebbbd40910f/inquirer_console-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-03-31 10:54:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Eusen",
"github_project": "inquirer_console",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "inquirer-console"
}