Struct Style
pub struct Style { /* private fields */ }
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
impl Style
const fn get_fg_color(self) -> Option<Color>Get the foreground color
const fn get_bg_color(self) -> Option<Color>Get the background color
const fn get_underline_color(self) -> Option<Color>const fn get_effects(self) -> Effectsconst fn is_plain(self) -> boolCheck if no styling is enabled
impl Style
const fn bold(self) -> SelfApply
boldeffectExamples
let style = anstyle::Style::new().bold();const fn dimmed(self) -> SelfApply
dimmedeffectExamples
let style = anstyle::Style::new().dimmed();const fn italic(self) -> SelfApply
italiceffectExamples
let style = anstyle::Style::new().italic();const fn underline(self) -> SelfApply
underlineeffectExamples
let style = anstyle::Style::new().underline();const fn blink(self) -> SelfApply
blinkeffectExamples
let style = anstyle::Style::new().blink();const fn invert(self) -> SelfApply
inverteffectExamples
let style = anstyle::Style::new().invert();Apply
hiddeneffectExamples
let style = anstyle::Style::new().hidden();const fn strikethrough(self) -> SelfApply
strikethrougheffectExamples
let style = anstyle::Style::new().strikethrough();
impl Style
const fn new() -> SelfNo effects enabled
Examples
let style = anstyle::Style::new();const fn fg_color(self, fg: Option<Color>) -> SelfSet foreground color
Examples
let style = anstyle::Style::new().fg_color(Some(anstyle::AnsiColor::Red.into()));const fn bg_color(self, bg: Option<Color>) -> SelfSet background color
Examples
let style = anstyle::Style::new().bg_color(Some(anstyle::AnsiColor::Red.into()));const fn underline_color(self, underline: Option<Color>) -> SelfSet underline color
Examples
let style = anstyle::Style::new().underline_color(Some(anstyle::AnsiColor::Red.into()));const fn effects(self, effects: Effects) -> SelfSet text effects
Examples
let style = anstyle::Style::new().effects(anstyle::Effects::BOLD | anstyle::Effects::UNDERLINE);fn render(self) -> impl Display + CopyRender the ANSI code
Stylealso implementsDisplaydirectly, so calling this method is optional.fn write_to(self, write: &mut dyn Write) -> Result<()>Write the ANSI code
fn render_reset(self) -> impl Display + CopyRenders the relevant [
Reset][crate::Reset] codeUnlike [
Reset::render][crate::Reset::render], this will elide the code if there is nothing to reset.fn write_reset_to(self, write: &mut dyn Write) -> Result<()>Write the relevant [
Reset][crate::Reset] codeUnlike [
Reset::render][crate::Reset::render], this will elide the code if there is nothing to reset.
Trait Implementations
impl BitOr<Effects> for Style
type Output = Style;fn bitor(self, rhs: Effects) -> Self
impl BitOrAssign<Effects> for Style
fn bitor_assign(&mut self, other: Effects)
impl Clone for Style
fn clone(&self) -> Self
impl Copy for Style
impl Debug for Style
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Default for Style
fn default() -> Self
impl Display for Style
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for Style
impl From<Effects> for Style
fn from(effects: Effects) -> Self
impl Hash for Style
fn hash<__H: Hasher>(&self, state: &mut __H)
impl Ord for Style
fn cmp(&self, other: &Self) -> Ordering
impl PartialEq for Style
fn eq(&self, other: &Self) -> bool
impl PartialEq<Effects> for Style
fn eq(&self, other: &Effects) -> bool
impl PartialOrd for Style
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
impl StructuralPartialEq for Style
impl Sub<Effects> for Style
type Output = Style;fn sub(self, other: Effects) -> Self
impl SubAssign<Effects> for Style
fn sub_assign(&mut self, other: Effects)