Struct yansi::Paint [] [src]

pub struct Paint<T> { /* fields omitted */ }

A structure encapsulating an item and styling.

See the crate level documentation for usage information.

Method Glossary

The Paint structure exposes many methods for convenience.

Unstyled Constructors

Return a new Paint structure with no styling applied.

Foreground Color Constructors

Return a new Paint structure with a foreground color applied.

Getters

Return information about the Paint structure.

Setters

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();

Global Methods

Modify or observe the global behavior of painting.

Methods

impl<T> Paint<T>
[src]

[src]

Constructs a new Paint structure encapsulating item with no styling.

use yansi::Paint;

assert_eq!(Paint::new("hello!").to_string(), "hello!".to_string());

[src]

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;

// The emoji won't be printed when coloring is disabled.
println!("{}Sprout!", Paint::masked("🌱 "));

[src]

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!"));

[src]

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!"));

[src]

Constructs a new Paintstructure encapsulating itemwith the foreground color set to black.

use yansi::Paint; 

println!("This is going to be black: {}", Paint::black("yay!"));

[src]

Constructs a new Paintstructure encapsulating itemwith the foreground color set to red.

use yansi::Paint; 

println!("This is going to be red: {}", Paint::red("yay!"));

[src]

Constructs a new Paintstructure encapsulating itemwith the foreground color set to green.

use yansi::Paint; 

println!("This is going to be green: {}", Paint::green("yay!"));

[src]

Constructs a new Paintstructure encapsulating itemwith the foreground color set to yellow.

use yansi::Paint; 

println!("This is going to be yellow: {}", Paint::yellow("yay!"));

[src]

Constructs a new Paintstructure encapsulating itemwith the foreground color set to blue.

use yansi::Paint; 

println!("This is going to be blue: {}", Paint::blue("yay!"));

[src]

Constructs a new Paintstructure encapsulating itemwith the foreground color set to purple.

use yansi::Paint; 

println!("This is going to be purple: {}", Paint::purple("yay!"));

[src]

Constructs a new Paintstructure encapsulating itemwith the foreground color set to cyan.

use yansi::Paint; 

println!("This is going to be cyan: {}", Paint::cyan("yay!"));

[src]

Constructs a new Paintstructure encapsulating itemwith the foreground color set to white.

use yansi::Paint; 

println!("This is going to be white: {}", Paint::white("yay!"));

[src]

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());

[src]

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();

// Using this method.
println!("Alert: {}", Paint::new("This thing happened!").with_style(s));

// Using the `style.paint()` method.
println!("Alert: {}", s.paint("This thing happened!"));

[src]

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;

// "Whoops! " will only print when coloring is enabled.
println!("{}Something happened.", Paint::red("Whoops! ").mask());

[src]

Sets the foreground to color.

use yansi::Paint;
use yansi::Color::Red;

println!("Red foreground: {}", Paint::new("hi!").fg(Red));

[src]

Sets the background to color.

use yansi::Paint;
use yansi::Color::Yellow;

println!("Yellow background: {}", Paint::new("hi!").bg(Yellow));

[src]

Enables the bold style on self.

use yansi::Paint; 

println!("Using bold: {}", Paint::new("hi").bold());

[src]

Enables the dimmed style on self.

use yansi::Paint; 

println!("Using dimmed: {}", Paint::new("hi").dimmed());

[src]

Enables the italic style on self.

use yansi::Paint; 

println!("Using italic: {}", Paint::new("hi").italic());

[src]

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());

[src]

Enables the invert style on self.

use yansi::Paint; 

println!("Using invert: {}", Paint::new("hi").invert());

[src]

Enables the hidden style on self.

use yansi::Paint; 

println!("Using hidden: {}", Paint::new("hi").hidden());

[src]

Enables the strikethrough style on self.

use yansi::Paint; 

println!("Using strikethrough: {}", Paint::new("hi").strikethrough());

impl Paint<()>
[src]

[src]

Disables coloring globally.

Example

use yansi::Paint;

// With coloring enabled, ANSI color codes are emitted.
assert_ne!(Paint::green("go").to_string(), "go".to_string());

// With coloring disabled, ANSI color codes are _not_ emitted.
Paint::disable();
assert_eq!(Paint::green("go").to_string(), "go".to_string());

[src]

Enables coloring globally. Coloring is enabled by default, so this method should only be called to re enable coloring.

Example

use yansi::Paint;

// With coloring disabled, ANSI color codes are _not_ emitted.
Paint::disable();
assert_eq!(Paint::green("go").to_string(), "go".to_string());

// Reenabling causes color code to be emitted.
Paint::enable();
assert_ne!(Paint::green("go").to_string(), "go".to_string());

[src]

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.

Example

use yansi::Paint;

// Coloring is enabled by default.
assert!(Paint::is_enabled());

// Disable it with `Paint::disable()`.
Paint::disable();
assert!(!Paint::is_enabled());

// Reenable with `Paint::enable()`.
Paint::enable();
assert!(Paint::is_enabled());

[src]

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.

Example

use yansi::Paint;

// A best-effort Windows ASCII terminal support enabling.
Paint::enable_windows_ascii();

Trait Implementations

impl<T: Default> Default for Paint<T>
[src]

[src]

Returns the "default value" for a type. Read more

impl<T: Eq> Eq for Paint<T>
[src]

impl<T: PartialEq> PartialEq for Paint<T>
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl<T: Ord> Ord for Paint<T>
[src]

[src]

This method returns an Ordering between self and other. Read more

1.21.0
[src]

Compares and returns the maximum of two values. Read more

1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl<T: PartialOrd> PartialOrd for Paint<T>
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<T: Hash> Hash for Paint<T>
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<T: Copy> Copy for Paint<T>
[src]

impl<T: Clone> Clone for Paint<T>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: Display> Display for Paint<T>
[src]

[src]

Formats the value using the given formatter. Read more

impl<T: Debug> Debug for Paint<T>
[src]

[src]

Formats the value using the given formatter. Read more