Struct yansi::Style [−][src]
#[repr(packed)]pub struct Style { /* fields omitted */ }
Represents a set of styling options.
See the crate level documentation for usage information.
Method Glossary
The Style structure exposes many methods for convenience. The majority of
these methods are shared with Paint.
Unstyled Constructors
Return a new Style structure with no styling applied.
Foreground Color Constructors
Return a new Style structure with a foreground color applied.
Style::black()Style::red()Style::green()Style::yellow()Style::blue()Style::purple()Style::cyan()Style::white()
Getters
Return information about a Style structure.
style.fg_color()style.bg_color()style.is_masked()style.is_bold()style.is_dimmed()style.is_italic()style.is_underline()style.is_blink()style.is_invert()style.is_hidden()style.is_strikethrough()
Setters
Set a style property on a given Style structure.
style.fg(color: Color)style.bg(color: Color)style.mask()style.bold()style.dimmed()style.italic()style.underline()style.blink()style.invert()style.hidden()style.strikethrough()
These methods can be chained:
use yansi::Style; Style::red().underline().invert().italic().dimmed().bold();
Converters
Convert a Style into another structure.
Raw Formatters
Write the raw ANSI codes for a given Style to a fmt::Formatter.
Methods
impl Style[src]
impl Stylepub fn new() -> Style[src]
pub fn new() -> StyleDefault, unstylized Style. This is identical to Style::default().
use yansi::Style; let plain = Style::new(); assert_eq!(plain, Style::default());
pub fn masked() -> Style[src]
pub fn masked() -> StyleDefault, unstylized but masked Style. Aside from masking, this is
identical to Style::default().
An item with masked styling is not written out when painting is
disabled during Display or Debug invocations. When painting is
enabled, masking has no effect.
use yansi::Style; let plain = Style::masked(); assert_eq!(plain, Style::default());
pub fn black() -> Style[src]
pub fn black() -> StyleConstructs a new Stylestructure with the foreground color set to black.
use yansi::Style; let black = Style::black(); println!("This is going to be black: {}", black.paint("yay!"));
pub fn red() -> Style[src]
pub fn red() -> StyleConstructs a new Stylestructure with the foreground color set to red.
use yansi::Style; let red = Style::red(); println!("This is going to be red: {}", red.paint("yay!"));
pub fn green() -> Style[src]
pub fn green() -> StyleConstructs a new Stylestructure with the foreground color set to green.
use yansi::Style; let green = Style::green(); println!("This is going to be green: {}", green.paint("yay!"));
pub fn yellow() -> Style[src]
pub fn yellow() -> StyleConstructs a new Stylestructure with the foreground color set to yellow.
use yansi::Style; let yellow = Style::yellow(); println!("This is going to be yellow: {}", yellow.paint("yay!"));
pub fn blue() -> Style[src]
pub fn blue() -> StyleConstructs a new Stylestructure with the foreground color set to blue.
use yansi::Style; let blue = Style::blue(); println!("This is going to be blue: {}", blue.paint("yay!"));
pub fn purple() -> Style[src]
pub fn purple() -> StyleConstructs a new Stylestructure with the foreground color set to purple.
use yansi::Style; let purple = Style::purple(); println!("This is going to be purple: {}", purple.paint("yay!"));
pub fn cyan() -> Style[src]
pub fn cyan() -> StyleConstructs a new Stylestructure with the foreground color set to cyan.
use yansi::Style; let cyan = Style::cyan(); println!("This is going to be cyan: {}", cyan.paint("yay!"));
pub fn white() -> Style[src]
pub fn white() -> StyleConstructs a new Stylestructure with the foreground color set to white.
use yansi::Style; let white = Style::white(); println!("This is going to be white: {}", white.paint("yay!"));
pub fn fg_color(&self) -> Color[src]
pub fn fg_color(&self) -> ColorReturns the foreground color of self.
use yansi::{Style, Color}; let plain = Style::new(); assert_eq!(plain.fg_color(), Color::Unset); let red = plain.fg(Color::Red); assert_eq!(red.fg_color(), Color::Red);
pub fn bg_color(&self) -> Color[src]
pub fn bg_color(&self) -> ColorReturns the foreground color of self.
use yansi::{Style, Color}; let plain = Style::new(); assert_eq!(plain.bg_color(), Color::Unset); let white = plain.bg(Color::White); assert_eq!(white.bg_color(), Color::White);
pub fn is_masked(&self) -> bool[src]
pub fn is_masked(&self) -> boolReturns true if self is masked.
use yansi::Style; let plain = Style::new(); assert!(!plain.is_masked()); let masked = plain.mask(); assert!(masked.is_masked());
pub fn is_bold(&self) -> bool[src]
pub fn is_bold(&self) -> boolReturns trueif the bold property is set on self.
use yansi::Style; let plain = Style::new(); assert!(!plain.is_bold()); let styled = plain.bold(); assert!(styled.is_bold());
pub fn is_dimmed(&self) -> bool[src]
pub fn is_dimmed(&self) -> boolReturns trueif the dimmed property is set on self.
use yansi::Style; let plain = Style::new(); assert!(!plain.is_dimmed()); let styled = plain.dimmed(); assert!(styled.is_dimmed());
pub fn is_italic(&self) -> bool[src]
pub fn is_italic(&self) -> boolReturns trueif the italic property is set on self.
use yansi::Style; let plain = Style::new(); assert!(!plain.is_italic()); let styled = plain.italic(); assert!(styled.is_italic());
pub fn is_underline(&self) -> bool[src]
pub fn is_underline(&self) -> boolReturns trueif the underline property is set on self.
use yansi::Style; let plain = Style::new(); assert!(!plain.is_underline()); let styled = plain.underline(); assert!(styled.is_underline());
pub fn is_blink(&self) -> bool[src]
pub fn is_blink(&self) -> boolReturns trueif the blink property is set on self.
use yansi::Style; let plain = Style::new(); assert!(!plain.is_blink()); let styled = plain.blink(); assert!(styled.is_blink());
pub fn is_invert(&self) -> bool[src]
pub fn is_invert(&self) -> boolReturns trueif the invert property is set on self.
use yansi::Style; let plain = Style::new(); assert!(!plain.is_invert()); let styled = plain.invert(); assert!(styled.is_invert());
Returns trueif the hidden property is set on self.
use yansi::Style; let plain = Style::new(); assert!(!plain.is_hidden()); let styled = plain.hidden(); assert!(styled.is_hidden());
pub fn is_strikethrough(&self) -> bool[src]
pub fn is_strikethrough(&self) -> boolReturns trueif the strikethrough property is set on self.
use yansi::Style; let plain = Style::new(); assert!(!plain.is_strikethrough()); let styled = plain.strikethrough(); assert!(styled.is_strikethrough());
pub fn fg(self, color: Color) -> Style[src]
pub fn fg(self, color: Color) -> StyleSets the foreground to color.
use yansi::{Color, Style}; let red_fg = Style::new().fg(Color::Red);
pub fn bg(self, color: Color) -> Style[src]
pub fn bg(self, color: Color) -> StyleSets the background to color.
use yansi::{Color, Style}; let red_bg = Style::new().bg(Color::Red);
pub fn mask(self) -> Style[src]
pub fn mask(self) -> StyleSets self to be masked.
An item with masked styling is not written out when painting is
disabled during Display or Debug invocations. When painting is
enabled, masking has no effect.
use yansi::Style; let masked = Style::new().mask(); // "Whoops! " will only print when coloring is enabled. println!("{}Something happened.", masked.paint("Whoops! "));
pub fn bold(self) -> Style[src]
pub fn bold(self) -> StyleEnables the bold style on self.
use yansi::Paint; println!("Using bold: {}", Paint::new("hi").bold());
pub fn dimmed(self) -> Style[src]
pub fn dimmed(self) -> StyleEnables the dimmed style on self.
use yansi::Paint; println!("Using dimmed: {}", Paint::new("hi").dimmed());
pub fn italic(self) -> Style[src]
pub fn italic(self) -> StyleEnables the italic style on self.
use yansi::Paint; println!("Using italic: {}", Paint::new("hi").italic());
pub fn underline(self) -> Style[src]
pub fn underline(self) -> StyleEnables the underline style on self.
use yansi::Paint; println!("Using underline: {}", Paint::new("hi").underline());
pub fn blink(self) -> Style[src]
pub fn blink(self) -> StyleEnables the blink style on self.
use yansi::Paint; println!("Using blink: {}", Paint::new("hi").blink());
pub fn invert(self) -> Style[src]
pub fn invert(self) -> StyleEnables 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());
pub fn strikethrough(self) -> Style[src]
pub fn strikethrough(self) -> StyleEnables the strikethrough style on self.
use yansi::Paint; println!("Using strikethrough: {}", Paint::new("hi").strikethrough());
pub fn paint<T>(self, item: T) -> Paint<T>[src]
pub fn paint<T>(self, item: T) -> Paint<T>Constructs a new Paint structure that encapsulates item with the
style set to self.
use yansi::{Style, Color}; let alert = Style::red().bold().underline(); println!("Alert: {}", alert.paint("This thing happened!"));
pub fn fmt_prefix(&self, f: &mut Formatter) -> Result[src]
pub fn fmt_prefix(&self, f: &mut Formatter) -> ResultWrites the ANSI code prefix for the currently set styles.
This method is intended to be used inside of fmt::Display and
fmt::Debug implementations for custom or specialized use-cases. Most
users should use Paint for all painting needs.
Example
use std::fmt; use yansi::Style; struct CustomItem { item: u32, style: Style } impl fmt::Display for CustomItem { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.style.fmt_prefix(f)?; write!(f, "number: {}", self.item)?; self.style.fmt_suffix(f) } }
pub fn fmt_suffix(&self, f: &mut Formatter) -> Result[src]
pub fn fmt_suffix(&self, f: &mut Formatter) -> ResultWrites the ANSI code suffix for the currently set styles.
This method is intended to be used inside of fmt::Display and
fmt::Debug implementations for custom or specialized use-cases. Most
users should use Paint for all painting needs.
Example
use std::fmt; use yansi::Style; struct CustomItem { item: u32, style: Style } impl fmt::Display for CustomItem { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.style.fmt_prefix(f)?; write!(f, "number: {}", self.item)?; self.style.fmt_suffix(f) } }
Trait Implementations
impl Default for Style[src]
impl Default for Styleimpl Debug for Style[src]
impl Debug for Stylefn fmt(&self, f: &mut Formatter) -> Result[src]
fn fmt(&self, f: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl Eq for Style[src]
impl Eq for Styleimpl Ord for Style[src]
impl Ord for Stylefn cmp(&self, other: &Style) -> Ordering[src]
fn cmp(&self, other: &Style) -> OrderingThis method returns an Ordering between self and other. Read more
fn max(self, other: Self) -> Self1.21.0[src]
fn max(self, other: Self) -> SelfCompares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self1.21.0[src]
fn min(self, other: Self) -> SelfCompares and returns the minimum of two values. Read more
impl PartialOrd for Style[src]
impl PartialOrd for Stylefn partial_cmp(&self, other: &Style) -> Option<Ordering>[src]
fn partial_cmp(&self, other: &Style) -> Option<Ordering>This method returns an ordering between self and other values if one exists. Read more
fn lt(&self, other: &Style) -> bool[src]
fn lt(&self, other: &Style) -> boolThis method tests less than (for self and other) and is used by the < operator. Read more
fn le(&self, other: &Style) -> bool[src]
fn le(&self, other: &Style) -> boolThis method tests less than or equal to (for self and other) and is used by the <= operator. Read more
fn gt(&self, other: &Style) -> bool[src]
fn gt(&self, other: &Style) -> boolThis method tests greater than (for self and other) and is used by the > operator. Read more
fn ge(&self, other: &Style) -> bool[src]
fn ge(&self, other: &Style) -> boolThis method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
impl Hash for Style[src]
impl Hash for Stylefn hash<__H: Hasher>(&self, state: &mut __H)[src]
fn hash<__H: Hasher>(&self, state: &mut __H)Feeds this value into the given [Hasher]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, Feeds a slice of this type into the given [Hasher]. Read more
impl Copy for Style[src]
impl Copy for Styleimpl Clone for Style[src]
impl Clone for Stylefn clone(&self) -> Style[src]
fn clone(&self) -> StyleReturns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl PartialEq for Style[src]
impl PartialEq for Style