pub trait Paint {
Show 61 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 resetting(&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.
Because this trait is implemented for all types, you can use its methods on
any type. With the exception of one constructor method, Paint::new()
,
all methods are called with method syntax:
use yansi::Paint;
"hello".green(); // calls `Paint::<&'static str>::green()`.
"hello".strike(); // calls `Paint::<&'static str>::strike()`.
1.on_red(); // calls `Paint::<i32>::red()`.
1.blink(); // calls `Paint::<i32>::blink()`.
§Chaining
All methods return a Painted
whose methods are exactly those of Paint
.
This means you can chain Paint
method calls:
use yansi::Paint;
"hello".green().strike(); // calls `Paint::green()` then `Painted::strike()`.
1.on_red().blink(); // calls `Paint::red()` + `Painted::blink()`.
§Borrow vs. Owned Receiver
The returned Painted
type contains a borrow to the receiver:
use yansi::{Paint, Painted};
let v: Painted<&i32> = 1.red();
This is nearly always what you want. In the exceedingly rare case that you
do want Painted
to own its value, use Paint::new()
or the equivalent
Painted::new()
:
use yansi::{Paint, Painted};
let v: Painted<i32> = Paint::new(1);
let v: Painted<i32> = Painted::new(1);
§Further Details
See the crate level docs for more details and examples.
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>
Returns self
with the
fg()
set to
Color::BrightBlack
.
§Example
println!("{}", value.bright_black());
sourcefn bright_red(&self) -> Painted<&Self>
fn bright_red(&self) -> Painted<&Self>
sourcefn bright_green(&self) -> Painted<&Self>
fn bright_green(&self) -> Painted<&Self>
Returns self
with the
fg()
set to
Color::BrightGreen
.
§Example
println!("{}", value.bright_green());
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>
Returns self
with the
fg()
set to
Color::BrightWhite
.
§Example
println!("{}", value.bright_white());
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 clear(&self) -> Painted<&Self>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&Self>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.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);