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.
๐ What's New in v0.2
- ๐ Progress Indicators: New
progress_bar(),track(), andspinner()methods for better user feedback - ๐จ Theme Preview CLI:
chuk-term themes --side-by-sideto compare all 8 themes - ๐ Examples Browser:
chuk-term examplesto discover and run examples - ๐งช Improved Testing: 93% code coverage with 616 passing tests
- ๐ Better Documentation: New CONTRIBUTING.md and updated guides
- ๐ง Quality Automation: Pre-commit hooks with latest tools (ruff, black, mypy)
See CHANGELOG.md for complete release history.
โจ 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
- ๐ Progress Indicators: Progress bars, spinners, and task tracking with
track()andprogress_bar() - ๐ 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/chrishayuk/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:
- ๐ Read the Getting Started Guide
- ๐ค Check llms.txt for LLM-optimized documentation
- ๐ Browse examples for working code
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()
Progress Indicators (New!)
from chuk_term.ui import output
import time
# Progress bar with detailed tracking
with output.progress_bar("Processing files", show_time=True) as progress:
task = progress.add_task("download", total=100)
for i in range(100):
progress.update(task, advance=1)
time.sleep(0.01)
# Simple iteration tracking
items = ['file1.txt', 'file2.txt', 'file3.txt']
for item in output.track(items, "Processing files"):
process(item) # Your processing logic
# Spinner for indeterminate tasks
with output.spinner("Loading data..."):
load_data() # Long-running operation
Theme Support
from chuk_term.ui import output
from chuk_term.ui.theme import set_theme, get_theme, get_available_themes
# Set a theme
set_theme("monokai") # or dracula, solarized, minimal, terminal
# Get current theme
current = get_theme()
output.info(f"Using theme: {current.name}")
# List all available themes
themes = get_available_themes()
output.info(f"Available themes: {', '.join(themes)}")
๐ฅ๏ธ CLI Usage
ChukTerm includes a powerful CLI for exploring and testing features:
# Show library information
chuk-term info
chuk-term info --verbose
# Run interactive demo
chuk-term demo
# Preview all themes (New!)
chuk-term themes # Detailed preview of each theme
chuk-term themes --side-by-side # Compact side-by-side comparison
# Explore examples (New!)
chuk-term examples # List all available examples with descriptions
chuk-term examples --list-only # Quick list of example names
chuk-term examples --run demo # Run a specific example
# 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/chrishayuk/chuk-term.git
cd chuk-term
# Install with dev dependencies using uv
uv sync --dev
# Install pre-commit hooks (automatic code quality checks)
uv run pre-commit install
# Verify installation
chuk-term --version
uv run pytest # Run tests
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
- ๐ Getting Started Guide - Installation, examples, and best practices
- ๐ค LLM Documentation - AI-optimized reference (llmstxt.org)
- ๐ Examples Directory - Working code examples
Core Documentation
- Output Management - Centralized console output system
- Terminal Management - Terminal control and state management
- Theme System - Theming and styling guide
- Package Management - Using uv for dependency management
- Unit Testing - Testing guidelines and best practices
- Test Coverage - Coverage requirements and reports
- Code Quality - Linting, formatting, and quality standards
API Reference
Output Levels
output.debug()- Debug information (only in verbose mode)output.info()- Informational messagesoutput.success()- Success confirmationsoutput.warning()- Warning messagesoutput.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 (616 tests, 93% coverage)
โโโ examples/ # Example scripts
โ โโโ ui_demo.py
โ โโโ ui_streaming_*.py # Streaming demonstrations
โ โโโ ...
โโโ docs/ # Documentation
โ โโโ ui/ # UI documentation
โ โ โโโ GETTING_STARTED.md # Quick start guide
โ โโโ testing/ # Testing documentation
โ โโโ UNIT_TESTING.md
โ โโโ TEST_COVERAGE.md
โโโ llms.txt # LLM-optimized docs (llmstxt.org)
โโโ CLAUDE.md # Project context for AI agents
โโโ CONTRIBUTING.md # Contribution guidelines
โโโ pyproject.toml # Package configuration
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
Quick Contribution Steps
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests (
uv run pytest) - Commit with a descriptive message
- Push to your fork
- Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
๐ฎ Support
- ๐ซ Report issues at GitHub Issues
- ๐ฌ Discuss at GitHub Discussions
- ๐ Read docs at GitHub Wiki
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chuk_term-0.3.tar.gz.
File metadata
- Download URL: chuk_term-0.3.tar.gz
- Upload date:
- Size: 195.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
067aa20a95aea20992cea4dcbcd94e5b04b9daa728d484aca0aa25b1f6f3b05e
|
|
| MD5 |
80a9c35869523f2bce57909d2f176969
|
|
| BLAKE2b-256 |
609db764eb12cee770051f232f4a72421c233b7ffcfe21d8cc45ff176a46d10e
|
File details
Details for the file chuk_term-0.3-py3-none-any.whl.
File metadata
- Download URL: chuk_term-0.3-py3-none-any.whl
- Upload date:
- Size: 45.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ca06b2e5f7d1cbeb27fce3ff6a1d448a8cbaa02aa6757dbc56a40eb2938f712
|
|
| MD5 |
58ba9006bc61d050a47ca955f776d547
|
|
| BLAKE2b-256 |
e8e715f3f5cfa6587f422151b92d29b9adaa560681d10f84bb66ba17ee19ab1e
|