pub struct Style {
pub foreground: Option<Colour>,
pub background: Option<Colour>,
pub is_bold: bool,
pub is_dimmed: bool,
pub is_italic: bool,
pub is_underline: bool,
pub is_blink: bool,
pub is_reverse: bool,
pub is_hidden: bool,
pub is_strikethrough: bool,
}Expand description
A style is a collection of properties that can format a string using ANSI escape codes.
§Examples
use yansi_term::{Style, Colour};
let style = Style::new().bold().on(Colour::Black);
println!("{}", style.paint("Bold on black"));Fields§
§foreground: Option<Colour>The style’s foreground colour, if it has one.
background: Option<Colour>The style’s background colour, if it has one.
is_bold: boolWhether this style is bold.
is_dimmed: boolWhether this style is dimmed.
is_italic: boolWhether this style is italic.
is_underline: boolWhether this style is underlined.
is_blink: boolWhether this style is blinking.
is_reverse: boolWhether this style has reverse colours.
Whether this style is hidden.
is_strikethrough: boolWhether this style is struckthrough.
Implementations§
Source§impl Style
impl Style
Sourcepub fn write_prefix(&self, f: &mut Formatter<'_>) -> Result<bool, Error>
pub fn write_prefix(&self, f: &mut Formatter<'_>) -> Result<bool, Error>
Write any bytes that go before a piece of text to the given writer.
Sourcepub fn write_reset(f: &mut Formatter<'_>) -> Result
pub fn write_reset(f: &mut Formatter<'_>) -> Result
Write any bytes that go after a piece of text to the given writer.
Source§impl Style
impl Style
Sourcepub fn new() -> Style
pub fn new() -> Style
Creates a new Style with no properties set.
§Examples
use yansi_term::Style;
let style = Style::new();
println!("{}", style.paint("hi"));Sourcepub fn bold(self) -> Self
pub fn bold(self) -> Self
Returns a Style with the bold property set.
§Examples
use yansi_term::Style;
let style = Style::new().bold();
println!("{}", style.paint("hey"));Sourcepub fn dimmed(self) -> Self
pub fn dimmed(self) -> Self
Returns a Style with the dimmed property set.
§Examples
use yansi_term::Style;
let style = Style::new().dimmed();
println!("{}", style.paint("sup"));Sourcepub fn italic(self) -> Self
pub fn italic(self) -> Self
Returns a Style with the italic property set.
§Examples
use yansi_term::Style;
let style = Style::new().italic();
println!("{}", style.paint("greetings"));Sourcepub fn underline(self) -> Self
pub fn underline(self) -> Self
Returns a Style with the underline property set.
§Examples
use yansi_term::Style;
let style = Style::new().underline();
println!("{}", style.paint("salutations"));Sourcepub fn blink(self) -> Self
pub fn blink(self) -> Self
Returns a Style with the blink property set.
§Examples
use yansi_term::Style;
let style = Style::new().blink();
println!("{}", style.paint("wazzup"));Sourcepub fn reverse(self) -> Self
pub fn reverse(self) -> Self
Returns a Style with the reverse property set.
§Examples
use yansi_term::Style;
let style = Style::new().reverse();
println!("{}", style.paint("aloha"));Returns a Style with the hidden property set.
§Examples
use yansi_term::Style;
let style = Style::new().hidden();
println!("{}", style.paint("ahoy"));Sourcepub fn strikethrough(self) -> Self
pub fn strikethrough(self) -> Self
Returns a Style with the strikethrough property set.
§Examples
use yansi_term::Style;
let style = Style::new().strikethrough();
println!("{}", style.paint("yo"));Sourcepub fn fg(self, foreground: Colour) -> Self
pub fn fg(self, foreground: Colour) -> Self
Returns a Style with the foreground colour property set.
§Examples
use yansi_term::{Style, Colour};
let style = Style::new().fg(Colour::Yellow);
println!("{}", style.paint("hi"));Trait Implementations§
Source§impl From<Colour> for Style
impl From<Colour> for Style
Source§fn from(colour: Colour) -> Style
fn from(colour: Colour) -> Style
You can turn a Colour into a Style with the foreground colour set
with the From trait.
use yansi_term::{Style, Colour};
let green_foreground = Style::default().fg(Colour::Green);
assert_eq!(green_foreground, Colour::Green.normal());
assert_eq!(green_foreground, Colour::Green.into());
assert_eq!(green_foreground, Style::from(Colour::Green));