Name | x-console JSON |
Version |
0.1.1
JSON |
| download |
home_page | http://github.com/puntorigen/x_console |
Summary | Class for nice and easy user interaction, with coloring and automatic translation support |
upload_time | 2025-03-18 22:11:51 |
maintainer | None |
docs_url | None |
author | Pablo Schaffner |
requires_python | <4,>=3.7 |
license | None |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# x_console
[](https://pypi.org/project/x_console/)
[](https://pypi.org/project/x_console/)
[](https://github.com/puntorigen/x_console/blob/main/LICENSE)
Python CLI class for nice and easy user interaction, with coloring, formatting and automatic translation support.
## Features
- **Rich Text Formatting** - Apply colors and styles with simple token markers
- **Automatic Translation** - Detect input language and translate output (supports both online and offline modes)
- **Interactive Prompts** - Simple prompts, menus and selection dialogs
- **Spinners and Progress Indicators** - Show processing status with animated spinners
- **Rich Command Line Interface** - Built on top of rich_click with beautiful styling
- **Debug and Logging** - Formatted debug messages and warnings
## Installation
```bash
# Basic installation
pip install x_console
# With online translation support (using Google Translate)
pip install "x_console[online]"
# With offline translation support (using EasyNMT)
pip install "x_console[offline]"
# Full installation with all translation features
pip install "x_console[full]"
```
## Basic Usage
```python
from x_console import CLIManager
# Initialize the CLI manager
cli = CLIManager(debug=True, debug_prefix="APP")
# Display formatted message
cli.echo("Hello *World*! This text has _italic_ and |dim| formatting.")
# Ask for user input
name = cli.prompt("What is your name?")
cli.echo("Nice to meet you, *{name}*!", name=name)
# Show a process with spinner
def my_task():
# This generator yields status update messages
yield ("Starting process...", {})
yield ("Processing step {step}...", {"step": 1})
yield ("Processing step {step}...", {"step": 2})
yield ("Finalizing...", {})
cli.process(my_task, message="Running task")
```
## Text Formatting
x_console provides simple token-based formatting:
```python
# Default token mappings:
# * for yellow text
# _ for italic text
# | for dim text
cli.echo("This is *yellow* text with _italic_ and |dim| formatting.")
# Custom tokens
cli.setColorTokens({
"*": "bold red",
"#": "blue",
"~": "green italic",
"@": "cyan underline"
})
cli.echo("Now *red bold*, #blue#, ~green italic~ and @underlined@!")
```
## Language Detection and Translation
```python
# Automatic language detection and translation
cli.setup_language("Hola mundo") # Detects Spanish and sets as target language
# Messages will now be automatically translated
cli.echo("Hello world!") # Will output "Hola mundo!"
# Translate text manually
english_text = cli.translate("Bonjour le monde", target_lang="en", online=True)
print(english_text) # "Hello world"
```
## Interactive Menus
```python
# Create a selection menu
choices = ["Option 1", "Option 2", "Option 3"]
selected = cli.select("Choose an option:", choices, default="Option 1")
cli.echo("You selected: *{option}*", option=selected)
```
## Command Line Applications
x_console integrates with rich_click for beautiful CLI applications:
```python
from x_console import CLIManager
cli = CLIManager()
@cli.command()
@cli.option("--name", "-n", help="Your name")
@cli.option("--verbose", "-v", is_flag=True, help="Enable verbose output")
def hello(name, verbose):
"""Say hello to someone."""
if verbose:
cli.debug_("Running with verbose mode")
cli.echo("Hello, *{name}*!", name=name or "World")
if __name__ == "__main__":
hello()
```
## Processing with Spinners
```python
import time
def long_process():
for i in range(1, 11):
# Simulate work
time.sleep(0.5)
# Yield status updates as (message_template, kwargs) tuples
yield ("Step {step} of {total}...", {"step": i, "total": 10})
# Final yield with completion message
yield ("Process completed successfully!", {})
# Run the process with a spinner
cli.process(long_process, message="Running long process")
```
## Debug and Warning Messages
```python
# Enable debug mode
cli.debug = True
# Debug message (only shown when debug=True)
cli.debug_("Connected to {server} on port {port}", server="example.com", port=8080)
# Warning message (only shown when debug=True)
cli.warn_("Connection timeout after {seconds}s", seconds=30)
# Log messages (always shown)
cli.log("Application started")
```
## License
MIT License - see [LICENSE](LICENSE) file for details.
## Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
Raw data
{
"_id": null,
"home_page": "http://github.com/puntorigen/x_console",
"name": "x-console",
"maintainer": null,
"docs_url": null,
"requires_python": "<4,>=3.7",
"maintainer_email": null,
"keywords": null,
"author": "Pablo Schaffner",
"author_email": "pablo@puntorigen.com",
"download_url": "https://files.pythonhosted.org/packages/b8/93/9cf9c1f840d4c97394a75cbefaa271e55aaee43df05d5e01faf99280731b/x_console-0.1.1.tar.gz",
"platform": null,
"description": "# x_console\n\n[](https://pypi.org/project/x_console/)\n[](https://pypi.org/project/x_console/)\n[](https://github.com/puntorigen/x_console/blob/main/LICENSE)\n\nPython CLI class for nice and easy user interaction, with coloring, formatting and automatic translation support.\n\n## Features\n\n- **Rich Text Formatting** - Apply colors and styles with simple token markers\n- **Automatic Translation** - Detect input language and translate output (supports both online and offline modes)\n- **Interactive Prompts** - Simple prompts, menus and selection dialogs\n- **Spinners and Progress Indicators** - Show processing status with animated spinners\n- **Rich Command Line Interface** - Built on top of rich_click with beautiful styling\n- **Debug and Logging** - Formatted debug messages and warnings\n\n## Installation\n\n```bash\n# Basic installation\npip install x_console\n\n# With online translation support (using Google Translate)\npip install \"x_console[online]\"\n\n# With offline translation support (using EasyNMT)\npip install \"x_console[offline]\"\n\n# Full installation with all translation features\npip install \"x_console[full]\"\n```\n\n## Basic Usage\n\n```python\nfrom x_console import CLIManager\n\n# Initialize the CLI manager\ncli = CLIManager(debug=True, debug_prefix=\"APP\")\n\n# Display formatted message\ncli.echo(\"Hello *World*! This text has _italic_ and |dim| formatting.\")\n\n# Ask for user input\nname = cli.prompt(\"What is your name?\")\ncli.echo(\"Nice to meet you, *{name}*!\", name=name)\n\n# Show a process with spinner\ndef my_task():\n # This generator yields status update messages\n yield (\"Starting process...\", {})\n yield (\"Processing step {step}...\", {\"step\": 1})\n yield (\"Processing step {step}...\", {\"step\": 2})\n yield (\"Finalizing...\", {})\n \ncli.process(my_task, message=\"Running task\")\n```\n\n## Text Formatting\n\nx_console provides simple token-based formatting:\n\n```python\n# Default token mappings:\n# * for yellow text\n# _ for italic text\n# | for dim text\n\ncli.echo(\"This is *yellow* text with _italic_ and |dim| formatting.\")\n\n# Custom tokens\ncli.setColorTokens({\n \"*\": \"bold red\",\n \"#\": \"blue\",\n \"~\": \"green italic\",\n \"@\": \"cyan underline\"\n})\n\ncli.echo(\"Now *red bold*, #blue#, ~green italic~ and @underlined@!\")\n```\n\n## Language Detection and Translation\n\n```python\n# Automatic language detection and translation\ncli.setup_language(\"Hola mundo\") # Detects Spanish and sets as target language\n\n# Messages will now be automatically translated\ncli.echo(\"Hello world!\") # Will output \"Hola mundo!\"\n\n# Translate text manually\nenglish_text = cli.translate(\"Bonjour le monde\", target_lang=\"en\", online=True)\nprint(english_text) # \"Hello world\"\n```\n\n## Interactive Menus\n\n```python\n# Create a selection menu\nchoices = [\"Option 1\", \"Option 2\", \"Option 3\"]\nselected = cli.select(\"Choose an option:\", choices, default=\"Option 1\")\ncli.echo(\"You selected: *{option}*\", option=selected)\n```\n\n## Command Line Applications\n\nx_console integrates with rich_click for beautiful CLI applications:\n\n```python\nfrom x_console import CLIManager\n\ncli = CLIManager()\n\n@cli.command()\n@cli.option(\"--name\", \"-n\", help=\"Your name\")\n@cli.option(\"--verbose\", \"-v\", is_flag=True, help=\"Enable verbose output\")\ndef hello(name, verbose):\n \"\"\"Say hello to someone.\"\"\"\n if verbose:\n cli.debug_(\"Running with verbose mode\")\n cli.echo(\"Hello, *{name}*!\", name=name or \"World\")\n\nif __name__ == \"__main__\":\n hello()\n```\n\n## Processing with Spinners\n\n```python\nimport time\n\ndef long_process():\n for i in range(1, 11):\n # Simulate work\n time.sleep(0.5)\n # Yield status updates as (message_template, kwargs) tuples\n yield (\"Step {step} of {total}...\", {\"step\": i, \"total\": 10})\n \n # Final yield with completion message\n yield (\"Process completed successfully!\", {})\n\n# Run the process with a spinner\ncli.process(long_process, message=\"Running long process\")\n```\n\n## Debug and Warning Messages\n\n```python\n# Enable debug mode\ncli.debug = True\n\n# Debug message (only shown when debug=True)\ncli.debug_(\"Connected to {server} on port {port}\", server=\"example.com\", port=8080)\n\n# Warning message (only shown when debug=True)\ncli.warn_(\"Connection timeout after {seconds}s\", seconds=30)\n\n# Log messages (always shown)\ncli.log(\"Application started\")\n```\n\n## License\n\nMIT License - see [LICENSE](LICENSE) file for details.\n\n## Contributing\n\nContributions are welcome! Feel free to open issues or submit pull requests.\n",
"bugtrack_url": null,
"license": null,
"summary": "Class for nice and easy user interaction, with coloring and automatic translation support",
"version": "0.1.1",
"project_urls": {
"Homepage": "http://github.com/puntorigen/x_console"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "89506feb332794cf8416b55c8b4d07eb143b90ea18a55bad375a926bfbdaf32f",
"md5": "c698a08c9cb3828f36f3daf61312a6ac",
"sha256": "fde5beb5c70757156fa4530adae5b117e112303e3655a464012d0b0e292fd5cf"
},
"downloads": -1,
"filename": "x_console-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c698a08c9cb3828f36f3daf61312a6ac",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4,>=3.7",
"size": 11724,
"upload_time": "2025-03-18T22:11:50",
"upload_time_iso_8601": "2025-03-18T22:11:50.066532Z",
"url": "https://files.pythonhosted.org/packages/89/50/6feb332794cf8416b55c8b4d07eb143b90ea18a55bad375a926bfbdaf32f/x_console-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "b8939cf9c1f840d4c97394a75cbefaa271e55aaee43df05d5e01faf99280731b",
"md5": "b937ed16a1a0742a9e3572b33c0236f3",
"sha256": "449e42bf159aad7e23a1906abd031a052e8b6bd91b024d76cf902ec4fbc20583"
},
"downloads": -1,
"filename": "x_console-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "b937ed16a1a0742a9e3572b33c0236f3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4,>=3.7",
"size": 12376,
"upload_time": "2025-03-18T22:11:51",
"upload_time_iso_8601": "2025-03-18T22:11:51.616270Z",
"url": "https://files.pythonhosted.org/packages/b8/93/9cf9c1f840d4c97394a75cbefaa271e55aaee43df05d5e01faf99280731b/x_console-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-03-18 22:11:51",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "puntorigen",
"github_project": "x_console",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "x-console"
}