pub struct Styled<T, Link = WithoutLink> {
pub value: T,
pub style: Style,
/* private fields */
}Expand description
A styled value.
Has builder methods for building a style. See crate level docs for examples of these.
Supports hyperlinks via the link method.
This type can be created using Styleable::styled
or Styleable::styled_with.
Fields§
§value: T§style: StyleImplementations§
Source§impl<T, Link> Styled<T, Link>
impl<T, Link> Styled<T, Link>
Sourcepub const fn underline_colored(self, color: Color) -> Self
pub const fn underline_colored(self, color: Color) -> Self
Set the underline attribute and color.
Examples found in repository?
3fn main() {
4 let hello = "Hello".styled().bold().red().on_blue();
5
6 println!("{}", lazy_format!("{:b}", 12));
7
8 let world = lazy_format!("Wor{}ld", lazy_format!("he{}he", "haha").styled().blue())
9 .styled()
10 .cyan()
11 .inverted();
12
13 println!("{hello}, {world}!");
14
15 println!("{:?}", world.style);
16 println!("{:?}", world.to_string());
17
18 println!("{}", "strikethrough".styled().strikethrough());
19
20 println!(
21 "{}",
22 "Google".styled().bold().green().link("https://google.com")
23 );
24
25 println!("{}", "Hello".styled().underline_colored(48.into()));
26}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 hello = "Hello".styled().bold().red().on_blue();
5
6 println!("{}", lazy_format!("{:b}", 12));
7
8 let world = lazy_format!("Wor{}ld", lazy_format!("he{}he", "haha").styled().blue())
9 .styled()
10 .cyan()
11 .inverted();
12
13 println!("{hello}, {world}!");
14
15 println!("{:?}", world.style);
16 println!("{:?}", world.to_string());
17
18 println!("{}", "strikethrough".styled().strikethrough());
19
20 println!(
21 "{}",
22 "Google".styled().bold().green().link("https://google.com")
23 );
24
25 println!("{}", "Hello".styled().underline_colored(48.into()));
26}Sourcepub const fn underlined(self) -> Self
pub const fn underlined(self) -> Self
Set the underline attribute.
Sourcepub const fn inverted(self) -> Self
pub const fn inverted(self) -> Self
Set the inverted attribute.
Examples found in repository?
3fn main() {
4 let hello = "Hello".styled().bold().red().on_blue();
5
6 println!("{}", lazy_format!("{:b}", 12));
7
8 let world = lazy_format!("Wor{}ld", lazy_format!("he{}he", "haha").styled().blue())
9 .styled()
10 .cyan()
11 .inverted();
12
13 println!("{hello}, {world}!");
14
15 println!("{:?}", world.style);
16 println!("{:?}", world.to_string());
17
18 println!("{}", "strikethrough".styled().strikethrough());
19
20 println!(
21 "{}",
22 "Google".styled().bold().green().link("https://google.com")
23 );
24
25 println!("{}", "Hello".styled().underline_colored(48.into()));
26}Set the hidden attribute.
Sourcepub const fn strikethrough(self) -> Self
pub const fn strikethrough(self) -> Self
Set the strikethrough attribute.
Examples found in repository?
3fn main() {
4 let hello = "Hello".styled().bold().red().on_blue();
5
6 println!("{}", lazy_format!("{:b}", 12));
7
8 let world = lazy_format!("Wor{}ld", lazy_format!("he{}he", "haha").styled().blue())
9 .styled()
10 .cyan()
11 .inverted();
12
13 println!("{hello}, {world}!");
14
15 println!("{:?}", world.style);
16 println!("{:?}", world.to_string());
17
18 println!("{}", "strikethrough".styled().strikethrough());
19
20 println!(
21 "{}",
22 "Google".styled().bold().green().link("https://google.com")
23 );
24
25 println!("{}", "Hello".styled().underline_colored(48.into()));
26}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 red(self) -> Self
pub const fn red(self) -> Self
Set the foreground color to red.
Examples found in repository?
3fn main() {
4 let hello = "Hello".styled().bold().red().on_blue();
5
6 println!("{}", lazy_format!("{:b}", 12));
7
8 let world = lazy_format!("Wor{}ld", lazy_format!("he{}he", "haha").styled().blue())
9 .styled()
10 .cyan()
11 .inverted();
12
13 println!("{hello}, {world}!");
14
15 println!("{:?}", world.style);
16 println!("{:?}", world.to_string());
17
18 println!("{}", "strikethrough".styled().strikethrough());
19
20 println!(
21 "{}",
22 "Google".styled().bold().green().link("https://google.com")
23 );
24
25 println!("{}", "Hello".styled().underline_colored(48.into()));
26}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 green(self) -> Self
pub const fn green(self) -> Self
Set the foreground color to green.
Examples found in repository?
3fn main() {
4 let hello = "Hello".styled().bold().red().on_blue();
5
6 println!("{}", lazy_format!("{:b}", 12));
7
8 let world = lazy_format!("Wor{}ld", lazy_format!("he{}he", "haha").styled().blue())
9 .styled()
10 .cyan()
11 .inverted();
12
13 println!("{hello}, {world}!");
14
15 println!("{:?}", world.style);
16 println!("{:?}", world.to_string());
17
18 println!("{}", "strikethrough".styled().strikethrough());
19
20 println!(
21 "{}",
22 "Google".styled().bold().green().link("https://google.com")
23 );
24
25 println!("{}", "Hello".styled().underline_colored(48.into()));
26}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 hello = "Hello".styled().bold().red().on_blue();
5
6 println!("{}", lazy_format!("{:b}", 12));
7
8 let world = lazy_format!("Wor{}ld", lazy_format!("he{}he", "haha").styled().blue())
9 .styled()
10 .cyan()
11 .inverted();
12
13 println!("{hello}, {world}!");
14
15 println!("{:?}", world.style);
16 println!("{:?}", world.to_string());
17
18 println!("{}", "strikethrough".styled().strikethrough());
19
20 println!(
21 "{}",
22 "Google".styled().bold().green().link("https://google.com")
23 );
24
25 println!("{}", "Hello".styled().underline_colored(48.into()));
26}Sourcepub const fn on_blue(self) -> Self
pub const fn on_blue(self) -> Self
Set the background color to blue.
Examples found in repository?
3fn main() {
4 let hello = "Hello".styled().bold().red().on_blue();
5
6 println!("{}", lazy_format!("{:b}", 12));
7
8 let world = lazy_format!("Wor{}ld", lazy_format!("he{}he", "haha").styled().blue())
9 .styled()
10 .cyan()
11 .inverted();
12
13 println!("{hello}, {world}!");
14
15 println!("{:?}", world.style);
16 println!("{:?}", world.to_string());
17
18 println!("{}", "strikethrough".styled().strikethrough());
19
20 println!(
21 "{}",
22 "Google".styled().bold().green().link("https://google.com")
23 );
24
25 println!("{}", "Hello".styled().underline_colored(48.into()));
26}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 cyan(self) -> Self
pub const fn cyan(self) -> Self
Set the foreground color to cyan.
Examples found in repository?
3fn main() {
4 let hello = "Hello".styled().bold().red().on_blue();
5
6 println!("{}", lazy_format!("{:b}", 12));
7
8 let world = lazy_format!("Wor{}ld", lazy_format!("he{}he", "haha").styled().blue())
9 .styled()
10 .cyan()
11 .inverted();
12
13 println!("{hello}, {world}!");
14
15 println!("{:?}", world.style);
16 println!("{:?}", world.to_string());
17
18 println!("{}", "strikethrough".styled().strikethrough());
19
20 println!(
21 "{}",
22 "Google".styled().bold().green().link("https://google.com")
23 );
24
25 println!("{}", "Hello".styled().underline_colored(48.into()));
26}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.
Sourcepub fn link<Uri>(self, uri: Uri) -> Styled<T, WithLink<Uri>>where
Uri: Display,
pub fn link<Uri>(self, uri: Uri) -> Styled<T, WithLink<Uri>>where
Uri: Display,
Set a link associated with this value.
This will create a clickable link in terminal emulators that support it.
Note that this method produces a different type to a styled value without
a link - Styled<T, WithLink<Uri> as opposed to the default
Styled<T, Link = WithoutLink>.
§Examples
use stylic::Styleable;
println!("{}", "Click me!".styled().link("https://example.com"));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}More examples
3fn main() {
4 let hello = "Hello".styled().bold().red().on_blue();
5
6 println!("{}", lazy_format!("{:b}", 12));
7
8 let world = lazy_format!("Wor{}ld", lazy_format!("he{}he", "haha").styled().blue())
9 .styled()
10 .cyan()
11 .inverted();
12
13 println!("{hello}, {world}!");
14
15 println!("{:?}", world.style);
16 println!("{:?}", world.to_string());
17
18 println!("{}", "strikethrough".styled().strikethrough());
19
20 println!(
21 "{}",
22 "Google".styled().bold().green().link("https://google.com")
23 );
24
25 println!("{}", "Hello".styled().underline_colored(48.into()));
26}Source§impl<T> Styled<T, WithoutLink>
impl<T> Styled<T, WithoutLink>
Sourcepub const fn new(value: T, style: Style) -> Self
pub const fn new(value: T, style: Style) -> Self
Create a new styled value.
This is not the recommended way of doing this (see
Styleable::styled for a more
convenient way), but could be useful in a const environment.