@taml/cli
Command-line tool for converting ANSI escape sequences to TAML (Terminal ANSI Markup Language) format in batch operations.
TAML Ecosystem
TAML (Terminal ANSI Markup Language) is a lightweight markup language for styling terminal output with ANSI escape codes. For the complete specification, visit the TAML Specification Repository.
Package Dependencies
graph TD
B["@taml/parser"] --> A["@taml/ast"]
C["@taml/react"] --> A
C --> B
D["@taml/docusaurus"] --> C
F["@taml/cli"] --> E["@taml/encoder"]
F -.-> A
F -.-> B
style F fill:#e1f5fe,stroke:#01579b,stroke-width:2px
Related Packages
Core Infrastructure
- @taml/ast - Foundation package providing AST node types, visitor patterns, and tree traversal utilities for TAML documents.
- @taml/parser - Robust parser that converts TAML markup strings into typed AST nodes with comprehensive error handling and validation.
Input/Output Tools
- @taml/encoder - Converts raw ANSI escape sequences into clean TAML markup for further processing and manipulation.
- @taml/cli - Command-line tool for converting ANSI escape sequences to TAML format in batch operations.
Integration Packages
- @taml/react - React component that renders TAML markup as styled JSX elements with full TypeScript support and performance optimization.
- @taml/docusaurus - Docusaurus theme that automatically detects and renders TAML code blocks in documentation sites.
Installation
Global Installation (Recommended)
npm install -g @taml/cli
Local Installation
npm install @taml/cli
Alternative Package Managers
npm
npm install -g @taml/cli
yarn
yarn global add @taml/cli
pnpm
pnpm add -g @taml/cli
bun
bun add -g @taml/cli
Verify Installation
taml --version
Quick Start
Here's a 5-minute introduction to converting terminal output to readable TAML markup:
# Basic usage - pipe any command output
git status | taml
# Convert colored logs
npm install | taml
# Process build output
npm run build | taml
# Save output to file
docker logs container-name | taml > output.taml
# Chain with other tools
cat app.log | taml | grep "ERROR"
Before (Raw ANSI):
echo -e "\033[31mError:\033[0m \033[1mFile not found\033[0m"
# Output: [31mError:[0m [1mFile not found[0m
After (Clean TAML):
echo -e "\033[31mError:\033[0m \033[1mFile not found\033[0m" | taml
# Output: <red>Error:</red> <bold>File not found</bold>
Usage Examples
Basic Command Conversion
Git Output
# Convert Git status
git status | taml
# Sample output:
# On branch <green>main</green>
# Your branch is up to date with 'origin/main'.
#
# Changes not staged for commit:
# <red>modified: src/app.ts</red>
# <red>modified: README.md</red>
Build Tools
# Convert npm output
npm run build | taml
# Sample output:
# <bold><blue>Building application...</blue></bold>
#
# <green>โ</green> Compiling TypeScript
# <green>โ</green> Bundling assets
# <yellow>โ </yellow> Large bundle size detected
# <green>โ</green> Build completed successfully!
Test Results
# Convert test runner output
npm test | taml
# Sample output:
# <bold><blue>Running test suite...</blue></bold>
#
# <bold>Authentication Tests</bold>
# <green>โ</green> should login with valid credentials <dim>(15ms)</dim>
# <green>โ</green> should reject invalid password <dim>(8ms)</dim>
# <red>โ</red> should handle expired tokens <dim>(23ms)</dim>
File Processing
Process Log Files
# Convert application logs
cat /var/log/app.log | taml > readable-logs.taml
# Process multiple files
for log in *.log; do
cat "$log" | taml > "${log%.log}.taml"
done
# Filter and convert
grep "ERROR" app.log | taml > errors.taml
Batch Processing
# Process all log files in directory
find /var/log -name "*.log" -exec sh -c 'cat "$1" | taml > "${1%.log}.taml"' _ {} \;
# Convert with timestamps
ls -la --color=always | taml > directory-listing.taml
# Process Docker logs
docker logs my-container 2>&1 | taml > container-logs.taml
Advanced Usage
Streaming Processing
# Real-time log monitoring
tail -f /var/log/app.log | taml
# Process continuous output
npm run dev | taml
# Monitor build processes
docker build . | taml
Integration with Other Tools
# Combine with grep for filtering
docker logs container | taml | grep -E "<red>|<yellow>"
# Use with less for paging
npm run build | taml | less -R
# Pipe to file and display
git log --oneline --color=always | tee >(taml > git-log.taml) | taml
CI/CD Integration
# In GitHub Actions
- name: Build and convert output
run: |
npm run build 2>&1 | taml > build-output.taml
# In Jenkins pipeline
sh 'npm test 2>&1 | taml > test-results.taml'
# In GitLab CI
script:
- npm run deploy | taml > deployment-log.taml
Practical Scenarios
1. Development Workflow
Debug Build Issues
# Capture build errors with colors preserved
npm run build 2>&1 | taml > build-debug.taml
# Compare different build outputs
npm run build:dev | taml > dev-build.taml
npm run build:prod | taml > prod-build.taml
diff dev-build.taml prod-build.taml
Monitor Development Server
# Convert dev server output for analysis
npm run dev | taml > dev-server.taml &
DEV_PID=$!
# Later, analyze the output
kill $DEV_PID
grep -E "<red>|<yellow>" dev-server.taml
2. DevOps and Monitoring
Container Logs
# Convert Docker container logs
docker logs --follow my-app | taml > app-logs.taml
# Process Kubernetes pod logs
kubectl logs -f deployment/my-app | taml > k8s-logs.taml
# Analyze deployment logs
kubectl rollout status deployment/my-app | taml > deployment-status.taml
System Monitoring
# Convert system logs
journalctl -f | taml > system-logs.taml
# Process service status
systemctl status nginx | taml > nginx-status.taml
# Monitor resource usage
top -b -n1 | taml > system-resources.taml
3. Documentation Generation
Capture Command Examples
# Generate documentation examples
echo "# Git Status Example" > docs/git-example.md
echo '```taml' >> docs/git-example.md
git status | taml >> docs/git-example.md
echo '```' >> docs/git-example.md
# Create build output documentation
echo "# Build Process" > docs/build-process.md
echo '```taml' >> docs/build-process.md
npm run build | taml >> docs/build-process.md
echo '```' >> docs/build-process.md
Tutorial Creation
# Create interactive tutorials with preserved colors
mkdir tutorial-outputs
git init | taml > tutorial-outputs/01-git-init.taml
git add . | taml > tutorial-outputs/02-git-add.taml
git commit -m "Initial commit" | taml > tutorial-outputs/03-git-commit.taml
4. Testing and Quality Assurance
Test Output Analysis
# Convert test results for analysis
npm test | taml > test-results.taml
# Extract failed tests
grep -A 5 -B 1 "<red>โ</red>" test-results.taml > failed-tests.taml
# Compare test runs
npm test | taml > current-tests.taml
diff baseline-tests.taml current-tests.taml
Performance Monitoring
# Capture benchmark results
npm run benchmark | taml > benchmark-results.taml
# Monitor memory usage during tests
npm test 2>&1 | taml > test-with-memory.taml
Command Reference
Usage
taml [options]
Input Methods
Standard Input (Recommended)
# Pipe from commands
command | taml
# Redirect from files
taml < input.log
# Here documents
taml << EOF
$(echo -e "\033[31mRed text\033[0m")
EOF
File Processing
# Process single file
cat file.log | taml > output.taml
# Process multiple files
cat *.log | taml > combined.taml
# Process with error handling
cat file.log 2>/dev/null | taml > output.taml || echo "Processing failed"
Output Options
Standard Output
# Direct output to terminal
command | taml
# Pipe to other commands
command | taml | grep "pattern"
# Combine with pagers
command | taml | less -R
File Output
# Save to file
command | taml > output.taml
# Append to file
command | taml >> output.taml
# Split output
command | taml | tee output.taml | grep "ERROR"
Exit Codes
| Code |
Description |
0 |
Success - conversion completed |
1 |
Error - no input provided or processing failed |
Error Handling
The CLI tool provides comprehensive error handling:
No Input Provided
$ taml
Error: No input provided. Please pipe ANSI text to this command.
Usage: cat file.txt | taml-cli
echo -e "\e[31mRed text\e[0m" | taml-cli
Processing Errors
# Malformed ANSI sequences are passed through
echo -e "Normal \033[XYZ Invalid \033[31mRed\033[0m" | taml
# Output: Normal [XYZ Invalid <red>Red</red>
Large File Handling
# Efficiently processes large files
cat large-file.log | taml > large-output.taml
# Memory-efficient streaming
tail -f continuous.log | taml
Supported ANSI Features
Colors
Standard Colors (30-37)
- Black (
\033[30m) โ <black>
- Red (
\033[31m) โ <red>
- Green (
\033[32m) โ <green>
- Yellow (
\033[33m) โ <yellow>
- Blue (
\033[34m) โ <blue>
- Magenta (
\033[35m) โ <magenta>
- Cyan (
\033[36m) โ <cyan>
- White (
\033[37m) โ <white>
Bright Colors (90-97)
- Bright Black (
\033[90m) โ <brightBlack>
- Bright Red (
\033[91m) โ <brightRed>
- Bright Green (
\033[92m) โ <brightGreen>
- Bright Yellow (
\033[93m) โ <brightYellow>
- Bright Blue (
\033[94m) โ <brightBlue>
- Bright Magenta (
\033[95m) โ <brightMagenta>
- Bright Cyan (
\033[96m) โ <brightCyan>
- Bright White (
\033[97m) โ <brightWhite>
Background Colors (40-47, 100-107)
- Standard Backgrounds:
<bgBlack>, <bgRed>, <bgGreen>, etc.
- Bright Backgrounds:
<bgBrightBlack>, <bgBrightRed>, etc.
Text Styles
Formatting
- Bold (
\033[1m) โ <bold>
- Dim (
\033[2m) โ <dim>
- Italic (
\033[3m) โ <italic>
- Underline (
\033[4m) โ <underline>
- Strikethrough (
\033[9m) โ <strikethrough>
Reset Sequences
- Full Reset (
\033[0m) โ Closes all open tags
- Foreground Reset (
\033[39m) โ Removes color formatting
- Background Reset (
\033[49m) โ Removes background formatting
Advanced Features
Extended Colors
- 256-Color Palette (
\033[38;5;n) โ Mapped to closest standard color
- RGB Colors (
\033[38;2;r;g;b) โ Converted to nearest standard color
- Background Extended (
\033[48;5;n, \033[48;2;r;g;b) โ Background variants
Nested Formatting
# Complex nesting is properly handled
echo -e "\033[1m\033[4m\033[31mBold Underlined Red\033[0m" | taml
# Output: <bold><underline><red>Bold Underlined Red</red></underline></bold>
Integration with TAML Ecosystem
With Parser
# Convert ANSI to TAML, then parse with @taml/parser
echo -e "\033[31mError\033[0m" | taml | node -e "
const { parse } = require('@taml/parser');
const { getAllText } = require('@taml/ast');
let input = '';
process.stdin.on('data', chunk => input += chunk);
process.stdin.on('end', () => {
const ast = parse(input.trim());
console.log('Plain text:', getAllText(ast));
});
"
With React Components
# Generate TAML for React components
git status | taml > src/examples/git-status.taml
# Use in React app
import { parse } from '@taml/parser';
import { TamlRenderer } from '@taml/react';
import gitStatusTaml from './examples/git-status.taml';
function GitExample() {
const ast = parse(gitStatusTaml);
return <TamlRenderer ast={ast} />;
}
With Documentation Tools