| Crates.io | pigment |
| lib.rs | pigment |
| version | 0.1.2 |
| created_at | 2025-05-14 17:02:26.508054+00 |
| updated_at | 2025-05-16 03:16:02.215554+00 |
| description | All the colors of the web, by name – case-/space-/snake-insensitive |
| homepage | |
| repository | https://github.com/crazywolf132/pigment |
| max_upload_size | |
| id | 1673705 |
| size | 277,108 |
All the colors of the web, by name – case-/space-/snake-insensitive.
Pigment is a Rust library that provides access to hundreds of named colors, with a forgiving lookup system that ignores case, spaces, and other non-alphanumeric characters.
Add this to your Cargo.toml:
[dependencies]
pigment = "0.1.2"
use pigment::color;
fn main() {
// Look up a color by name
let azure = color("Azure").unwrap();
// Access color properties
println!("Name: {}", azure.name()); // "Azure"
println!("Hex: {}", azure.hex()); // "#007FFF"
println!("RGB: {:?}", azure.rgb()); // (0, 127, 255)
// Forgiving lookups - these all return the same color
assert_eq!(color("Azure"), color("azure"));
assert_eq!(color("Azure"), color("AZURE"));
assert_eq!(color("Azure"), color("a z u r e"));
assert_eq!(color("Azure"), color("a-z-u-r-e"));
}
use pigment::color;
fn main() {
let red = color("Red").unwrap();
// Print colored text in terminal
println!("{}This is red text{}",
red.ansi().fg(), // Foreground color
pigment::ansi::Ansi::reset() // Reset formatting
);
let blue = color("Blue").unwrap();
println!("{}Text on blue background{}",
blue.ansi().bg(), // Background color
pigment::ansi::Ansi::reset()
);
}
Pigment can integrate with several popular Rust color libraries. Here are some examples:
Enable the owo feature in your Cargo.toml:
[dependencies]
pigment = { version = "0.1.2", features = ["owo"] }
owo-colors = "4"
Then use it like this:
use owo_colors::OwoColorize;
use pigment::color;
fn main() {
let azure = color("Azure").unwrap();
// Use with owo-colors
let owo_color: owo_colors::Rgb = azure.into();
// Now you can use all owo-colors functionality
println!("{}", "Azure colored text".color(owo_color));
}
Enable the termcolor feature in your Cargo.toml:
[dependencies]
pigment = { version = "0.1.2", features = ["termcolor"] }
termcolor = "1.2"
Then use it like this:
use std::io::Write;
use termcolor::{ColorChoice, ColorSpec, StandardStream, WriteColor};
use pigment::color;
fn main() {
let azure = color("Azure").unwrap();
let tc_color: termcolor::Color = azure.into();
let mut stdout = StandardStream::stdout(ColorChoice::Always);
stdout.set_color(ColorSpec::new().set_fg(Some(tc_color))).unwrap();
writeln!(&mut stdout, "Azure colored text").unwrap();
stdout.reset().unwrap();
}
Enable the colored feature in your Cargo.toml:
[dependencies]
pigment = { version = "0.1.2", features = ["colored"] }
colored = "2"
Then use it like this:
use colored::Colorize;
use pigment::color;
fn main() {
let azure = color("Azure").unwrap();
let c_color: colored::Color = azure.into();
println!("{}", "Azure colored text".color(c_color));
}
Other supported libraries include anstyle, nu-ansi-term, yansi, and crossterm.
See the examples directory for more detailed usage examples.
This project is licensed under the MIT License - see the LICENSE file for details.