Crates.io | rustylook |
lib.rs | rustylook |
version | 0.1.0 |
created_at | 2025-08-29 21:51:41.418602+00 |
updated_at | 2025-08-29 21:51:41.418602+00 |
description | A simple library for colorizing terminal output |
homepage | https://github.com/firebreather-heart/rustylook |
repository | https://github.com/firebreather-heart/rustylook |
max_upload_size | |
id | 1816974 |
size | 13,436 |
A simple and lightweight Rust library for adding colors to your terminal output using ANSI escape codes. Perfect for creating colorful CLI applications and improving terminal user experience.
Add this to your Cargo.toml
:
[dependencies]
rustylook = "0.1.0"
use rustylook::Brush;
fn main() {
// Create a brush and paint text
let red_brush = Brush::new("red").unwrap();
println!("{}", red_brush.paint("Hello, World!"));
// Or use the quick paint method
println!("{}", Brush::q_paint("Quick and easy!", "blue"));
}
Color | ANSI Code | Example |
---|---|---|
red | 31 | đ´ Error messages |
green | 32 | â Success messages |
yellow | 33 | â ī¸ Warning messages |
blue | 34 | âšī¸ Info messages |
purple | 35 | đ Highlights |
cyan | 36 | đĩ Special text |
gray | 30 | đ Comments |
white | 37 | âĒ Default text |
Note: gray
and grey
are both accepted spellings.
use rustylook::Brush;
fn main() {
// Create a brush instance
if let Some(brush) = Brush::new("green") {
let message = brush.paint("Operation successful!");
println!("{}", message);
}
// Handle invalid colors
match Brush::new("invalid_color") {
Some(brush) => println!("{}", brush.paint("This won't print")),
None => println!("Invalid color specified"),
}
}
use rustylook::Brush;
fn main() {
println!("{}", Brush::q_paint("Error: File not found", "red"));
println!("{}", Brush::q_paint("Warning: Low disk space", "yellow"));
println!("{}", Brush::q_paint("Success: File saved", "green"));
println!("{}", Brush::q_paint("Info: Processing...", "blue"));
}
use rustylook::Brush;
fn print_status(status: &str, message: &str) {
let (color, prefix) = match status {
"error" => ("red", "â ERROR"),
"warning" => ("yellow", "â ī¸ WARN"),
"success" => ("green", "â
SUCCESS"),
"info" => ("blue", "âšī¸ INFO"),
_ => ("white", "đ LOG"),
};
println!("{}: {}",
Brush::q_paint(prefix, color),
message
);
}
fn main() {
print_status("info", "Starting application...");
print_status("warning", "Configuration file not found, using defaults");
print_status("success", "Connected to database");
print_status("error", "Failed to load user data");
}
use rustylook::Brush;
fn colorize_log_level(level: &str, message: &str) -> String {
let color = match level.to_lowercase().as_str() {
"debug" => "gray",
"info" => "blue",
"warn" => "yellow",
"error" => "red",
_ => "white",
};
format!("[{}] {}",
Brush::q_paint(&level.to_uppercase(), color),
message
)
}
fn main() {
println!("{}", colorize_log_level("debug", "Debug information"));
println!("{}", colorize_log_level("info", "Application started"));
println!("{}", colorize_log_level("warn", "Memory usage high"));
println!("{}", colorize_log_level("error", "Critical failure"));
}
Brush::new(color: &str) -> Option<Self>
Creates a new brush with the specified color.
Parameters:
color
: A string slice representing the color nameReturns:
Some(Brush)
if the color is validNone
if the color is not recognizedbrush.paint(text: &str) -> String
Applies the brush's color to the given text.
Parameters:
text
: The string slice to be coloredReturns:
String
with ANSI color codes appliedBrush::q_paint(text: &str, color: &str) -> String
Quickly colors text with the specified color (static method).
Parameters:
text
: The string slice to be coloredcolor
: The color name as a string sliceReturns:
String
with ANSI color codes applied (defaults to white for invalid colors)This library works on:
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.
# Clone the repository
git clone https://github.com/firebreather-heart/rustylook.git
cd rustylook
# Run tests
cargo test
# Build documentation
cargo doc --open
# Check formatting
cargo fmt --check
This project is licensed under
Brush::new()
and Brush::paint()
methodsBrush::q_paint()
convenience methodMade with â¤ī¸ by Firebreather