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: Color>(self) -> Self
pub const fn fg<C: Color>(self) -> Self
Set the foreground color generically
use owo_colors::{OwoColorize, colors::*};
println!("{}", "red foreground".fg::<Red>());
Sourcepub const fn bg<C: Color>(self) -> Self
pub const fn bg<C: Color>(self) -> Self
Set the background color generically.
use owo_colors::{OwoColorize, colors::*};
println!("{}", "black background".bg::<Black>());
Sourcepub const fn remove_fg(self) -> Self
pub const fn remove_fg(self) -> Self
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) -> Self
pub const fn remove_bg(self) -> Self
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) -> Self
pub const fn on_magenta(self) -> Self
Change the foreground color to magenta
Sourcepub const fn default_color(self) -> Self
pub const fn default_color(self) -> Self
Change the foreground color to the terminal default
Sourcepub const fn on_default_color(self) -> Self
pub const fn on_default_color(self) -> Self
Change the foreground color to the terminal default
Sourcepub const fn bright_black(self) -> Self
pub const fn bright_black(self) -> Self
Change the foreground color to bright black
Sourcepub const fn on_bright_black(self) -> Self
pub const fn on_bright_black(self) -> Self
Change the foreground color to bright black
Sourcepub const fn bright_red(self) -> Self
pub const fn bright_red(self) -> Self
Change the foreground color to bright red
Sourcepub const fn on_bright_red(self) -> Self
pub const fn on_bright_red(self) -> Self
Change the foreground color to bright red
Sourcepub const fn bright_green(self) -> Self
pub const fn bright_green(self) -> Self
Change the foreground color to bright green
Sourcepub const fn on_bright_green(self) -> Self
pub const fn on_bright_green(self) -> Self
Change the foreground color to bright green
Sourcepub const fn bright_yellow(self) -> Self
pub const fn bright_yellow(self) -> Self
Change the foreground color to bright yellow
Sourcepub const fn on_bright_yellow(self) -> Self
pub const fn on_bright_yellow(self) -> Self
Change the foreground color to bright yellow
Sourcepub const fn bright_blue(self) -> Self
pub const fn bright_blue(self) -> Self
Change the foreground color to bright blue
Sourcepub const fn on_bright_blue(self) -> Self
pub const fn on_bright_blue(self) -> Self
Change the foreground color to bright blue
Sourcepub const fn bright_magenta(self) -> Self
pub const fn bright_magenta(self) -> Self
Change the foreground color to bright magenta
Sourcepub const fn on_bright_magenta(self) -> Self
pub const fn on_bright_magenta(self) -> Self
Change the foreground color to bright magenta
Sourcepub const fn bright_purple(self) -> Self
pub const fn bright_purple(self) -> Self
Change the foreground color to bright purple
Sourcepub const fn on_bright_purple(self) -> Self
pub const fn on_bright_purple(self) -> Self
Change the foreground color to bright purple
Sourcepub const fn bright_cyan(self) -> Self
pub const fn bright_cyan(self) -> Self
Change the foreground color to bright cyan
Sourcepub const fn on_bright_cyan(self) -> Self
pub const fn on_bright_cyan(self) -> Self
Change the foreground color to bright cyan
Sourcepub const fn bright_white(self) -> Self
pub const fn bright_white(self) -> Self
Change the foreground color to bright white
Sourcepub const fn on_bright_white(self) -> Self
pub const fn on_bright_white(self) -> Self
Change the foreground color to bright white
Sourcepub const fn blink_fast(self) -> Self
pub const fn blink_fast(self) -> Self
Make the text blink (but fast!)
Hide the text
Sourcepub const fn strikethrough(self) -> Self
pub const fn strikethrough(self) -> Self
Cross out the text
Sourcepub const fn remove_effect(self, effect: Effect) -> Self
pub const fn remove_effect(self, effect: Effect) -> Self
Remove a given effect from the style
Sourcepub const fn effects(self, effects: &[Effect]) -> Self
pub const fn effects(self, effects: &[Effect]) -> Self
Apply a given set of effects to the style
Sourcepub const fn remove_effects(self, effects: &[Effect]) -> Self
pub const fn remove_effects(self, effects: &[Effect]) -> Self
Remove a given set of effects from the style
Sourcepub const fn remove_all_effects(self) -> Self
pub const fn remove_all_effects(self) -> Self
Disables all the given effects from the style
Sourcepub fn color<Color: DynColor>(self, color: Color) -> Self
pub fn color<Color: DynColor>(self, color: Color) -> Self
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: DynColor>(self, color: Color) -> Self
pub fn on_color<Color: DynColor>(self, color: Color) -> Self
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) -> Self
pub const fn fg_rgb<const R: u8, const G: u8, const B: u8>(self) -> Self
Set the foreground color to a specific RGB value.
Sourcepub const fn bg_rgb<const R: u8, const G: u8, const B: u8>(self) -> Self
pub const fn bg_rgb<const R: u8, const G: u8, const B: u8>(self) -> Self
Set the background color to a specific RGB value.
Sourcepub const fn truecolor(self, r: u8, g: u8, b: u8) -> Self
pub const fn truecolor(self, r: u8, g: u8, b: u8) -> Self
Sets the foreground color to an RGB value.
Sourcepub const fn on_truecolor(self, r: u8, g: u8, b: u8) -> Self
pub const fn on_truecolor(self, r: u8, g: u8, b: u8) -> Self
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
Sourcepub fn fmt_prefix(&self, f: &mut Formatter<'_>) -> Result
pub fn fmt_prefix(&self, f: &mut Formatter<'_>) -> Result
Applies the ANSI-prefix for this style to the given formatter
Sourcepub fn fmt_suffix(&self, f: &mut Formatter<'_>) -> Result
pub fn fmt_suffix(&self, f: &mut Formatter<'_>) -> Result
Applies the ANSI-suffix for this style to the given formatter
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<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C: Color>(&self) -> FgColorDisplay<'_, C, Self>
fn fg<C: Color>(&self) -> FgColorDisplay<'_, C, Self>
Source§fn bg<C: Color>(&self) -> BgColorDisplay<'_, C, Self>
fn bg<C: Color>(&self) -> BgColorDisplay<'_, C, Self>
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: DynColor>(
&self,
color: Color,
) -> FgDynColorDisplay<'_, Color, Self>
fn color<Color: DynColor>( &self, color: Color, ) -> FgDynColorDisplay<'_, Color, Self>
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read moreSource§fn on_color<Color: DynColor>(
&self,
color: Color,
) -> BgDynColorDisplay<'_, Color, Self>
fn on_color<Color: DynColor>( &self, color: Color, ) -> BgDynColorDisplay<'_, Color, Self>
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more