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§
sourcefn fg(&self, value: Color) -> Painted<&Self>
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();
sourcefn bright_black(&self) -> Painted<&Self>
fn bright_black(&self) -> Painted<&Self>
sourcefn bright_red(&self) -> Painted<&Self>
fn bright_red(&self) -> Painted<&Self>
sourcefn bright_green(&self) -> Painted<&Self>
fn bright_green(&self) -> Painted<&Self>
sourcefn bright_yellow(&self) -> Painted<&Self>
fn bright_yellow(&self) -> Painted<&Self>
Returns self
with the
fg()
set to
Color::BrightYellow
.
Example
println!("{}", value.bright_yellow());
sourcefn bright_blue(&self) -> Painted<&Self>
fn bright_blue(&self) -> Painted<&Self>
sourcefn bright_magenta(&self) -> Painted<&Self>
fn bright_magenta(&self) -> Painted<&Self>
Returns self
with the
fg()
set to
Color::BrightMagenta
.
Example
println!("{}", value.bright_magenta());
sourcefn bright_cyan(&self) -> Painted<&Self>
fn bright_cyan(&self) -> Painted<&Self>
sourcefn bright_white(&self) -> Painted<&Self>
fn bright_white(&self) -> Painted<&Self>
sourcefn bg(&self, value: Color) -> Painted<&Self>
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();
sourcefn on_primary(&self) -> Painted<&Self>
fn on_primary(&self) -> Painted<&Self>
sourcefn on_magenta(&self) -> Painted<&Self>
fn on_magenta(&self) -> Painted<&Self>
sourcefn on_bright_black(&self) -> Painted<&Self>
fn on_bright_black(&self) -> Painted<&Self>
Returns self
with the
bg()
set to
Color::BrightBlack
.
Example
println!("{}", value.on_bright_black());
sourcefn on_bright_red(&self) -> Painted<&Self>
fn on_bright_red(&self) -> Painted<&Self>
sourcefn on_bright_green(&self) -> Painted<&Self>
fn on_bright_green(&self) -> Painted<&Self>
Returns self
with the
bg()
set to
Color::BrightGreen
.
Example
println!("{}", value.on_bright_green());
sourcefn on_bright_yellow(&self) -> Painted<&Self>
fn on_bright_yellow(&self) -> Painted<&Self>
Returns self
with the
bg()
set to
Color::BrightYellow
.
Example
println!("{}", value.on_bright_yellow());
sourcefn on_bright_blue(&self) -> Painted<&Self>
fn on_bright_blue(&self) -> Painted<&Self>
Returns self
with the
bg()
set to
Color::BrightBlue
.
Example
println!("{}", value.on_bright_blue());
sourcefn on_bright_magenta(&self) -> Painted<&Self>
fn on_bright_magenta(&self) -> Painted<&Self>
Returns self
with the
bg()
set to
Color::BrightMagenta
.
Example
println!("{}", value.on_bright_magenta());
sourcefn on_bright_cyan(&self) -> Painted<&Self>
fn on_bright_cyan(&self) -> Painted<&Self>
Returns self
with the
bg()
set to
Color::BrightCyan
.
Example
println!("{}", value.on_bright_cyan());
sourcefn on_bright_white(&self) -> Painted<&Self>
fn on_bright_white(&self) -> Painted<&Self>
Returns self
with the
bg()
set to
Color::BrightWhite
.
Example
println!("{}", value.on_bright_white());
sourcefn attr(&self, value: Attribute) -> Painted<&Self>
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();
sourcefn underline(&self) -> Painted<&Self>
fn underline(&self) -> Painted<&Self>
Returns self
with the
attr()
set to
Attribute::Underline
.
Example
println!("{}", value.underline());
sourcefn rapid_blink(&self) -> Painted<&Self>
fn rapid_blink(&self) -> Painted<&Self>
Returns self
with the
attr()
set to
Attribute::RapidBlink
.
Example
println!("{}", value.rapid_blink());
sourcefn quirk(&self, value: Quirk) -> Painted<&Self>
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();
sourcefn whenever(&self, value: Condition) -> Painted<&Self>
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);