polychrome

Crates.iopolychrome
lib.rspolychrome
version3.0.1
created_at2024-04-01 14:47:06.95646+00
updated_at2025-08-21 17:35:38.245038+00
descriptionA crate for printing colored and underlined text in the terminal.
homepage
repository
max_upload_size
id1192595
size469,535
ElΓ­as LeguizamΓ³n (EliasLeguizamon123)

documentation

https://docs.rs/polychrome/latest/polychrome/

README

🎨 Polychrome

Polychrome Logo

A modern, feature-rich terminal styling library for Rust

Crates.io Documentation License


✨ Features

  • 🌈 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

πŸš€ Quick Start

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)
    );
}

πŸ“– Examples

Basic Text Styling

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)
);

Advanced Effects

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);

Progress Bars

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));

Predefined Colors

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

Terminal Utilities

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!");
}

🎨 Underline Styles

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));

πŸ”— Method Chaining

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)
);

πŸ–₯️ Terminal Compatibility

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

πŸš€ Performance

Polychrome is designed to be fast and lightweight:

  • Zero runtime dependencies
  • Minimal memory allocations
  • Efficient string formatting
  • No heap allocations for basic styling

πŸ“Š Migration from v2.x

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));

πŸ“š Documentation

🀝 Contributing

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.

πŸ“„ License

This project is licensed under the MIT OR Apache-2.0 license.


Made with ❀️ and πŸ¦€ by the Rust community

Commit count: 0

cargo fmt