| Crates.io | pretty-console |
| lib.rs | pretty-console |
| version | 1.0.3 |
| created_at | 2025-11-02 16:04:16.033741+00 |
| updated_at | 2025-11-02 16:06:04.823177+00 |
| description | A fluent, zero-cost API for styling terminal text with colors and attributes |
| homepage | |
| repository | https://github.com/elcoosp/pretty-console |
| max_upload_size | |
| id | 1913270 |
| size | 46,429 |
pretty-consoleA fluent, zero-cost API for styling terminal text with colors and attributes. Write beautifully formatted console output with an intuitive, chainable interface.
Add this to your Cargo.toml:
[dependencies]
pretty_console = "0.1.0"
Basic usage:
use pretty_console::Console;
fn main() {
Console::new("Hello, world!").red().bold().println();
Console::new("This is a warning").yellow().underline().println();
Console::new("Success!").green().on_black().println();
}
use pretty_console::Console;
// Simple color and attribute combinations
Console::new("Error message").red().bold().println();
Console::new("Warning message").yellow().italic().println();
Console::new("Info message").blue().underline().println();
// Background colors
Console::new("Inverted").white().on_red().println();
Console::new("Custom color!").fg_rgb(255, 0, 128).println();
Console::new("Gradient").bg_rgb(128, 255, 0).println();
Console::new("Important notice!")
.bright_red()
.on_bright_yellow()
.bold()
.italic()
.underline()
.blink()
.println();
use pretty_console::Console;
// Create a style template
let error_style = Console::new("").red().bold();
let warning_style = Console::new("").yellow().italic();
let success_style = Console::new("").green().bold();
// Reuse with different text
error_style.with_text("Error: File not found").println();
warning_style.with_text("Warning: Deprecated API").println();
success_style.with_text("Success: Operation completed").println();
use pretty_console::Console;
let username = "Alice";
let status = Console::new("online").green().bold();
println!("User {} is {}", username, status);
// Output: User Alice is online (with "online" in green and bold)
use pretty_console::{Console, Style, Color};
// Create predefined styles
let heading_style = Style::new()
.fg(Color::BRIGHT_BLUE)
.bold()
.underline();
let note_style = Style::new()
.fg(Color::BRIGHT_BLACK)
.italic();
// Use the styles
Console::new_with_style("Chapter 1: Introduction", heading_style).println();
Console::new_with_style("Note: This is important", note_style).println();
// Basic colors
Color::BLACK, Color::RED, Color::GREEN, Color::YELLOW
Color::BLUE, Color::MAGENTA, Color::CYAN, Color::WHITE
// Bright colors
Color::BRIGHT_BLACK, Color::BRIGHT_RED, Color::BRIGHT_GREEN
Color::BRIGHT_YELLOW, Color::BRIGHT_BLUE, Color::BRIGHT_MAGENTA
Color::BRIGHT_CYAN, Color::BRIGHT_WHITE
fg(color), bg(color) - Set foreground/background colorfg_rgb(r, g, b), bg_rgb(r, g, b) - Set RGB colorsred(), green(), blue(), etc. - Foreground color shortcutson_red(), on_green(), on_blue(), etc. - Background color shortcutsbold(), italic(), underline(), blink()dim(), reverse(), hidden(), strikethrough()print() - Print without newlineprintln() - Print with newlinewrite_to(writer) - Write to any std::io::Writeto_string() - Get formatted stringFor environments where terminal colors aren't supported or desired:
[dependencies]
pretty_console = { version = "0.1.0", features = ["no-color"] }
With the no-color feature, all ANSI escape codes are omitted, and text is printed as-is.
The builder pattern uses zero-cost abstractions - all styling is computed at compile time where possible. The ANSI code generation is optimized and only occurs when actually printing.
For best Windows compatibility, ensure your terminal supports ANSI escape codes or use Windows 10+.
| Feature | pretty_console | termcolor | colored |
|---|---|---|---|
| Fluent API | ✅ | ❌ | ✅ |
| True Color | ✅ | ✅ | ✅ |
| Zero-Cost | ✅ | ✅ | ❌ |
| Reusable Styles | ✅ | ❌ | ❌ |
| Attribute Combos | ✅ | ✅ | ✅ |
| No Dependencies | ✅ | ❌ | ✅ |
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.
Happy styling! 🎨