pub struct Paint<T> { /* fields omitted */ }
A structure encapsulating an item and styling.
See the crate level documentation for usage information.
The Paint
structure exposes many methods for convenience.
Return a new Paint
structure with no styling applied.
Return a new Paint
structure with a foreground color applied.
Return information about the Paint
structure.
Set a style property on a given Paint
structure.
These methods can be chained:
use yansi::Paint;
Paint::new("hi").underline().invert().italic().dimmed().bold();
Modify or observe the global behavior of painting.
Constructs a new Paint
structure encapsulating item
with no styling.
use yansi::Paint;
assert_eq!(Paint::new("hello!").to_string(), "hello!".to_string());
Constructs a new masked Paint
structure encapsulating item
.
A masked Paint
is not written out when painting is disabled during
Display
or Debug
invocations. When painting is enabled, masking has
no effect.
use yansi::Paint;
println!("{}Sprout!", Paint::masked("🌱 "));
Constructs a new Paint
structure encapsulating item
with the
foreground color set to the RGB color r
, g
, b
.
use yansi::Paint;
println!("This is going to be funky: {}", Paint::rgb(70, 130, 122, "hi!"));
Constructs a new Paint
structure encapsulating item
with the
foreground color set to the fixed 256-bit color color
.
use yansi::Paint;
println!("This is going to be funky: {}", Paint::fixed(100, "hi!"));
Constructs a new Paint
structure encapsulating item
with the foreground color set to black.
use yansi::Paint;
println!("This is going to be black: {}", Paint::black("yay!"));
Constructs a new Paint
structure encapsulating item
with the foreground color set to red.
use yansi::Paint;
println!("This is going to be red: {}", Paint::red("yay!"));
Constructs a new Paint
structure encapsulating item
with the foreground color set to green.
use yansi::Paint;
println!("This is going to be green: {}", Paint::green("yay!"));
Constructs a new Paint
structure encapsulating item
with the foreground color set to yellow.
use yansi::Paint;
println!("This is going to be yellow: {}", Paint::yellow("yay!"));
Constructs a new Paint
structure encapsulating item
with the foreground color set to blue.
use yansi::Paint;
println!("This is going to be blue: {}", Paint::blue("yay!"));
Constructs a new Paint
structure encapsulating item
with the foreground color set to purple.
use yansi::Paint;
println!("This is going to be purple: {}", Paint::purple("yay!"));
Constructs a new Paint
structure encapsulating item
with the foreground color set to cyan.
use yansi::Paint;
println!("This is going to be cyan: {}", Paint::cyan("yay!"));
Constructs a new Paint
structure encapsulating item
with the foreground color set to white.
use yansi::Paint;
println!("This is going to be white: {}", Paint::white("yay!"));
Retrieves the style currently set on self
.
use yansi::{Style, Paint};
let alert = Style::red().bold().underline();
let painted = Paint::red("hi").bold().underline();
assert_eq!(alert, painted.style());
Sets the style of self
to style
.
Any styling currently set on self
is lost. Prefer to use the
style.paint()
method to create a Paint
struct from
Style
.
use yansi::{Paint, Style};
let s = Style::red().bold().underline();
println!("Alert: {}", Paint::new("This thing happened!").with_style(s));
println!("Alert: {}", s.paint("This thing happened!"));
Masks self
.
A masked Paint
is not written out when painting is disabled during
Display
or Debug
invocations. When painting is enabled, masking has
no effect.
use yansi::Paint;
println!("{}Something happened.", Paint::red("Whoops! ").mask());
Sets the foreground to color
.
use yansi::Paint;
use yansi::Color::Red;
println!("Red foreground: {}", Paint::new("hi!").fg(Red));
Sets the background to color
.
use yansi::Paint;
use yansi::Color::Yellow;
println!("Yellow background: {}", Paint::new("hi!").bg(Yellow));
Enables the bold style on self
.
use yansi::Paint;
println!("Using bold: {}", Paint::new("hi").bold());
Enables the dimmed style on self
.
use yansi::Paint;
println!("Using dimmed: {}", Paint::new("hi").dimmed());
Enables the italic style on self
.
use yansi::Paint;
println!("Using italic: {}", Paint::new("hi").italic());
Enables the underline style on self
.
use yansi::Paint;
println!("Using underline: {}", Paint::new("hi").underline());
Enables the blink style on self
.
use yansi::Paint;
println!("Using blink: {}", Paint::new("hi").blink());
Enables the invert style on self
.
use yansi::Paint;
println!("Using invert: {}", Paint::new("hi").invert());
Enables the hidden style on self
.
use yansi::Paint;
println!("Using hidden: {}", Paint::new("hi").hidden());
Enables the strikethrough style on self
.
use yansi::Paint;
println!("Using strikethrough: {}", Paint::new("hi").strikethrough());
Disables coloring globally.
use yansi::Paint;
assert_ne!(Paint::green("go").to_string(), "go".to_string());
Paint::disable();
assert_eq!(Paint::green("go").to_string(), "go".to_string());
Enables coloring globally. Coloring is enabled by default, so this
method should only be called to re enable coloring.
use yansi::Paint;
Paint::disable();
assert_eq!(Paint::green("go").to_string(), "go".to_string());
Paint::enable();
assert_ne!(Paint::green("go").to_string(), "go".to_string());
Returns true
if coloring is enabled and false
otherwise. Coloring is
enabled by default but can be enabled and disabled on-the-fly with the
Paint::enable()
and Paint::disable()
methods.
use yansi::Paint;
assert!(Paint::is_enabled());
Paint::disable();
assert!(!Paint::is_enabled());
Paint::enable();
assert!(Paint::is_enabled());
Enables ASCII terminal escape sequences on Windows consoles when
possible. Returns true
if escape sequence support was successfully
enabled and false
otherwise. On non-Windows targets, this method
always returns true
.
Support for escape sequences in Windows consoles was added in the
Windows 10 anniversary update. For targets with older Windows
installations, this method is expected to return false
.
use yansi::Paint;
Paint::enable_windows_ascii();
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Returns the "default value" for a type. Read more
Performs copy-assignment from source
. Read more
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self | 1.21.0 [src] |
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self | 1.21.0 [src] |
Compares and returns the minimum of two values. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given [Hasher
]. Read more
Feeds a slice of this type into the given [Hasher
]. Read more
Converts the given value to a String
. Read more
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Mutably borrows from an owned value. Read more