๐จ make_colors
A simple, powerful, and cross-platform Rust library for adding colors to your terminal output with support for hex colors, RGB values, and rich text attributes.
โจ Features
- ๐จ Standard terminal colors - 16 ANSI colors with light variants
- ๐ Hex color support - Use colors like
#00FFFF,#FF5500 - ๐ฏ RGB color support - Full 24-bit color with RGB values (0-255)
- ๐ญ 16.7 Million Colors - True Color (24-bit) support like Python's
rich - ๐ Simple API - Easy to use functions and builder pattern
- ๐ Text attributes - Bold, italic, underline, dim, blink, and more
- ๐ง Flexible notation - Full names, abbreviations, multiple formats
- ๐ Zero dependencies - Lightweight and fast
- ๐ฅ๏ธ Cross-platform - Works on Windows, Linux, and macOS
๐ธ Screenshots
Basic Colors Example
Hex Colors & Gradients
Screenshots show output from cargo run --example basic and cargo run --example hex_test
๐ฆ Installation
Add this to your Cargo.toml:
[]
= "0.1"
๐ Quick Start
use *;
๐จ Color Reference
Available Colors
| Color Name | Shortcuts | Light Variant | Light Shortcut |
|---|---|---|---|
| black | b, bk | lightblack | lb |
| red | r, rd, re | lightred | lr |
| green | g, gr, ge | lightgreen | lg |
| yellow | y, ye, yl | lightyellow | ly |
| blue | bl | lightblue | lb |
| magenta | m, mg, ma | lightmagenta | lm |
| cyan | c, cy, cn | lightcyan | lc |
| white | w, wh, wi, wt | lightwhite | lw |
Color Preview
// Standard colors
println!;
println!;
println!;
println!;
println!;
println!;
println!;
println!;
// Light variants
println!;
println!;
println!;
println!;
๐ก Usage Examples
Basic Usage
use *;
// Full color names
println!;
// Using shortcuts
println!;
// Mixed notation
println!;
Hex Colors (24-bit True Color)
// Basic hex color
println!;
// Hex with background
println!;
// Various hex colors
println!;
println!;
println!;
// Material Design colors
println!;
println!;
println!;
RGB Colors (16.7 Million Colors)
// Basic RGB
println!;
// RGB with background
println!;
// Various RGB colors
println!;
println!;
println!;
// Create gradients
for i in 0..=10
println!;
Text Attributes
// Single attribute
println!;
println!;
println!;
// Multiple attributes
println!;
// Available attributes: bold, dim, italic, underline, blink, reverse, hidden, strikethrough
ColorBuilder Pattern
// Basic builder
let text = new
.fg
.bold
.build;
println!;
// Builder with hex colors
let text = new
.fg_hex.unwrap
.bg_hex.unwrap
.underline
.build;
println!;
// Builder with RGB
let text = new
.fg_rgb
.bg_rgb
.bold
.italic
.build;
println!;
// Chaining multiple attributes
let text = new
.fg
.bg
.bold
.underline
.italic
.build;
println!;
Macros
// Simple macro usage
println!;
println!;
// Hex color macro
println!;
println!;
Practical Examples
Status Messages
println!;
println!;
println!;
Log Levels
println!;
println!;
println!;
println!;
Progress Bar
// Usage
for i in .step_by
Menu System
create_menu;
Gradient Generator
// Horizontal gradient
gradient_horizontal;
๐ง API Reference
Functions
make_colors(text: &str, fg: &str, bg: Option<&str>) -> String
Main function to colorize text with named colors.
make_colors_with_attrs(text: &str, fg: &str, bg: Option<&str>, attrs: &[&str]) -> String
Colorize text with attributes (bold, italic, etc.).
make_colors_hex(text: &str, fg_hex: &str, bg_hex: Option<&str>) -> Result<String, MakeColorsError>
Colorize text using hex color codes (#RRGGBB).
make_colors_hex_with_attrs(text: &str, fg_hex: &str, bg_hex: Option<&str>, attrs: &[&str]) -> Result<String, MakeColorsError>
Colorize text using hex colors with attributes.
make_colors_rgb(text: &str, fg_rgb: (u8, u8, u8), bg_rgb: Option<(u8, u8, u8)>) -> String
Colorize text using RGB values.
make_colors_rgb_with_attrs(text: &str, fg_rgb: (u8, u8, u8), bg_rgb: Option<(u8, u8, u8)>, attrs: &[&str]) -> String
Colorize text using RGB values with attributes.
hex_to_rgb(hex: &str) -> Result<(u8, u8, u8), MakeColorsError>
Convert hex color string to RGB tuple.
ColorBuilder
Builder pattern for creating colored text:
new
.fg // Set foreground color by name
.bg // Set background color by name
.fg_hex // Set foreground by hex
.bg_hex // Set background by hex
.fg_rgb // Set foreground by RGB
.bg_rgb // Set background by RGB
.bold // Add bold attribute
.italic // Add italic attribute
.underline // Add underline attribute
.dim // Add dim attribute
.blink // Add blink attribute
.reverse // Add reverse attribute
.attr // Add custom attribute
.build // Build the colored string
Macros
color! // Simple colored text
color! // Text with background
color_hex! // Hex colored text
color_hex! // Hex text with background
๐ฅ๏ธ Platform Support
Windows
- โ Windows 10+ (full ANSI support with 24-bit color)
- โ Windows Terminal - Excellent True Color support
- โ PowerShell 7+ - Full support
- โ ๏ธ CMD - Basic support (may need Windows Terminal for best results)
- โ ๏ธ Older Windows may require ANSICON
Linux/Unix
- โ Most modern terminals (xterm, gnome-terminal, konsole, etc.)
- โ Tmux/Screen - Full True Color support
- โ SSH sessions - Supported when terminal supports colors
- โ 24-bit True Color in most modern terminals
macOS
- โ Terminal.app - Full support
- โ iTerm2 - Excellent True Color support
- โ Other terminals - Generally well supported
True Color Support
This library uses 24-bit True Color (16.7 million colors) via ANSI escape sequences:
\x1b[38;2;R;G;Bmfor foreground colors\x1b[48;2;R;G;Bmfor background colors
For best results, use a terminal that supports True Color:
- Windows Terminal โ
- iTerm2 (macOS) โ
- Gnome Terminal โ
- Konsole โ
- VSCode integrated terminal โ
๐ฏ Best Practices
- Use hex or RGB for precise colors - When you need exact brand colors or gradients
- Use named colors for common cases - Simpler and more readable code
- Test on target terminals - Ensure colors display correctly
- Provide fallbacks - Handle environments without color support gracefully
- Use attributes sparingly - Too many can reduce readability
- Check True Color support - Not all terminals support 24-bit color
๐ Examples
Run the included examples:
# Basic colors and features
# Full hex color test with gradients
๐งช Testing
Run the test suite:
Build documentation:
๐ Comparison with Other Libraries
| Feature | make_colors | colored | termcolor | ansi_term |
|---|---|---|---|---|
| Hex colors | โ | โ | โ | โ |
| RGB (24-bit) | โ | โ | โ | โ |
| Named colors | โ | โ | โ | โ |
| Abbreviations | โ | โ | โ | โ |
| Builder pattern | โ | โ | โ | โ |
| Macros | โ | โ | โ | โ |
| Zero deps | โ | โ | โ | โ |
| True Color | โ 16.7M | โ Limited | โ | โ |
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ Changelog
Version 0.1.0
- Initial release
- Support for 16 standard ANSI colors
- Hex color support (#RRGGBB)
- RGB color support (24-bit True Color)
- Text attributes (bold, italic, underline, etc.)
- Builder pattern
- Convenience macros
- Zero dependencies
๐ License
Licensed under the MIT License. See LICENSE for details.
๐จโ๐ป Author
Hadi Cahyadi
๐ง cumulus13@gmail.com
๐ GitHub: https://github.com/cumulus13
๐ Repository: https://github.com/cumulus13/make_colors_rust
๐ Acknowledgments
Inspired by:
- make_colors (Python) - Original Python library
- rich (Python) - Python's rich text library
- colored (Rust) - Rust colored library
๐ Related Projects
- make_colors (Python) - Python version with similar API
โจ Made with โค๏ธ for colorful Rust terminal experiences!
Support 16,777,216 colors ! ๐จ๐
