Trait yansi::Paint

source ·
pub trait Paint {
Show 60 methods // Required methods fn fg(&self, value: Color) -> Painted<&Self>; fn primary(&self) -> Painted<&Self>; fn fixed(&self, color: u8) -> Painted<&Self>; fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&Self>; fn black(&self) -> Painted<&Self>; fn red(&self) -> Painted<&Self>; fn green(&self) -> Painted<&Self>; fn yellow(&self) -> Painted<&Self>; fn blue(&self) -> Painted<&Self>; fn magenta(&self) -> Painted<&Self>; fn cyan(&self) -> Painted<&Self>; fn white(&self) -> Painted<&Self>; fn bright_black(&self) -> Painted<&Self>; fn bright_red(&self) -> Painted<&Self>; fn bright_green(&self) -> Painted<&Self>; fn bright_yellow(&self) -> Painted<&Self>; fn bright_blue(&self) -> Painted<&Self>; fn bright_magenta(&self) -> Painted<&Self>; fn bright_cyan(&self) -> Painted<&Self>; fn bright_white(&self) -> Painted<&Self>; fn bg(&self, value: Color) -> Painted<&Self>; fn on_primary(&self) -> Painted<&Self>; fn on_fixed(&self, color: u8) -> Painted<&Self>; fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&Self>; fn on_black(&self) -> Painted<&Self>; fn on_red(&self) -> Painted<&Self>; fn on_green(&self) -> Painted<&Self>; fn on_yellow(&self) -> Painted<&Self>; fn on_blue(&self) -> Painted<&Self>; fn on_magenta(&self) -> Painted<&Self>; fn on_cyan(&self) -> Painted<&Self>; fn on_white(&self) -> Painted<&Self>; fn on_bright_black(&self) -> Painted<&Self>; fn on_bright_red(&self) -> Painted<&Self>; fn on_bright_green(&self) -> Painted<&Self>; fn on_bright_yellow(&self) -> Painted<&Self>; fn on_bright_blue(&self) -> Painted<&Self>; fn on_bright_magenta(&self) -> Painted<&Self>; fn on_bright_cyan(&self) -> Painted<&Self>; fn on_bright_white(&self) -> Painted<&Self>; fn attr(&self, value: Attribute) -> Painted<&Self>; fn bold(&self) -> Painted<&Self>; fn dim(&self) -> Painted<&Self>; fn italic(&self) -> Painted<&Self>; fn underline(&self) -> Painted<&Self>; fn blink(&self) -> Painted<&Self>; fn rapid_blink(&self) -> Painted<&Self>; fn invert(&self) -> Painted<&Self>; fn conceal(&self) -> Painted<&Self>; fn strike(&self) -> Painted<&Self>; fn quirk(&self, value: Quirk) -> Painted<&Self>; fn mask(&self) -> Painted<&Self>; fn wrap(&self) -> Painted<&Self>; fn linger(&self) -> Painted<&Self>; fn clear(&self) -> Painted<&Self>; fn bright(&self) -> Painted<&Self>; fn on_bright(&self) -> Painted<&Self>; fn whenever(&self, value: Condition) -> Painted<&Self>; // Provided methods fn new(self) -> Painted<Self> where Self: Sized { ... } fn paint<S: Into<Style>>(&self, style: S) -> Painted<&Self> { ... }
}
Expand description

A trait to apply styling to any value, implemented for all types.

See the crate level docs for usage details.

Required Methods§

source

fn fg(&self, value: Color) -> Painted<&Self>

Returns a styled value derived from self with the foreground set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like red() and green(), which have the same functionality but are pithier.

Example

Set foreground color to white using fg():

use yansi::{Paint, Color};

painted.fg(Color::White);

Set foreground color to white using white().

use yansi::Paint;

painted.white();
source

fn primary(&self) -> Painted<&Self>

Returns self with the fg() set to Color::Primary.

Example
println!("{}", value.primary());
source

fn fixed(&self, color: u8) -> Painted<&Self>

Returns self with the fg() set to Color::Fixed.

Example
println!("{}", value.fixed(color));
source

fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&Self>

Returns self with the fg() set to Color::Rgb.

Example
println!("{}", value.rgb(r, g, b));
source

fn black(&self) -> Painted<&Self>

Returns self with the fg() set to Color::Black.

Example
println!("{}", value.black());
source

fn red(&self) -> Painted<&Self>

Returns self with the fg() set to Color::Red.

Example
println!("{}", value.red());
source

fn green(&self) -> Painted<&Self>

Returns self with the fg() set to Color::Green.

Example
println!("{}", value.green());
source

fn yellow(&self) -> Painted<&Self>

Returns self with the fg() set to Color::Yellow.

Example
println!("{}", value.yellow());
source

fn blue(&self) -> Painted<&Self>

Returns self with the fg() set to Color::Blue.

Example
println!("{}", value.blue());
source

fn magenta(&self) -> Painted<&Self>

Returns self with the fg() set to Color::Magenta.

Example
println!("{}", value.magenta());
source

fn cyan(&self) -> Painted<&Self>

Returns self with the fg() set to Color::Cyan.

Example
println!("{}", value.cyan());
source

fn white(&self) -> Painted<&Self>

Returns self with the fg() set to Color::White.

Example
println!("{}", value.white());
source

fn bright_black(&self) -> Painted<&Self>

Returns self with the fg() set to Color::BrightBlack.

Example
println!("{}", value.bright_black());
source

fn bright_red(&self) -> Painted<&Self>

Returns self with the fg() set to Color::BrightRed.

Example
println!("{}", value.bright_red());
source

fn bright_green(&self) -> Painted<&Self>

Returns self with the fg() set to Color::BrightGreen.

Example
println!("{}", value.bright_green());
source

fn bright_yellow(&self) -> Painted<&Self>

Returns self with the fg() set to Color::BrightYellow.

Example
println!("{}", value.bright_yellow());
source

fn bright_blue(&self) -> Painted<&Self>

Returns self with the fg() set to Color::BrightBlue.

Example
println!("{}", value.bright_blue());
source

fn bright_magenta(&self) -> Painted<&Self>

Returns self with the fg() set to Color::BrightMagenta.

Example
println!("{}", value.bright_magenta());
source

fn bright_cyan(&self) -> Painted<&Self>

Returns self with the fg() set to Color::BrightCyan.

Example
println!("{}", value.bright_cyan());
source

fn bright_white(&self) -> Painted<&Self>

Returns self with the fg() set to Color::BrightWhite.

Example
println!("{}", value.bright_white());
source

fn bg(&self, value: Color) -> Painted<&Self>

Returns a styled value derived from self with the background set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like on_red() and on_green(), which have the same functionality but are pithier.

Example

Set background color to red using fg():

use yansi::{Paint, Color};

painted.bg(Color::Red);

Set background color to red using on_red().

use yansi::Paint;

painted.on_red();
source

fn on_primary(&self) -> Painted<&Self>

Returns self with the bg() set to Color::Primary.

Example
println!("{}", value.on_primary());
source

fn on_fixed(&self, color: u8) -> Painted<&Self>

Returns self with the bg() set to Color::Fixed.

Example
println!("{}", value.on_fixed(color));
source

fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&Self>

Returns self with the bg() set to Color::Rgb.

Example
println!("{}", value.on_rgb(r, g, b));
source

fn on_black(&self) -> Painted<&Self>

Returns self with the bg() set to Color::Black.

Example
println!("{}", value.on_black());
source

fn on_red(&self) -> Painted<&Self>

Returns self with the bg() set to Color::Red.

Example
println!("{}", value.on_red());
source

fn on_green(&self) -> Painted<&Self>

Returns self with the bg() set to Color::Green.

Example
println!("{}", value.on_green());
source

fn on_yellow(&self) -> Painted<&Self>

Returns self with the bg() set to Color::Yellow.

Example
println!("{}", value.on_yellow());
source

fn on_blue(&self) -> Painted<&Self>

Returns self with the bg() set to Color::Blue.

Example
println!("{}", value.on_blue());
source

fn on_magenta(&self) -> Painted<&Self>

Returns self with the bg() set to Color::Magenta.

Example
println!("{}", value.on_magenta());
source

fn on_cyan(&self) -> Painted<&Self>

Returns self with the bg() set to Color::Cyan.

Example
println!("{}", value.on_cyan());
source

fn on_white(&self) -> Painted<&Self>

Returns self with the bg() set to Color::White.

Example
println!("{}", value.on_white());
source

fn on_bright_black(&self) -> Painted<&Self>

Returns self with the bg() set to Color::BrightBlack.

Example
println!("{}", value.on_bright_black());
source

fn on_bright_red(&self) -> Painted<&Self>

Returns self with the bg() set to Color::BrightRed.

Example
println!("{}", value.on_bright_red());
source

fn on_bright_green(&self) -> Painted<&Self>

Returns self with the bg() set to Color::BrightGreen.

Example
println!("{}", value.on_bright_green());
source

fn on_bright_yellow(&self) -> Painted<&Self>

Returns self with the bg() set to Color::BrightYellow.

Example
println!("{}", value.on_bright_yellow());
source

fn on_bright_blue(&self) -> Painted<&Self>

Returns self with the bg() set to Color::BrightBlue.

Example
println!("{}", value.on_bright_blue());
source

fn on_bright_magenta(&self) -> Painted<&Self>

Returns self with the bg() set to Color::BrightMagenta.

Example
println!("{}", value.on_bright_magenta());
source

fn on_bright_cyan(&self) -> Painted<&Self>

Returns self with the bg() set to Color::BrightCyan.

Example
println!("{}", value.on_bright_cyan());
source

fn on_bright_white(&self) -> Painted<&Self>

Returns self with the bg() set to Color::BrightWhite.

Example
println!("{}", value.on_bright_white());
source

fn attr(&self, value: Attribute) -> Painted<&Self>

Enables the styling Attribute value.

This method should be used rarely. Instead, prefer to use attribute-specific builder methods like bold() and underline(), which have the same functionality but are pithier.

Example

Make text bold using attr():

use yansi::{Paint, Attribute};

painted.attr(Attribute::Bold);

Make text bold using using bold().

use yansi::Paint;

painted.bold();
source

fn bold(&self) -> Painted<&Self>

Returns self with the attr() set to Attribute::Bold.

Example
println!("{}", value.bold());
source

fn dim(&self) -> Painted<&Self>

Returns self with the attr() set to Attribute::Dim.

Example
println!("{}", value.dim());
source

fn italic(&self) -> Painted<&Self>

Returns self with the attr() set to Attribute::Italic.

Example
println!("{}", value.italic());
source

fn underline(&self) -> Painted<&Self>

Returns self with the attr() set to Attribute::Underline.

Example
println!("{}", value.underline());

Returns self with the attr() set to Attribute::Blink.

Example
println!("{}", value.blink());

Returns self with the attr() set to Attribute::RapidBlink.

Example
println!("{}", value.rapid_blink());
source

fn invert(&self) -> Painted<&Self>

Returns self with the attr() set to Attribute::Invert.

Example
println!("{}", value.invert());
source

fn conceal(&self) -> Painted<&Self>

Returns self with the attr() set to Attribute::Conceal.

Example
println!("{}", value.conceal());
source

fn strike(&self) -> Painted<&Self>

Returns self with the attr() set to Attribute::Strike.

Example
println!("{}", value.strike());
source

fn quirk(&self, value: Quirk) -> Painted<&Self>

Enables the yansi Quirk value.

This method should be used rarely. Instead, prefer to use quirk-specific builder methods like mask() and wrap(), which have the same functionality but are pithier.

Example

Enable wrapping using .quirk():

use yansi::{Paint, Quirk};

painted.quirk(Quirk::Wrap);

Enable wrapping using wrap().

use yansi::Paint;

painted.wrap();
source

fn mask(&self) -> Painted<&Self>

Returns self with the quirk() set to Quirk::Mask.

Example
println!("{}", value.mask());
source

fn wrap(&self) -> Painted<&Self>

Returns self with the quirk() set to Quirk::Wrap.

Example
println!("{}", value.wrap());
source

fn linger(&self) -> Painted<&Self>

Returns self with the quirk() set to Quirk::Linger.

Example
println!("{}", value.linger());
source

fn clear(&self) -> Painted<&Self>

Returns self with the quirk() set to Quirk::Clear.

Example
println!("{}", value.clear());
source

fn bright(&self) -> Painted<&Self>

Returns self with the quirk() set to Quirk::Bright.

Example
println!("{}", value.bright());
source

fn on_bright(&self) -> Painted<&Self>

Returns self with the quirk() set to Quirk::OnBright.

Example
println!("{}", value.on_bright());
source

fn whenever(&self, value: Condition) -> Painted<&Self>

Conditionally enable styling based on whether the Condition value applies. Replaces any previous condition.

See the crate level docs for more details.

Example

Enable styling painted only when both stdout and stderr are TTYs:

use yansi::{Paint, Condition};

painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);

Provided Methods§

source

fn new(self) -> Painted<Self>where Self: Sized,

Create a new Painted with a default Style.

Example
use yansi::Paint;

let painted = Paint::new("hello");
assert_eq!(painted.style, yansi::Style::new());
source

fn paint<S: Into<Style>>(&self, style: S) -> Painted<&Self>

Apply a style wholesale to self. Any previous style is replaced.

Example
use yansi::{Paint, Style, Color::*};

static DEBUG: Style = Black.bold().on_yellow();

let painted = "hello".paint(DEBUG);

Implementors§

source§

impl<T: ?Sized> Paint for T