Skip to main content

Crate spraypaint

Crate spraypaint 

Source
Expand description

§spraypaint

Terminal string styling for Rust.

§Quick Start

use spraypaint::{paint, Colorize};

// Primary API: paint! prints directly (like println!)
paint!("{red.bold Error:} something went wrong");
paint!("Hello {green.italic world}!");
paint!(inline, "{yellow Loading...}");   // no newline
paint!(stderr, "{red.bold FATAL:} disk full");

// Extension trait: chain styles, then call .paint()
"Warning".yellow().on_red().italic().paint();

// Compose styled values for format strings / loggers
let msg = "critical".red().bold();
eprintln!("status: {msg}");

§Color Levels

spraypaint auto-detects terminal color support via environment variables:

  • NO_COLOR → disable all color
  • FORCE_COLOR=3 → force truecolor
  • COLORTERM=truecolor → enable RGB

Override programmatically:

use spraypaint::detect::{set_color_level, ColorLevel};
set_color_level(ColorLevel::TrueColor);

Re-exports§

pub use color::Color;
pub use detect::color_level;
pub use detect::set_color_level;
pub use detect::ColorLevel;
pub use ext::Colorize;
pub use gradient::Gradient;
pub use style::Attrs;
pub use style::Style;
pub use utils::strip_ansi;

Modules§

color
Color types supporting Basic 16, Xterm 256, and 24-bit RGB.
detect
Terminal color capability detection.
ext
The Colorize extension trait: add styling to any fmt::Display value.
gradient
Gradient text: interpolate colors smoothly across a string’s characters.
prelude
Convenience re-export: use spraypaint::prelude::* brings the most common items into scope.
style
The Style struct: a composable, copy-able bundle of colors and text attributes.
utils
Utility functions for working with ANSI-styled strings.

Macros§

paint
Print styled text to stdout with a trailing newline.
styled
Return an owned String with ANSI styling applied (does not print).

Structs§

Styled
A value T with an attached Style.