| Crates.io | polychrome |
| lib.rs | polychrome |
| version | 3.0.1 |
| created_at | 2024-04-01 14:47:06.95646+00 |
| updated_at | 2025-08-21 17:35:38.245038+00 |
| description | A crate for printing colored and underlined text in the terminal. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1192595 |
| size | 469,535 |
A modern, feature-rich terminal styling library for Rust
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:
Polychrome is designed to be fast and lightweight:
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