ANSI Formatting
params-proto automatically generates colorized, terminal-aware help text for better readability.
Overview
Help text comes in two flavors:
__help_str__: Plain text (for testing, logs, pipes)__ansi_str__: Colorized with line wrapping (for terminal display)
Color Scheme
When displayed in a terminal, help text is automatically colorized:
- Type names (INT, STR, FLOAT): Bold Cyan
- (required): Bold Red
- (default: ...): Dim Cyan
- Option names (--foo): Bold
Example
Terminal output will show:
--data-pathand--batch-sizein boldSTRandINTin bold cyan(required)in bold red(default: 32)in dim cyan
Line Wrapping
Long descriptions are automatically wrapped to fit terminal width:
Output wraps intelligently:
Terminal Width Detection
The module automatically detects terminal width using shutil.get_terminal_size():
- Default: 80 characters (fallback)
- Maximum: 120 characters (for readability)
- Adaptive: Uses actual terminal width when available
Disabling Colors
Colors are automatically disabled when:
- Output is piped:
python script.py --help | grep param NO_COLORenvironment variable is setTERM=dumb- Output is not a TTY (terminal)
Manual Control
Testing
Tests use __help_str__ (plain text) to avoid brittle ANSI code assertions:
Environment Variables
Standard environment variables are respected:
| Variable | Effect |
|---|---|
NO_COLOR | Disable all ANSI colors |
FORCE_COLOR | Force colors even when piped |
CLICOLOR=0 | Disable colors (standard) |
TERM=dumb | Disable colors |
Implementation Details
Color Codes
Width Detection
Colorization
Strip ANSI
Best Practices
- Testing: Always test
__help_str__, not__ansi_str__ - Documentation: Use inline comments for parameter descriptions
- Pipes: Colors auto-disable for pipes and redirects
- Accessibility: Respect
NO_COLORfor screen readers - Width: Keep descriptions readable at 80 characters
Customization
Currently, the color scheme is fixed for consistency. Future versions may support:
- Custom color schemes via config
- Per-parameter color overrides
- Rich text formatting (underline, backgrounds)
- Emoji support
See ANSI_HELP_CONSIDERATIONS.md in the repository for roadmap.
Related
- Configuration Basics - Functions and classes
CLI Generation- How Python becomes CLI- Types Guide - Type annotation support
- Release Notes - v3.0.0 ANSI features