Expand description
§prettyt
A lightweight, environment-aware ANSI terminal text styling library featuring automatic color capability downsampling.
§Core Features
- Automatic Detection: Dynamically inspects the terminal environment (see the
terminalsubmodule) to safeguard layouts. - Smart Downsampling: Gracefully downsamples
TrueColor(RGB) colors to256-colorpalettes orbasic16-color ANSI buckets depending on what the host terminal supports. - Zero-Allocation Architecture: Evaluation happens lazily during the formatting pass via
fmt::Display, preventing heap allocations and copies.
§Quick Start
§Inline Printing (Using Macros)
Use the sprintln! macro to cleanly format and print styled text. It seamlessly handles native format! interpolation arguments directly, eliminating the need to manually build separate formatted strings beforehand:
use prettyt::{Color, make_style, sprintln};
let info = make_style!(fg(Color::BrightCyan), bold);
let success = make_style!(fg(Color::BrightGreen));
// Pass format arguments smoothly into the macro
sprintln!(info, "-> Launching cluster workers on node #{}", 104);
sprintln!(
success,
"-> Status: {} (verified in {}s)",
"OK",
0.003
);§Builder Style Formatting
For finer control, you can build styles dynamically using the fluent builder API. The .apply() method accepts any type implementing std::fmt::Display and returns a lazy, zero-allocation proxy structure that streams ANSI escape sequences directly to your output macro:
use prettyt::{Style, Color};
let error_badge = Style::new().fg(Color::White).bg(Color::Red).bold();
let highlight = Style::new().fg(Color::Cyan).bold();
// Pass string literals directly, or pass numeric references allocation-free
println!("{} Database panic!", error_badge.apply(" PANIC "));
println!("Returned error code: {}", highlight.apply(&500));Re-exports§
pub use style::css_colors::CSSColor;pub use style::Color;pub use style::Style;pub use terminal::ColorLevel;pub use terminal::registry::clear_override;pub use terminal::registry::set_override;
Modules§
- layout
layout - Layout primitives for composing structured terminal output.
- style
- Text manipulation properties, custom coloring models, and evaluation macros.
- terminal
- Terminal color capability detection and environment handling.