pub struct Style { /* private fields */ }Expand description
ANSI Text styling
You can print a Style to render the corresponding ANSI code.
Using the alternate flag # will render the ANSI reset code, if needed.
Together, this makes it convenient to render styles using inline format arguments.
§Examples
let style = anstyle::Style::new().bold();
let value = 42;
println!("{style}{value}{style:#}");Implementations§
Source§impl Style
§Core
impl Style
§Core
Sourcepub const fn fg_color(self, fg: Option<Color>) -> Style
pub const fn fg_color(self, fg: Option<Color>) -> Style
Set foreground color
§Examples
let style = anstyle::Style::new().fg_color(Some(anstyle::AnsiColor::Red.into()));Sourcepub const fn bg_color(self, bg: Option<Color>) -> Style
pub const fn bg_color(self, bg: Option<Color>) -> Style
Set background color
§Examples
let style = anstyle::Style::new().bg_color(Some(anstyle::AnsiColor::Red.into()));Sourcepub const fn underline_color(self, underline: Option<Color>) -> Style
pub const fn underline_color(self, underline: Option<Color>) -> Style
Set underline color
§Examples
let style = anstyle::Style::new().underline_color(Some(anstyle::AnsiColor::Red.into()));Sourcepub const fn effects(self, effects: Effects) -> Style
pub const fn effects(self, effects: Effects) -> Style
Set text effects
§Examples
let style = anstyle::Style::new().effects(anstyle::Effects::BOLD | anstyle::Effects::UNDERLINE);Sourcepub fn render(self) -> impl Display + Copy
pub fn render(self) -> impl Display + Copy
Render the ANSI code
Style also implements Display directly, so calling this method is optional.
Sourcepub fn render_reset(self) -> impl Display + Copy
pub fn render_reset(self) -> impl Display + Copy
Renders the relevant Reset code
Unlike Reset::render, this will elide the code if there is nothing to reset.
Sourcepub fn write_reset_to(self, write: &mut dyn Write) -> Result<(), Error>
pub fn write_reset_to(self, write: &mut dyn Write) -> Result<(), Error>
Write the relevant Reset code
Unlike Reset::render, this will elide the code if there is nothing to reset.
Source§impl Style
§Convenience
impl Style
§Convenience
Source§impl Style
§Reflection
impl Style
§Reflection
Sourcepub const fn get_fg_color(self) -> Option<Color>
pub const fn get_fg_color(self) -> Option<Color>
Get the foreground color
Sourcepub const fn get_bg_color(self) -> Option<Color>
pub const fn get_bg_color(self) -> Option<Color>
Get the background color
pub const fn get_underline_color(self) -> Option<Color>
pub const fn get_effects(self) -> Effects
Trait Implementations§
Source§impl BitOr<Effects> for Style
§Examples
let style = anstyle::Style::new() | anstyle::Effects::BOLD.into();
impl BitOr<Effects> for Style
§Examples
let style = anstyle::Style::new() | anstyle::Effects::BOLD.into();Source§impl BitOrAssign<Effects> for Style
§Examples
let mut style = anstyle::Style::new();
style |= anstyle::Effects::BOLD.into();
impl BitOrAssign<Effects> for Style
§Examples
let mut style = anstyle::Style::new();
style |= anstyle::Effects::BOLD.into();Source§fn bitor_assign(&mut self, other: Effects)
fn bitor_assign(&mut self, other: Effects)
Performs the
|= operation. Read moreSource§impl ColorStyle for Style
impl ColorStyle for Style
Source§fn fg_magenta(self) -> Style
fn fg_magenta(self) -> Style
Create a new style with magenta foreground color
Source§fn fg_bright_red(self) -> Style
fn fg_bright_red(self) -> Style
Create a new style with bright red foreground color
Source§fn fg_bright_green(self) -> Style
fn fg_bright_green(self) -> Style
Create a new style with bright green foreground color
Source§fn fg_bright_blue(self) -> Style
fn fg_bright_blue(self) -> Style
Create a new style with bright blue foreground color
Source§fn fg_bright_yellow(self) -> Style
fn fg_bright_yellow(self) -> Style
Create a new style with bright yellow foreground color
Source§fn fg_bright_magenta(self) -> Style
fn fg_bright_magenta(self) -> Style
Create a new style with bright magenta foreground color
Source§fn fg_bright_cyan(self) -> Style
fn fg_bright_cyan(self) -> Style
Create a new style with bright cyan foreground color
Source§fn fg_bright_white(self) -> Style
fn fg_bright_white(self) -> Style
Create a new style with bright white foreground color
Source§fn with_dimmed(self) -> Style
fn with_dimmed(self) -> Style
Create a new style with dimmed formatting
Source§fn with_underline(self) -> Style
fn with_underline(self) -> Style
Create a new style with underline formatting
Source§impl From<Effects> for Style
§Examples
let style: anstyle::Style = anstyle::Effects::BOLD.into();
impl From<Effects> for Style
§Examples
let style: anstyle::Style = anstyle::Effects::BOLD.into();Source§impl Ord for Style
impl Ord for Style
Source§impl PartialEq<Effects> for Style
§Examples
let effects = anstyle::Effects::BOLD;
assert_eq!(anstyle::Style::new().effects(effects), effects);
assert_ne!(anstyle::Effects::UNDERLINE | effects, effects);
assert_ne!(anstyle::RgbColor(0, 0, 0).on_default() | effects, effects);
impl PartialEq<Effects> for Style
§Examples
let effects = anstyle::Effects::BOLD;
assert_eq!(anstyle::Style::new().effects(effects), effects);
assert_ne!(anstyle::Effects::UNDERLINE | effects, effects);
assert_ne!(anstyle::RgbColor(0, 0, 0).on_default() | effects, effects);Source§impl PartialOrd for Style
impl PartialOrd for Style
Source§impl Sub<Effects> for Style
§Examples
let style = anstyle::Style::new().bold().underline() - anstyle::Effects::BOLD.into();
impl Sub<Effects> for Style
§Examples
let style = anstyle::Style::new().bold().underline() - anstyle::Effects::BOLD.into();Source§impl SubAssign<Effects> for Style
§Examples
let mut style = anstyle::Style::new().bold().underline();
style -= anstyle::Effects::BOLD.into();
impl SubAssign<Effects> for Style
§Examples
let mut style = anstyle::Style::new().bold().underline();
style -= anstyle::Effects::BOLD.into();Source§fn sub_assign(&mut self, other: Effects)
fn sub_assign(&mut self, other: Effects)
Performs the
-= operation. Read moreimpl Copy for Style
impl Eq for Style
impl StructuralPartialEq for Style
Auto Trait Implementations§
impl Freeze for Style
impl RefUnwindSafe for Style
impl Send for Style
impl Sync for Style
impl Unpin for Style
impl UnwindSafe for Style
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Stylize for T
impl<T> Stylize for T
Source§fn bright_red(self) -> Styled<T>
fn bright_red(self) -> Styled<T>
Apply bright red color style to a value.
Source§fn bright_green(self) -> Styled<T>
fn bright_green(self) -> Styled<T>
Apply bright green color style to a value.
Source§fn bright_blue(self) -> Styled<T>
fn bright_blue(self) -> Styled<T>
Apply bright blue color style to a value.
Source§fn bright_yellow(self) -> Styled<T>
fn bright_yellow(self) -> Styled<T>
Apply bright yellow color style to a value.
Source§fn bright_magenta(self) -> Styled<T>
fn bright_magenta(self) -> Styled<T>
Apply bright magenta color style to a value.
Source§fn bright_cyan(self) -> Styled<T>
fn bright_cyan(self) -> Styled<T>
Apply bright cyan color style to a value.
Source§fn bright_white(self) -> Styled<T>
fn bright_white(self) -> Styled<T>
Apply bright white color style to a value.