pub struct Style { /* private fields */ }
Expand description
A pre-computed style that can be applied to a struct using [OwoColorize::style
].
Its interface mimics that of [OwoColorize
], but instead of chaining methods on your
object, you instead chain them on the Style
object before applying it.
use owo_colors::{OwoColorize, Style};
let my_style = Style::new()
.red()
.on_white()
.strikethrough();
println!("{}", "red text, white background, struck through".style(my_style));
Implementations§
Source§impl Style
impl Style
Sourcepub const fn style<T>(&self, target: T) -> Styled<T>
pub const fn style<T>(&self, target: T) -> Styled<T>
Apply the style to a given struct to output.
§Example
Usage in const contexts:
use owo_colors::{OwoColorize, Style, Styled};
const STYLED_TEXT: Styled<&'static str> = Style::new().bold().italic().style("bold and italic text");
println!("{}", STYLED_TEXT);
Sourcepub const fn fg<C>(self) -> Stylewhere
C: Color,
pub const fn fg<C>(self) -> Stylewhere
C: Color,
Set the foreground color generically
use owo_colors::{OwoColorize, colors::*};
println!("{}", "red foreground".fg::<Red>());
Sourcepub const fn bg<C>(self) -> Stylewhere
C: Color,
pub const fn bg<C>(self) -> Stylewhere
C: Color,
Set the background color generically.
use owo_colors::{OwoColorize, colors::*};
println!("{}", "black background".bg::<Black>());
Sourcepub const fn remove_fg(self) -> Style
pub const fn remove_fg(self) -> Style
Removes the foreground color from the style. Note that this does not apply the default color, but rather represents not changing the current terminal color.
If you wish to actively change the terminal color back to the default, see
Style::default_color
.
Sourcepub const fn remove_bg(self) -> Style
pub const fn remove_bg(self) -> Style
Removes the background color from the style. Note that this does not apply the default color, but rather represents not changing the current terminal color.
If you wish to actively change the terminal color back to the default, see
Style::on_default_color
.
Sourcepub const fn on_magenta(self) -> Style
pub const fn on_magenta(self) -> Style
Change the foreground color to magenta
Sourcepub const fn default_color(self) -> Style
pub const fn default_color(self) -> Style
Change the foreground color to the terminal default
Sourcepub const fn on_default_color(self) -> Style
pub const fn on_default_color(self) -> Style
Change the foreground color to the terminal default
Sourcepub const fn bright_black(self) -> Style
pub const fn bright_black(self) -> Style
Change the foreground color to bright black
Sourcepub const fn on_bright_black(self) -> Style
pub const fn on_bright_black(self) -> Style
Change the foreground color to bright black
Sourcepub const fn bright_red(self) -> Style
pub const fn bright_red(self) -> Style
Change the foreground color to bright red
Sourcepub const fn on_bright_red(self) -> Style
pub const fn on_bright_red(self) -> Style
Change the foreground color to bright red
Sourcepub const fn bright_green(self) -> Style
pub const fn bright_green(self) -> Style
Change the foreground color to bright green
Sourcepub const fn on_bright_green(self) -> Style
pub const fn on_bright_green(self) -> Style
Change the foreground color to bright green
Sourcepub const fn bright_yellow(self) -> Style
pub const fn bright_yellow(self) -> Style
Change the foreground color to bright yellow
Sourcepub const fn on_bright_yellow(self) -> Style
pub const fn on_bright_yellow(self) -> Style
Change the foreground color to bright yellow
Sourcepub const fn bright_blue(self) -> Style
pub const fn bright_blue(self) -> Style
Change the foreground color to bright blue
Sourcepub const fn on_bright_blue(self) -> Style
pub const fn on_bright_blue(self) -> Style
Change the foreground color to bright blue
Sourcepub const fn bright_magenta(self) -> Style
pub const fn bright_magenta(self) -> Style
Change the foreground color to bright magenta
Sourcepub const fn on_bright_magenta(self) -> Style
pub const fn on_bright_magenta(self) -> Style
Change the foreground color to bright magenta
Sourcepub const fn bright_purple(self) -> Style
pub const fn bright_purple(self) -> Style
Change the foreground color to bright purple
Sourcepub const fn on_bright_purple(self) -> Style
pub const fn on_bright_purple(self) -> Style
Change the foreground color to bright purple
Sourcepub const fn bright_cyan(self) -> Style
pub const fn bright_cyan(self) -> Style
Change the foreground color to bright cyan
Sourcepub const fn on_bright_cyan(self) -> Style
pub const fn on_bright_cyan(self) -> Style
Change the foreground color to bright cyan
Sourcepub const fn bright_white(self) -> Style
pub const fn bright_white(self) -> Style
Change the foreground color to bright white
Sourcepub const fn on_bright_white(self) -> Style
pub const fn on_bright_white(self) -> Style
Change the foreground color to bright white
Sourcepub const fn blink_fast(self) -> Style
pub const fn blink_fast(self) -> Style
Make the text blink (but fast!)
Hide the text
Sourcepub const fn strikethrough(self) -> Style
pub const fn strikethrough(self) -> Style
Cross out the text
Sourcepub const fn remove_effect(self, effect: Effect) -> Style
pub const fn remove_effect(self, effect: Effect) -> Style
Remove a given effect from the style
Sourcepub const fn effects(self, effects: &[Effect]) -> Style
pub const fn effects(self, effects: &[Effect]) -> Style
Apply a given set of effects to the style
Sourcepub const fn remove_effects(self, effects: &[Effect]) -> Style
pub const fn remove_effects(self, effects: &[Effect]) -> Style
Remove a given set of effects from the style
Sourcepub const fn remove_all_effects(self) -> Style
pub const fn remove_all_effects(self) -> Style
Disables all the given effects from the style
Sourcepub fn color<Color>(self, color: Color) -> Stylewhere
Color: DynColor,
pub fn color<Color>(self, color: Color) -> Stylewhere
Color: DynColor,
Set the foreground color at runtime. Only use if you do not know which color will be used at
compile-time. If the color is constant, use either OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
,
use owo_colors::{OwoColorize, AnsiColors};
println!("{}", "green".color(AnsiColors::Green));
Sourcepub fn on_color<Color>(self, color: Color) -> Stylewhere
Color: DynColor,
pub fn on_color<Color>(self, color: Color) -> Stylewhere
Color: DynColor,
Set the background color at runtime. Only use if you do not know what color to use at
compile-time. If the color is constant, use either OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
,
use owo_colors::{OwoColorize, AnsiColors};
println!("{}", "yellow background".on_color(AnsiColors::BrightYellow));
Sourcepub const fn fg_rgb<const R: u8, const G: u8, const B: u8>(self) -> Style
pub const fn fg_rgb<const R: u8, const G: u8, const B: u8>(self) -> Style
Set the foreground color to a specific RGB value.
Sourcepub const fn bg_rgb<const R: u8, const G: u8, const B: u8>(self) -> Style
pub const fn bg_rgb<const R: u8, const G: u8, const B: u8>(self) -> Style
Set the background color to a specific RGB value.
Sourcepub const fn truecolor(self, r: u8, g: u8, b: u8) -> Style
pub const fn truecolor(self, r: u8, g: u8, b: u8) -> Style
Sets the foreground color to an RGB value.
Sourcepub const fn on_truecolor(self, r: u8, g: u8, b: u8) -> Style
pub const fn on_truecolor(self, r: u8, g: u8, b: u8) -> Style
Sets the background color to an RGB value.
Sourcepub const fn prefix_formatter(&self) -> StylePrefixFormatter
pub const fn prefix_formatter(&self) -> StylePrefixFormatter
Returns a formatter for the style’s ANSI prefix.
This can be used to separate out the prefix and suffix of a style.
§Example
use owo_colors::Style;
use std::fmt::Write;
let style = Style::new().red().on_blue();
let prefix = style.prefix_formatter();
let suffix = style.suffix_formatter();
// Write the prefix and suffix separately.
let mut output = String::new();
write!(output, "{}", prefix);
output.push_str("Hello");
write!(output, "{}", suffix);
assert_eq!(output, "\x1b[31;44mHello\x1b[0m");
Sourcepub const fn suffix_formatter(&self) -> StyleSuffixFormatter
pub const fn suffix_formatter(&self) -> StyleSuffixFormatter
Returns a formatter for the style’s ANSI suffix.
This can be used to separate out the prefix and suffix of a style.
§Example
Trait Implementations§
impl Copy 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more