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,
}
A style is a collection of properties that can format a string
using ANSI escape codes.
The style's foreground colour, if it has one.
The style's background colour, if it has one.
Whether this style is bold.
Whether this style is dimmed.
Whether this style is italic.
Whether this style is underlined.
Whether this style is blinking.
Whether this style has reverse colours.
Whether this style is hidden.
Whether this style is struckthrough.
The prefix for this style.
The infix between this style and another.
The suffix for this style.
Creates a new Style with no differences.
Returns a Style
with the bold property set.
Returns a Style
with the dimmed property set.
Returns a Style
with the italic property set.
Returns a Style
with the underline property set.
Returns a Style
with the blink property set.
Returns a Style
with the reverse property set.
Returns a Style
with the hidden property set.
Returns a Style
with the hidden property set.
Returns a Style
with the foreground colour property set.
Returns a Style
with the background colour property set.
Return true if this Style
has no actual styles, and can be written
without any control characters.
Paints the given text with this colour, returning an ANSI string.
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Returns a style with no properties set. Formatting text using this
style returns the exact same text.
use ansi_term::Style;
assert_eq!(None, Style::default().foreground);
assert_eq!(None, Style::default().background);
assert_eq!(false, Style::default().is_bold);
assert_eq!("txt", Style::default().paint("txt").to_string());
Performs copy-assignment from source
. Read more
You can turn a Colour
into a Style
with the foreground colour set
with the From
trait.
use ansi_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));
Styles have a special Debug
implementation that only shows the fields that
are set. Fields that haven’t been touched aren’t included in the output.
This behaviour gets bypassed when using the alternate formatting mode
format!("{:#?}")
.
use ansi_term::Colour::{Red, Blue};
assert_eq!("Style { fg(Red), on(Blue), bold, italic }",
format!("{:?}", Red.on(Blue).bold().italic()));
Formats the value using the given formatter. 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
Mutably borrows from an owned value. 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
)