pub struct Style {
pub fg: Color,
pub bg: Color,
pub underline: Option<Color>,
pub attributes: Attributes,
}Expand description
A style!
You don’t need to use this type directly, since Styled and StyledLink
both have the same methods for styling.
However, it may be useful to store a style and apply it to a value later:
let my_style = Style::new().bold().blue();
println!("{}", style("Hello").apply(my_style));Seee Stylize for more available styling options.
Style also implements Display so can be displayed directly.
This will apply the style to all following text until a new style is applied, making
it a less convenient way of styling text, but the option’s there.
Fields§
§fg: ColorForeground color.
bg: ColorBackground color.
underline: Option<Color>Underline color.
This sets the color used for underlining when the underline attribute
is enabled, but does not enable underlining by itself.
attributes: AttributesAttributes such as bold, italic, etc.
Implementations§
source§impl Style
impl Style
sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a new style with no attributes and default colors.
Examples found in repository?
examples/style.rs (line 4)
3 4 5 6 7 8 9 10 11 12 13 14
fn main() {
let my_style = Style::new().bold().blue();
println!("{}!", style("Hello").apply(my_style));
println!(
"{}",
style("Rust Language")
.apply(my_style)
.link("https://rust-lang.org")
);
}Trait Implementations§
source§impl Ord for Style
impl Ord for Style
source§impl PartialOrd for Style
impl PartialOrd for Style
source§impl Stylize for Style
impl Stylize for Style
source§fn underline_colored(self, color: impl Into<Color>) -> Self
fn underline_colored(self, color: impl Into<Color>) -> Self
Set the underline attribute and color.
source§fn attributes(self, attrs: Attributes) -> Self
fn attributes(self, attrs: Attributes) -> Self
Set the attributes. Read more
Set the hidden attribute.
source§fn strikethrough(self) -> Self
fn strikethrough(self) -> Self
Set the strikethrough attribute.
source§fn underline_black(self) -> Self
fn underline_black(self) -> Self
Set the underline attribute, and set the underline color to black.
source§fn underline_red(self) -> Self
fn underline_red(self) -> Self
Set the underline attribute, and set the underline color to red.
source§fn underline_green(self) -> Self
fn underline_green(self) -> Self
Set the underline attribute, and set the underline color to green.
source§fn underline_yellow(self) -> Self
fn underline_yellow(self) -> Self
Set the underline attribute, and set the underline color to yellow.
source§fn underline_blue(self) -> Self
fn underline_blue(self) -> Self
Set the underline attribute, and set the underline color to blue.
source§fn on_magenta(self) -> Self
fn on_magenta(self) -> Self
Set the background color to magenta.
source§fn underline_magenta(self) -> Self
fn underline_magenta(self) -> Self
Set the underline attribute, and set the underline color to magenta.
source§fn underline_cyan(self) -> Self
fn underline_cyan(self) -> Self
Set the underline attribute, and set the underline color to cyan.
source§fn underline_white(self) -> Self
fn underline_white(self) -> Self
Set the underline attribute, and set the underline color to white.
source§fn bright_black(self) -> Self
fn bright_black(self) -> Self
Set the foreground color to bright black.
source§fn on_bright_black(self) -> Self
fn on_bright_black(self) -> Self
Set the background color to bright black.
source§fn underline_bright_black(self) -> Self
fn underline_bright_black(self) -> Self
Set the underline attribute, and set the underline color to bright black.
source§fn bright_red(self) -> Self
fn bright_red(self) -> Self
Set the foreground color to bright red.
source§fn on_bright_red(self) -> Self
fn on_bright_red(self) -> Self
Set the background color to bright red.
source§fn underline_bright_red(self) -> Self
fn underline_bright_red(self) -> Self
Set the underline attribute, and set the underline color to bright red.
source§fn bright_green(self) -> Self
fn bright_green(self) -> Self
Set the foreground color to bright green.
source§fn on_bright_green(self) -> Self
fn on_bright_green(self) -> Self
Set the background color to bright green.
source§fn underline_bright_green(self) -> Self
fn underline_bright_green(self) -> Self
Set the underline attribute, and set the underline color to bright green.
source§fn bright_yellow(self) -> Self
fn bright_yellow(self) -> Self
Set the foreground color to bright yellow.
source§fn on_bright_yellow(self) -> Self
fn on_bright_yellow(self) -> Self
Set the background color to bright yellow.
source§fn underline_bright_yellow(self) -> Self
fn underline_bright_yellow(self) -> Self
Set the underline attribute, and set the underline color to bright yellow.
source§fn bright_blue(self) -> Self
fn bright_blue(self) -> Self
Set the foreground color to bright blue.
source§fn on_bright_blue(self) -> Self
fn on_bright_blue(self) -> Self
Set the background color to bright blue.
source§fn underline_bright_blue(self) -> Self
fn underline_bright_blue(self) -> Self
Set the underline attribute, and set the underline color to bright blue.
source§fn bright_magenta(self) -> Self
fn bright_magenta(self) -> Self
Set the foreground color to bright magenta.
source§fn on_bright_magenta(self) -> Self
fn on_bright_magenta(self) -> Self
Set the background color to bright magenta.
source§fn underline_bright_magenta(self) -> Self
fn underline_bright_magenta(self) -> Self
Set the underline attribute, and set the underline color to bright magenta.
source§fn bright_cyan(self) -> Self
fn bright_cyan(self) -> Self
Set the foreground color to bright cyan.
source§fn on_bright_cyan(self) -> Self
fn on_bright_cyan(self) -> Self
Set the background color to bright cyan.
source§fn underline_bright_cyan(self) -> Self
fn underline_bright_cyan(self) -> Self
Set the underline attribute, and set the underline color to bright cyan.
source§fn bright_white(self) -> Self
fn bright_white(self) -> Self
Set the foreground color to bright white.
source§fn on_bright_white(self) -> Self
fn on_bright_white(self) -> Self
Set the background color to bright white.
source§fn underline_bright_white(self) -> Self
fn underline_bright_white(self) -> Self
Set the underline attribute, and set the underline color to bright white.
impl 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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)