1 unstable release
new 0.1.0 | Dec 12, 2024 |
---|
#284 in Command-line interface
120 downloads per month
28KB
490 lines
Tinterm: Tinted Terminal with Colors and Gradients
A Rust library for adding beautiful colors and gradients to your terminal output with an ergonomic API.
Features
- 🎨 RGB color support for both foreground and background
- 🌈 Smooth color gradients
- ⚡ Simple and intuitive API
- 📝 Text styling (bold, italic, underline, etc.)
- 🔄 Chainable methods
- 📚 Comprehensive documentation and examples
Installation
Add this to your Cargo.toml
:
[dependencies]
tinterm = "0.1.0"
Quick Start
use tinterm::*;
// Simple colored text
println!("Hello".color(Color::RED));
// Background color
println!("World".background_color(Color::BLUE));
// Gradient text
println!("Rainbow".gradient(Color::RED, Color::BLUE, None));
// Styled text
println!("Bold and Blue".bold().color(Color::BLUE));
Color Methods
Basic Coloring
// Using descriptive names
"Text".color(Color::RED);
"Text".background_color(Color::BLUE);
// Using short aliases
"Text".fg(Color::RED);
"Text".bg(Color::BLUE);
Gradients
// Foreground gradient
"Gradient Text".gradient(Color::RED, Color::BLUE, None);
// Background gradient
"Gradient Background".gradient_bg(Color::RED, Color::BLUE, None);
// Multiline gradient with block mode
let text = "Line 1\nLine 2";
text.gradient(Color::RED, Color::BLUE, Some(true));
Text Styling
"This line is bold".bold();
"This line is italic".italic();
"This line is underline".underline();
"This line is strikethrough".strikethrough();
"This line is dim".dim();
"This line is blink".blink();
"This line is reverse".reverse();
"This line is hidden".hidden();
"This line is bright".bright();
Method Chaining
"Styled Text"
.bold()
.color(Color::RED)
.background_color(Color::BLUE);
Predefined Colors
The library comes with several predefined colors:
Color::RED
Color::GREEN
Color::BLUE
// ... and more
You can also create custom colors:
// Using RGB values (0-255)
let custom_color = Color::new(255, 128, 0);
// Using hex values
let hex_color = Color::from_hex("#FF8000").unwrap();
// or without the hash
let hex_color = Color::from_hex("FF8000").unwrap();
// Using them in text
println!("Custom RGB".color(custom_color));
println!("Custom Hex".color(hex_color));
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.