#ansi-term #terminal-colors #formatting-style

facet-ansi

A library for ANSI terminal formatting and styling, providing utilities to add colors and text effects to terminal output

5 releases (3 breaking)

Uses new Rust 2024

new 0.8.0 Apr 16, 2025
0.7.0 Apr 15, 2025
0.2.0 Apr 12, 2025
0.1.1 Apr 12, 2025
0.1.0 Apr 11, 2025

#111 in Command-line interface

Download history 374/week @ 2025-04-09

374 downloads per month

MIT/Apache

19KB
321 lines

Facet logo - a reflection library for Rust   facet-ansi

Coverage Status free of syn crates.io documentation MIT/Apache-2.0 licensed

Logo by Misiasart

Thanks to all individual and corporate sponsors, without whom this work could not exist:

Ko-fi GitHub Sponsors Patreon Zed built with depot

Think owo-colors, but even lighter, and unconditional. And not comprehensive.

Overview

facet-ansi is a lightweight library for adding ANSI colors and styles to terminal output. It provides a simple, ergonomic API without any conditional compilation or unnecessary complexity.

Examples

Basic Styling

use facet_ansi::Stylize;

# fn main() {
println!("{}", "This text is red".red());
println!("{}", "This text is blue".blue());
println!("{}", "This text is green".green());

// Combine with formatting
println!("{} and {}", "Red text".red(), "blue text".blue());
# }

Style Methods

use facet_ansi::Stylize;

# fn main() {
// Apply emphasis styles
println!("{}", "Bold text".bold());
println!("{}", "Underlined text".underline());
println!("{}", "Dimmed text".dim());

// Combine styles with method chaining
println!("{}", "Bold and red".red().style(facet_ansi::Style::new().bold()));
# }

Using the Style Module

use facet_ansi::{Stylize, ColorStyle, styles};

# fn main() {
// Use pre-defined styles
let warning_style = styles::yellow();
let error_style = styles::bright_red().bold();

println!("{}", "Warning message".style(warning_style));
println!("{}", "Error message".style(error_style));

// Create custom styles
let custom_style = facet_ansi::Style::new().fg_green().bold().underline();
println!("{}", "Custom styled text".style(custom_style));
# }

Debug Output

use facet_ansi::Stylize;

# fn main() {
// Works with debug formatting too
let data = vec![1, 2, 3];
println!("{:?}", data.cyan());
# }

License

Licensed under either of:

at your option.

Dependencies

~45KB