Style

Struct Style 

Source
pub struct Style { /* private fields */ }
Expand description

A structure representing text styling with effects and colors.

Implementations§

Source§

impl Style

Source

pub const fn new() -> Self

Creates a new, empty Style value.

Source

pub fn set_effect(self, effect: impl Into<Effect>, value: bool) -> Self

Sets the given effect to the specified value.

Source

pub fn get_effect(&self, effect: impl Into<Effect>) -> bool

Gets whether the given effect is set.

Source

pub fn get_effects(&self) -> GetEffects

Returns an iterator over the effects that are currently set.

Source

pub fn set_underline_effect( self, underline_effect: Option<UnderlineEffect>, ) -> Self

Sets the underline effect.

Source

pub fn get_underline_effect(&self) -> Option<UnderlineEffect>

Gets the underline effect.

Source

pub fn set_color( self, target: ColorTarget, color: Option<impl Into<Color>>, ) -> Self

Sets the color for the given color target.

To clear the color for some color target, the color type must be specified in the None value. To help with that, the Color::none() method can be used:

style.set_color(ColorTarget::Foreground, None::<Color>);
// or
style.set_color(ColorTarget::Foreground, Color::none());
Source

pub fn get_color(&self, target: ColorTarget) -> Option<Color>

Gets the color for the given color target.

Source

pub fn set<A: StylingAttribute<Self>>(self, attr: A, value: A::Value) -> Self

Sets the given attribute to the specified value.

Source

pub fn get<A: StylingAttribute<Self>>(&self, attr: A) -> A::Value

Gets the value of the given attribute.

Source

pub fn remove<A: StylingAttribute<Self>>(self, attr: A) -> Self

Clears the given attribute.

Source§

impl Style

Source

pub fn bold(self) -> Style

Sets the bold effect.

Source

pub fn faint(self) -> Style

Sets the faint effect.

Source

pub fn italic(self) -> Style

Sets the italic effect.

Source

pub fn underline(self) -> Style

Source

pub fn solid_underline(self) -> Style

Sets the solid underline effect.

Source

pub fn curly_underline(self) -> Style

Sets the curly underline effect.

Source

pub fn dotted_underline(self) -> Style

Sets the dotted underline effect.

Source

pub fn dashed_underline(self) -> Style

Sets the dashed underline effect.

Sets the blink effect.

Source

pub fn reverse(self) -> Style

Sets the reverse effect.

Source

pub fn conceal(self) -> Style

Sets the conceal effect.

Source

pub fn strikethrough(self) -> Style

Sets the strikethrough effect.

Source

pub fn double_underline(self) -> Style

Sets the double underline effect.

Source

pub fn overline(self) -> Style

Sets the overline effect.

Source

pub fn effect(self, effect: impl Into<Effect>) -> Style

Sets the given effect.

Source

pub fn underline_effect(self, underline_effect: UnderlineEffect) -> Style

Sets the underline effect.

Source

pub fn fg(self, color: impl Into<Color>) -> Style

Sets the foreground color.

Source

pub fn bg(self, color: impl Into<Color>) -> Style

Sets the background color.

Source

pub fn underline_color(self, color: impl Into<Color>) -> Style

Sets the underline color.

Source

pub fn color(self, targeted_color: impl Into<TargetedColor>) -> Style

Sets the given color in a target.

Source

pub fn add(self, element: impl StylingElement<Style>) -> Style

Adds the given element to the style.

Source

pub fn applied_to<C: Display>(self, content: C) -> Styled<C>

Applies the styling to the given content, returning a Styled<C> instance.

Source§

impl Style

Source

pub fn to_style(self) -> Style

Convert this type into a Style.

Trait Implementations§

Source§

impl Clone for Style

Source§

fn clone(&self) -> Style

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 Debug for Style

Source§

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

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

impl Default for Style

Source§

fn default() -> Style

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

impl Display for Style

Source§

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

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

impl From<BasicColor> for Style

Source§

fn from(value: BasicColor) -> Self

Converts to this type from the input type.
Source§

impl From<Color> for Style

Source§

fn from(value: Color) -> Self

Converts to this type from the input type.
Source§

impl From<Effect> for Style

Source§

fn from(value: Effect) -> Self

Converts to this type from the input type.
Source§

impl From<IndexedColor> for Style

Source§

fn from(value: IndexedColor) -> Self

Converts to this type from the input type.
Source§

impl From<RGBColor> for Style

Source§

fn from(value: RGBColor) -> Self

Converts to this type from the input type.
Source§

impl From<Reset> for Style

Source§

fn from(value: Reset) -> Self

Converts to this type from the input type.
Source§

impl From<SimpleColor> for Style

Source§

fn from(value: SimpleColor) -> Self

Converts to this type from the input type.
Source§

impl From<TargetedColor> for Style

Source§

fn from(value: TargetedColor) -> Self

Converts to this type from the input type.
Source§

impl From<UnderlineEffect> for Style

Source§

fn from(value: UnderlineEffect) -> Self

Converts to this type from the input type.
Source§

impl Hash for Style

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 PartialEq<Reset> for Style

Source§

fn eq(&self, other: &Reset) -> 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 PartialEq<Style> for Reset

Source§

fn eq(&self, other: &Style) -> 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 PartialEq for Style

Source§

fn eq(&self, other: &Style) -> 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 StylingAttribute<Style> for ColorTarget

Source§

type Value = Option<Color>

The type of value associated with this attribute.
Source§

fn set_in(self, composed_styling: Style, value: Self::Value) -> Style

Sets this attribute in the given parameter, returning it updated.
Source§

fn get_from(self, composed_styling: &Style) -> Self::Value

Gets the value of this attribute from the given parameter.
Source§

impl StylingAttribute<Style> for Effect

Source§

type Value = bool

The type of value associated with this attribute.
Source§

fn set_in(self, composed_styling: Style, value: Self::Value) -> Style

Sets this attribute in the given parameter, returning it updated.
Source§

fn get_from(self, composed_styling: &Style) -> Self::Value

Gets the value of this attribute from the given parameter.
Source§

impl StylingAttribute<Style> for UnderlineEffect

Source§

type Value = bool

The type of value associated with this attribute.
Source§

fn set_in(self, composed_styling: Style, value: Self::Value) -> Style

Sets this attribute in the given parameter, returning it updated.
Source§

fn get_from(self, composed_styling: &Style) -> Self::Value

Gets the value of this attribute from the given parameter.
Source§

impl StylingAttribute<Style> for UnderlineStyle

Source§

type Value = Option<UnderlineEffect>

The type of value associated with this attribute.
Source§

fn set_in(self, composed_styling: Style, value: Self::Value) -> Style

Sets this attribute in the given parameter, returning it updated.
Source§

fn get_from(self, composed_styling: &Style) -> Self::Value

Gets the value of this attribute from the given parameter.
Source§

impl StylingElement<Style> for BasicColor

Source§

fn add_to(self, composed_styling: Style) -> Style

Adds this element to the given parameter, returning it updated.
Source§

impl StylingElement<Style> for Color

Source§

fn add_to(self, composed_styling: Style) -> Style

Adds this element to the given parameter, returning it updated.
Source§

impl StylingElement<Style> for Effect

Source§

fn add_to(self, composed_styling: Style) -> Style

Adds this element to the given parameter, returning it updated.
Source§

impl StylingElement<Style> for IndexedColor

Source§

fn add_to(self, composed_styling: Style) -> Style

Adds this element to the given parameter, returning it updated.
Source§

impl StylingElement<Style> for RGBColor

Source§

fn add_to(self, composed_styling: Style) -> Style

Adds this element to the given parameter, returning it updated.
Source§

impl StylingElement<Style> for SimpleColor

Source§

fn add_to(self, composed_styling: Style) -> Style

Adds this element to the given parameter, returning it updated.
Source§

impl StylingElement<Style> for TargetedColor

Source§

fn add_to(self, composed_styling: Style) -> Style

Adds this element to the given parameter, returning it updated.
Source§

impl StylingElement<Style> for UnderlineEffect

Source§

fn add_to(self, composed_styling: Style) -> Style

Adds this element to the given parameter, returning it updated.
Source§

impl Copy for Style

Source§

impl Eq for Style

Source§

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> 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, 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.