pub struct Style {
pub fg: Color,
pub bg: Color,
pub underline: Color,
pub attributes: Attributes,
}Expand description
A style that can be applied to a value.
Has builder methods for building a style. See crate level docs for examples of these.
Fields§
§fg: ColorForeground color.
bg: ColorBackground color.
underline: ColorUnderline 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?
3fn main() {
4 let my_style = Style::new().bold().blue();
5
6 println!("{}!", "Hello".styled_with(my_style));
7
8 println!(
9 "{}",
10 "Rust Language"
11 .styled_with(my_style)
12 .link("https://rust-lang.org")
13 );
14}Sourcepub const fn underline_colored(self, color: Color) -> Self
pub const fn underline_colored(self, color: Color) -> Self
Set the underline attribute and color.
Sourcepub const fn attributes(self, attrs: Attributes) -> Self
pub const fn attributes(self, attrs: Attributes) -> Self
Set the attributes.
This will not unset any existing attributes.
Sourcepub const fn bold(self) -> Self
pub const fn bold(self) -> Self
Set the bold attribute.
Examples found in repository?
3fn main() {
4 let my_style = Style::new().bold().blue();
5
6 println!("{}!", "Hello".styled_with(my_style));
7
8 println!(
9 "{}",
10 "Rust Language"
11 .styled_with(my_style)
12 .link("https://rust-lang.org")
13 );
14}Sourcepub const fn underlined(self) -> Self
pub const fn underlined(self) -> Self
Set the underline attribute.
Set the hidden attribute.
Sourcepub const fn strikethrough(self) -> Self
pub const fn strikethrough(self) -> Self
Set the strikethrough attribute.
Sourcepub const fn underline_black(self) -> Self
pub const fn underline_black(self) -> Self
Set the underline attribute, and set the underline color to black.
Sourcepub const fn underline_red(self) -> Self
pub const fn underline_red(self) -> Self
Set the underline attribute, and set the underline color to red.
Sourcepub const fn underline_green(self) -> Self
pub const fn underline_green(self) -> Self
Set the underline attribute, and set the underline color to green.
Sourcepub const fn underline_yellow(self) -> Self
pub const fn underline_yellow(self) -> Self
Set the underline attribute, and set the underline color to yellow.
Sourcepub const fn blue(self) -> Self
pub const fn blue(self) -> Self
Set the foreground color to blue.
Examples found in repository?
3fn main() {
4 let my_style = Style::new().bold().blue();
5
6 println!("{}!", "Hello".styled_with(my_style));
7
8 println!(
9 "{}",
10 "Rust Language"
11 .styled_with(my_style)
12 .link("https://rust-lang.org")
13 );
14}Sourcepub const fn underline_blue(self) -> Self
pub const fn underline_blue(self) -> Self
Set the underline attribute, and set the underline color to blue.
Sourcepub const fn on_magenta(self) -> Self
pub const fn on_magenta(self) -> Self
Set the background color to magenta.
Sourcepub const fn underline_magenta(self) -> Self
pub const fn underline_magenta(self) -> Self
Set the underline attribute, and set the underline color to magenta.
Sourcepub const fn underline_cyan(self) -> Self
pub const fn underline_cyan(self) -> Self
Set the underline attribute, and set the underline color to cyan.
Sourcepub const fn underline_white(self) -> Self
pub const fn underline_white(self) -> Self
Set the underline attribute, and set the underline color to white.
Sourcepub const fn bright_black(self) -> Self
pub const fn bright_black(self) -> Self
Set the foreground color to bright black.
Sourcepub const fn on_bright_black(self) -> Self
pub const fn on_bright_black(self) -> Self
Set the background color to bright black.
Sourcepub const fn underline_bright_black(self) -> Self
pub const fn underline_bright_black(self) -> Self
Set the underline attribute, and set the underline color to bright black.
Sourcepub const fn bright_red(self) -> Self
pub const fn bright_red(self) -> Self
Set the foreground color to bright red.
Sourcepub const fn on_bright_red(self) -> Self
pub const fn on_bright_red(self) -> Self
Set the background color to bright red.
Sourcepub const fn underline_bright_red(self) -> Self
pub const fn underline_bright_red(self) -> Self
Set the underline attribute, and set the underline color to bright red.
Sourcepub const fn bright_green(self) -> Self
pub const fn bright_green(self) -> Self
Set the foreground color to bright green.
Sourcepub const fn on_bright_green(self) -> Self
pub const fn on_bright_green(self) -> Self
Set the background color to bright green.
Sourcepub const fn underline_bright_green(self) -> Self
pub const fn underline_bright_green(self) -> Self
Set the underline attribute, and set the underline color to bright green.
Sourcepub const fn bright_yellow(self) -> Self
pub const fn bright_yellow(self) -> Self
Set the foreground color to bright yellow.
Sourcepub const fn on_bright_yellow(self) -> Self
pub const fn on_bright_yellow(self) -> Self
Set the background color to bright yellow.
Sourcepub const fn underline_bright_yellow(self) -> Self
pub const fn underline_bright_yellow(self) -> Self
Set the underline attribute, and set the underline color to bright yellow.
Sourcepub const fn bright_blue(self) -> Self
pub const fn bright_blue(self) -> Self
Set the foreground color to bright blue.
Sourcepub const fn on_bright_blue(self) -> Self
pub const fn on_bright_blue(self) -> Self
Set the background color to bright blue.
Sourcepub const fn underline_bright_blue(self) -> Self
pub const fn underline_bright_blue(self) -> Self
Set the underline attribute, and set the underline color to bright blue.
Sourcepub const fn bright_magenta(self) -> Self
pub const fn bright_magenta(self) -> Self
Set the foreground color to bright magenta.
Sourcepub const fn on_bright_magenta(self) -> Self
pub const fn on_bright_magenta(self) -> Self
Set the background color to bright magenta.
Sourcepub const fn underline_bright_magenta(self) -> Self
pub const fn underline_bright_magenta(self) -> Self
Set the underline attribute, and set the underline color to bright magenta.
Sourcepub const fn bright_cyan(self) -> Self
pub const fn bright_cyan(self) -> Self
Set the foreground color to bright cyan.
Sourcepub const fn on_bright_cyan(self) -> Self
pub const fn on_bright_cyan(self) -> Self
Set the background color to bright cyan.
Sourcepub const fn underline_bright_cyan(self) -> Self
pub const fn underline_bright_cyan(self) -> Self
Set the underline attribute, and set the underline color to bright cyan.
Sourcepub const fn bright_white(self) -> Self
pub const fn bright_white(self) -> Self
Set the foreground color to bright white.
Sourcepub const fn on_bright_white(self) -> Self
pub const fn on_bright_white(self) -> Self
Set the background color to bright white.
Sourcepub const fn underline_bright_white(self) -> Self
pub const fn underline_bright_white(self) -> Self
Set the underline attribute, and set the underline color to bright white.