Styled

Struct Styled 

Source
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: Style

Implementations§

Source§

impl<T, Link> Styled<T, Link>

Source

pub const fn fg(self, color: Color) -> Self

Set the foreground color.

Examples found in repository?
examples/pallete.rs (line 5)
3fn main() {
4    for i in 0..=255 {
5        println!("{}", i.styled().fg(i.into()));
6    }
7}
Source

pub const fn bg(self, color: Color) -> Self

Set the background color.

Source

pub const fn underline_colored(self, color: Color) -> Self

Set the underline attribute and color.

Examples found in repository?
examples/demo.rs (line 25)
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

pub const fn attributes(self, attrs: Attributes) -> Self

Set the attributes.

This will not unset any existing attributes.

Source

pub const fn bold(self) -> Self

Set the bold attribute.

Examples found in repository?
examples/demo.rs (line 4)
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

pub const fn dim(self) -> Self

Set the dim attribute.

Source

pub const fn italic(self) -> Self

Set the italic attribute.

Source

pub const fn underlined(self) -> Self

Set the underline attribute.

Set the blink attribute.

Source

pub const fn inverted(self) -> Self

Set the inverted attribute.

Examples found in repository?
examples/demo.rs (line 11)
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

pub const fn hidden(self) -> Self

Set the hidden attribute.

Source

pub const fn strikethrough(self) -> Self

Set the strikethrough attribute.

Examples found in repository?
examples/demo.rs (line 18)
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

pub const fn black(self) -> Self

Set the foreground color to black.

Source

pub const fn on_black(self) -> Self

Set the background color to black.

Source

pub const fn underline_black(self) -> Self

Set the underline attribute, and set the underline color to black.

Source

pub const fn red(self) -> Self

Set the foreground color to red.

Examples found in repository?
examples/demo.rs (line 4)
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

pub const fn on_red(self) -> Self

Set the background color to red.

Source

pub const fn underline_red(self) -> Self

Set the underline attribute, and set the underline color to red.

Source

pub const fn green(self) -> Self

Set the foreground color to green.

Examples found in repository?
examples/demo.rs (line 22)
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

pub const fn on_green(self) -> Self

Set the background color to green.

Source

pub const fn underline_green(self) -> Self

Set the underline attribute, and set the underline color to green.

Source

pub const fn yellow(self) -> Self

Set the foreground color to yellow.

Source

pub const fn on_yellow(self) -> Self

Set the background color to yellow.

Source

pub const fn underline_yellow(self) -> Self

Set the underline attribute, and set the underline color to yellow.

Source

pub const fn blue(self) -> Self

Set the foreground color to blue.

Examples found in repository?
examples/demo.rs (line 8)
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

pub const fn on_blue(self) -> Self

Set the background color to blue.

Examples found in repository?
examples/demo.rs (line 4)
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

pub const fn underline_blue(self) -> Self

Set the underline attribute, and set the underline color to blue.

Source

pub const fn magenta(self) -> Self

Set the foreground color to magenta.

Source

pub const fn on_magenta(self) -> Self

Set the background color to magenta.

Source

pub const fn underline_magenta(self) -> Self

Set the underline attribute, and set the underline color to magenta.

Source

pub const fn cyan(self) -> Self

Set the foreground color to cyan.

Examples found in repository?
examples/demo.rs (line 10)
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

pub const fn on_cyan(self) -> Self

Set the background color to cyan.

Source

pub const fn underline_cyan(self) -> Self

Set the underline attribute, and set the underline color to cyan.

Source

pub const fn white(self) -> Self

Set the foreground color to white.

Source

pub const fn on_white(self) -> Self

Set the background color to white.

Source

pub const fn underline_white(self) -> Self

Set the underline attribute, and set the underline color to white.

Source

pub const fn bright_black(self) -> Self

Set the foreground color to bright black.

Source

pub const fn on_bright_black(self) -> Self

Set the background color to bright black.

Source

pub const fn underline_bright_black(self) -> Self

Set the underline attribute, and set the underline color to bright black.

Source

pub const fn bright_red(self) -> Self

Set the foreground color to bright red.

Source

pub const fn on_bright_red(self) -> Self

Set the background color to bright red.

Source

pub const fn underline_bright_red(self) -> Self

Set the underline attribute, and set the underline color to bright red.

Source

pub const fn bright_green(self) -> Self

Set the foreground color to bright green.

Source

pub const fn on_bright_green(self) -> Self

Set the background color to bright green.

Source

pub const fn underline_bright_green(self) -> Self

Set the underline attribute, and set the underline color to bright green.

Source

pub const fn bright_yellow(self) -> Self

Set the foreground color to bright yellow.

Source

pub const fn on_bright_yellow(self) -> Self

Set the background color to bright yellow.

Source

pub const fn underline_bright_yellow(self) -> Self

Set the underline attribute, and set the underline color to bright yellow.

Source

pub const fn bright_blue(self) -> Self

Set the foreground color to bright blue.

Source

pub const fn on_bright_blue(self) -> Self

Set the background color to bright blue.

Source

pub const fn underline_bright_blue(self) -> Self

Set the underline attribute, and set the underline color to bright blue.

Source

pub const fn bright_magenta(self) -> Self

Set the foreground color to bright magenta.

Source

pub const fn on_bright_magenta(self) -> Self

Set the background color to bright magenta.

Source

pub const fn underline_bright_magenta(self) -> Self

Set the underline attribute, and set the underline color to bright magenta.

Source

pub const fn bright_cyan(self) -> Self

Set the foreground color to bright cyan.

Source

pub const fn on_bright_cyan(self) -> Self

Set the background color to bright cyan.

Source

pub const fn underline_bright_cyan(self) -> Self

Set the underline attribute, and set the underline color to bright cyan.

Source

pub const fn bright_white(self) -> Self

Set the foreground color to bright white.

Source

pub const fn on_bright_white(self) -> Self

Set the background color to bright white.

Source

pub const fn underline_bright_white(self) -> Self

Set the underline attribute, and set the underline color to bright white.

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?
examples/style.rs (line 12)
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
Hide additional examples
examples/demo.rs (line 22)
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>

Source

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.

Source§

impl<T, Uri> Styled<T, WithLink<Uri>>

Access the link associated with this styled value.

§Examples
use stylic::Styleable;

let my_linked_value = "Example link"
    .styled()
    .link("https://example.com");

println!("Link: {}", my_linked_value.get_link());

Trait Implementations§

Source§

impl<T: Binary> Binary for Styled<T, WithoutLink>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Binary, Uri: Display> Binary for Styled<T, WithLink<Uri>>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Clone, Link: Clone> Clone for Styled<T, Link>

Source§

fn clone(&self) -> Styled<T, Link>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Default, Link: Default> Default for Styled<T, Link>

Source§

fn default() -> Styled<T, Link>

Returns the “default value” for a type. Read more
Source§

impl<T: Display> Display for Styled<T, WithoutLink>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Display, Uri: Display> Display for Styled<T, WithLink<Uri>>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Hash, Link: Hash> Hash for Styled<T, Link>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: LowerExp> LowerExp for Styled<T, WithoutLink>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: LowerExp, Uri: Display> LowerExp for Styled<T, WithLink<Uri>>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: LowerHex> LowerHex for Styled<T, WithoutLink>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: LowerHex, Uri: Display> LowerHex for Styled<T, WithLink<Uri>>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Octal> Octal for Styled<T, WithoutLink>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Octal, Uri: Display> Octal for Styled<T, WithLink<Uri>>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Ord, Link: Ord> Ord for Styled<T, Link>

Source§

fn cmp(&self, other: &Styled<T, Link>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq, Link: PartialEq> PartialEq for Styled<T, Link>

Source§

fn eq(&self, other: &Styled<T, Link>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd, Link: PartialOrd> PartialOrd for Styled<T, Link>

Source§

fn partial_cmp(&self, other: &Styled<T, Link>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Pointer> Pointer for Styled<T, WithoutLink>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Pointer, Uri: Display> Pointer for Styled<T, WithLink<Uri>>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: UpperExp> UpperExp for Styled<T, WithoutLink>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: UpperExp, Uri: Display> UpperExp for Styled<T, WithLink<Uri>>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: UpperHex> UpperHex for Styled<T, WithoutLink>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: UpperHex, Uri: Display> UpperHex for Styled<T, WithLink<Uri>>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Copy, Link: Copy> Copy for Styled<T, Link>

Source§

impl<T: Eq, Link: Eq> Eq for Styled<T, Link>

Source§

impl<T, Link> StructuralPartialEq for Styled<T, Link>

Auto Trait Implementations§

§

impl<T, Link> Freeze for Styled<T, Link>
where T: Freeze, Link: Freeze,

§

impl<T, Link> RefUnwindSafe for Styled<T, Link>
where T: RefUnwindSafe, Link: RefUnwindSafe,

§

impl<T, Link> Send for Styled<T, Link>
where T: Send, Link: Send,

§

impl<T, Link> Sync for Styled<T, Link>
where T: Sync, Link: Sync,

§

impl<T, Link> Unpin for Styled<T, Link>
where T: Unpin, Link: Unpin,

§

impl<T, Link> UnwindSafe for Styled<T, Link>
where T: UnwindSafe, Link: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Styleable for T

Source§

fn styled(self) -> Styled<Self>

Create a new Styled value from this value. Read more
Source§

fn styled_with(self, style: Style) -> Styled<Self>

Create a new Styled value from this value, with an existing style. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.