A modern, feature-rich terminal styling library for Rust
- π RGB and Hex Colors: Full truecolor support with easy-to-use APIs
- π¨ Background Colors: Style text with colorful backgrounds
- π Text Styling: Bold, italic, dim, blink, and more
- π Gradient Effects: Create beautiful color transitions
- π Polychrome Text: Automatic polychrome coloring
- π Progress Bars: Built-in customizable progress indicators
- π₯οΈ Terminal Utils: Cursor control, screen clearing, and more
- π Zero Dependencies: Lightweight and fast
- π Chainable API: Intuitive method chaining
- π¦ Memory Safe: Built with Rust's safety guarantees
Add Polychrome to your Cargo.toml:
[dependencies]
polychrome = "3.0.0"Then start styling your terminal output:
use polychrome::{StyleExt, colors};
fn main() {
// Simple colored text
println!("{}", "Hello, world!".color(255, 0, 0));
// Hex colors
println!("{}", "Hex colors!".hex_color("#00FF00").unwrap());
// Chained styling
println!("{}",
"Bold and colorful!"
.styled()
.bold()
.color(colors::BLUE.0, colors::BLUE.1, colors::BLUE.2)
);
}use polychrome::{StyleExt, UnderlineStyle};
// Colors and styles
println!("{}", "Bold red text".color(255, 0, 0).bold());
println!("{}", "Italic blue".color(0, 0, 255).italic());
println!("{}", "Underlined".underline(UnderlineStyle::Normal));
// Background colors
println!("{}",
"White on red background"
.styled()
.color(255, 255, 255)
.bg_color(255, 0, 0)
);use polychrome::{StyledText, colors};
// Gradient text
let gradient = StyledText::gradient("GRADIENT TEXT", colors::RED, colors::BLUE);
println!("{}", gradient);
// Polychrome effect
let polychrome = StyledText::polychrome("π POLYCHROME TEXT π");
println!("{}", polychrome);use polychrome::ProgressBar;
let bar = ProgressBar::new(30).color(0, 255, 0);
println!("[{}] 75%", bar.render(0.75));
// Custom characters
let custom_bar = ProgressBar::new(20).chars('β', 'β');
println!("[{}] 50%", custom_bar.render(0.5));use polychrome::colors;
println!("{}", "Red".color(colors::RED.0, colors::RED.1, colors::RED.2));
println!("{}", "Green".color(colors::GREEN.0, colors::GREEN.1, colors::GREEN.2));
println!("{}", "Blue".color(colors::BLUE.0, colors::BLUE.1, colors::BLUE.2));Available colors: RED, GREEN, BLUE, YELLOW, CYAN, MAGENTA, WHITE, BLACK, ORANGE, PURPLE, PINK, BROWN
use polychrome::utils;
// Clear screen and move cursor
utils::clear_screen();
utils::move_cursor(10, 5);
// Hide/show cursor
utils::hide_cursor();
utils::show_cursor();
// Check color support
if utils::supports_color() {
println!("Terminal supports colors!");
}use polychrome::UnderlineStyle;
println!("{}", "Normal".underline(UnderlineStyle::Normal));
println!("{}", "Strike".underline(UnderlineStyle::Strikethrough));
println!("{}", "Double".underline(UnderlineStyle::Double));
println!("{}", "Curly".underline(UnderlineStyle::Curly));
println!("{}", "Dotted".underline(UnderlineStyle::Dotted));
println!("{}", "Dashed".underline(UnderlineStyle::Dashed));Polychrome supports intuitive method chaining for complex styling:
use polychrome::{StyleExt, UnderlineStyle, colors};
println!("{}",
"Complex styling"
.styled()
.hex_color("#FF6B35").unwrap()
.bg_hex_color("#2E3440").unwrap()
.bold()
.italic()
.underline(UnderlineStyle::Curly)
);Polychrome works with modern terminals that support ANSI escape codes and 24-bit colors:
- β Windows Terminal
- β iTerm2 (macOS)
- β GNOME Terminal (Linux)
- β Alacritty
- β Kitty
- β VS Code Terminal
β οΈ CMD (Windows) - Limited support
Polychrome is designed to be fast and lightweight:
- Zero runtime dependencies
- Minimal memory allocations
- Efficient string formatting
- No heap allocations for basic styling
If you're upgrading from Polychrome v2.x:
// Old v2.x API
use polychrome::ColorPrintExt;
println!("{}", "Hello".color(255, 0, 0).underline(None));
// New v3.0 API (recommended)
use polychrome::{StyleExt, UnderlineStyle};
println!("{}", "Hello".color(255, 0, 0).underline(UnderlineStyle::Normal));Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT OR Apache-2.0 license.
Made with β€οΈ and π¦ by the Rust community
