Skip to main content

A terminal library with CLI interface

Project description

ChukTerm

A modern terminal library with a powerful CLI interface for building beautiful terminal applications in Python.

Python 3.10+ License: MIT Test Coverage Tests

โœจ Features

  • ๐ŸŽจ Rich UI Components: Banners, prompts, formatters, and code display with syntax highlighting
  • ๐ŸŽฏ Centralized Output Management: Consistent console output with multiple log levels
  • ๐ŸŽญ Theme Support: 8 built-in themes including default, dark, light, minimal, terminal, monokai, dracula, and solarized
  • ๐Ÿ“ Code Display: Syntax highlighting, diffs, code reviews, and side-by-side comparisons
  • ๐Ÿ”ง Terminal Management: Screen control, cursor management, hyperlinks, and color detection
  • ๐Ÿ’ฌ Interactive Prompts: Text input, confirmations, number input, single/multi selection menus
  • ๐Ÿ“Š Data Formatting: Tables, trees, JSON, timestamps, and structured output
  • ๐ŸŒŠ Streaming Support: Live-updating messages for real-time content streaming (LLM-style)
  • ๐Ÿค– AI-Friendly: Designed for AI agents with comprehensive docs and consistent APIs
  • ๐Ÿ”„ Environment Adaptation: Automatically adapts to TTY, CI, and NO_COLOR environments

๐Ÿ“ฆ Installation

Using uv (Recommended)

# Install as dependency
uv add chuk-term

# Install globally as tool
uv tool install chuk-term

Using pip

# Install from PyPI
pip install chuk-term

# With development dependencies
pip install chuk-term[dev]

From Source (Development)

# Clone the repository
git clone https://github.com/yourusername/chuk-term.git
cd chuk-term

# Install with uv (recommended)
uv sync --dev

# Or with pip
pip install -e ".[dev]"

# Verify installation
chuk-term --version

For detailed installation instructions, see the Getting Started Guide.

๐Ÿš€ Quick Start

For AI Agents and LLMs

ChukTerm is designed to be AI-friendly. For comprehensive guidance:

Basic Output

from chuk_term.ui import output

# Different message types
output.success("โœ“ Operation completed successfully")
output.error("โœ— An error occurred")
output.warning("โš  This needs attention")
output.info("โ„น Information message")
output.debug("๐Ÿ” Debug information")

# Special formatting
output.tip("๐Ÿ’ก Pro tip: Use themes for better visuals")
output.hint("This is a subtle hint")
output.command("git commit -m 'Initial commit'")

Interactive Prompts

from chuk_term.ui import ask, confirm, select_from_list, ask_number

# Get user input
name = ask("What's your name?")
age = ask_number("How old are you?", min_value=0, max_value=150)

# Confirmation
if confirm("Would you like to continue?"):
    output.success("Great! Let's proceed...")

# Selection menu
theme = select_from_list(
    ["default", "dark", "light", "minimal", "terminal"],
    "Choose a theme:"
)

Display Code with Syntax Highlighting

from chuk_term.ui import display_code, display_diff

# Show code with syntax highlighting
code = '''def hello_world():
    print("Hello from ChukTerm!")
    return True'''

display_code(code, language="python", title="Example Function")

# Show a diff
display_diff(
    old_text="Hello World",
    new_text="Hello ChukTerm!",
    title="Changes"
)

Streaming Messages (New!)

from chuk_term.ui.streaming import StreamingMessage, StreamingAssistant
import time

# Basic streaming message
with StreamingMessage(title="๐Ÿค– Assistant") as stream:
    stream.update("Processing your request")
    time.sleep(0.5)
    stream.update("...")
    time.sleep(0.5)
    stream.update(" Done!")
# Automatically finalizes with Markdown rendering

# Using StreamingAssistant for simpler API
assistant = StreamingAssistant()
stream = assistant.start()
for word in "Hello from ChukTerm streaming!".split():
    assistant.update(word + " ")
    time.sleep(0.2)
assistant.finalize()

Theme Support

from chuk_term.ui import output
from chuk_term.ui.theme import set_theme, get_theme

# Set a theme
set_theme("monokai")  # or dracula, solarized, minimal, terminal

# Get current theme
current = get_theme()
output.info(f"Using theme: {current.name}")

๐Ÿ–ฅ๏ธ CLI Usage

ChukTerm includes a CLI for testing and demonstrating features:

# Show library information
chuk-term info
chuk-term info --verbose

# Run interactive demo
chuk-term demo

# Run a command with theming
chuk-term run "ls -la"

# Test with specific theme
chuk-term test --theme monokai

๐Ÿ› ๏ธ Development

Setup Development Environment

# Clone the repository
git clone https://github.com/yourusername/chuk-term.git
cd chuk-term

# Install with dev dependencies using uv
uv sync --dev

# Install pre-commit hooks
pre-commit install

Running Tests

# Run all tests with coverage
uv run pytest --cov=chuk_term

# Run specific test file
uv run pytest tests/ui/test_output.py

# Run with verbose output
uv run pytest -v

Code Quality

# Run linting
uv run ruff check src/ tests/

# Auto-fix linting issues
uv run ruff check --fix src/ tests/

# Format code
uv run black src/ tests/

# Type checking
uv run mypy src/

# Run all checks
make check

Available Make Commands

make help        # Show all available commands
make dev         # Install for development
make test        # Run tests with coverage
make lint        # Run linting checks
make format      # Format code
make clean       # Remove build artifacts

๐Ÿ“š Documentation

Quick Start

Core Documentation

API Reference

Output Levels

  • output.debug() - Debug information (only in verbose mode)
  • output.info() - Informational messages
  • output.success() - Success confirmations
  • output.warning() - Warning messages
  • output.error() - Error messages (non-fatal)
  • output.fatal() - Fatal errors (exits program)

Themes

  • default - Balanced colors, good for most terminals
  • dark - High contrast on dark backgrounds
  • light - Optimized for light terminals
  • minimal - Plain text, no colors or icons
  • terminal - Basic ANSI colors only
  • monokai - Popular dark theme
  • dracula - Gothic dark theme
  • solarized - Low contrast, easy on eyes

๐Ÿ“ Examples

The examples directory contains demonstration scripts:

File Description
ui_demo.py Comprehensive UI component showcase
ui_code_demo.py Code display and syntax highlighting
ui_output_demo.py Output management features
ui_terminal_demo.py Terminal control capabilities
ui_theme_independence.py Theme system demonstration
Streaming Demos
ui_streaming_demo.py Advanced streaming UI capabilities
ui_streaming_message_demo.py StreamingMessage and StreamingAssistant demos
ui_streaming_practical_demo.py Real-world streaming use cases
ui_streaming_quickstart.py Simple streaming examples to get started
streaming_long_text_demo.py Token-by-token streaming with proper wrapping
Other
ui_quick_test.py Quick functionality test

Run any example:

# Run the main demo
uv run python examples/ui_demo.py

# Try the streaming demos
uv run python examples/ui_streaming_quickstart.py
uv run python examples/ui_streaming_practical_demo.py

๐Ÿ—๏ธ Project Structure

chuk-term/
โ”œโ”€โ”€ src/chuk_term/
โ”‚   โ”œโ”€โ”€ __init__.py        # Package metadata
โ”‚   โ”œโ”€โ”€ cli.py             # CLI interface
โ”‚   โ””โ”€โ”€ ui/                # UI components
โ”‚       โ”œโ”€โ”€ output.py      # Output management (singleton)
โ”‚       โ”œโ”€โ”€ terminal.py    # Terminal control
โ”‚       โ”œโ”€โ”€ theme.py       # Theme system (8 themes)
โ”‚       โ”œโ”€โ”€ prompts.py     # User prompts
โ”‚       โ”œโ”€โ”€ formatters.py  # Data formatters
โ”‚       โ”œโ”€โ”€ code.py        # Code display
โ”‚       โ”œโ”€โ”€ banners.py     # Banner displays
โ”‚       โ””โ”€โ”€ streaming.py   # Streaming message support
โ”œโ”€โ”€ tests/                 # Test suite (351 tests)
โ”œโ”€โ”€ examples/              # Example scripts
โ”‚   โ”œโ”€โ”€ ui_demo.py
โ”‚   โ”œโ”€โ”€ ui_streaming_*.py # Streaming demonstrations
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ docs/                  # Documentation
โ”‚   โ””โ”€โ”€ ui/
โ”‚       โ””โ”€โ”€ GETTING_STARTED.md  # Quick start guide
โ”œโ”€โ”€ llms.txt              # LLM-optimized docs
โ”œโ”€โ”€ CLAUDE.md             # Project context
โ””โ”€โ”€ pyproject.toml        # Package configuration

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

Quick Contribution Steps

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (uv run pytest)
  5. Commit with a descriptive message
  6. Push to your fork
  7. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Built with Rich for beautiful terminal output
  • Package management by uv
  • Testing with pytest

๐Ÿ“ฎ Support

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

chuk_term-0.1.8.tar.gz (183.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chuk_term-0.1.8-py3-none-any.whl (42.1 kB view details)

Uploaded Python 3

File details

Details for the file chuk_term-0.1.8.tar.gz.

File metadata

  • Download URL: chuk_term-0.1.8.tar.gz
  • Upload date:
  • Size: 183.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for chuk_term-0.1.8.tar.gz
Algorithm Hash digest
SHA256 c81715e116b1f58cb8a476444148bff68a73df8c945fd4c69f2277c05017b978
MD5 00c91d86495bcab6dae49e3dfcc589f9
BLAKE2b-256 22fcd132aa500d11447284a8ba5481921550e90bef16e4ca86ebe1f3e1baefcb

See more details on using hashes here.

File details

Details for the file chuk_term-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: chuk_term-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 42.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for chuk_term-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 8b14f5c56d8ea099a1bcc827cd316ee83d9407c936782f7351bd31c0e1594adb
MD5 1355e8c280264b60d788d729252aae88
BLAKE2b-256 6508e375c6e56f160701311fdf41c291b54a3fd4ad8f794fce316c79169339a4

See more details on using hashes here.

Supported by

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