StyledString

Struct StyledString 

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

A styled string that preserves styling context like colored’s ColoredString

This type automatically handles reset sequences to ensure that when styled strings are embedded within other styled strings, the outer styling context is properly preserved.

Implementations§

Source§

impl StyledString

Source

pub const fn new(content: String, style: Style) -> Self

Create a new StyledString with the given content and style

Source

pub fn to_styled(&self) -> String

Convert to final styled string with proper ANSI codes

Source

pub fn bold(self) -> Self

Chain bold styling

Source

pub fn italic(self) -> Self

Chain italic styling

Source

pub fn dim(self) -> Self

Chain dim styling

Source

pub fn underline(self) -> Self

Chain underline styling

Trait Implementations§

Source§

impl AsRef<str> for StyledString

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for StyledString

Source§

fn clone(&self) -> StyledString

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 StyledString

Source§

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

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

impl Display for StyledString

Source§

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

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

impl From<StyledString> for String

Source§

fn from(styled: StyledString) -> Self

Converts to this type from the input type.
Source§

impl StyledPrint for StyledString

Source§

fn print(self)

Print the styled string to stdout
Source§

fn println(self)

Print the styled string to stdout with a newline
Source§

fn vprintln(self, verbosity: Verbosity)

Print the styled string with verbosity gating
Source§

impl Styler for StyledString

Source§

fn to_style(&self) -> Style

Convert this item to a Style for use with styling macros
Source§

fn prtln(&self, args: Arguments<'_>)

Print a styled line using this style Read more
Source§

fn vprtln(&self, verbosity: Verbosity, args: Arguments<'_>)

Print a styled line with verbosity gating using this style Read more
Source§

fn paint<D>(&self, val: D) -> String
where D: Display,

Apply this style to text and return the styled string Read more
Source§

fn bold(self) -> Style
where Self: Sized,

Return a Style with bold formatting enabled Read more
Source§

fn italic(self) -> Style
where Self: Sized,

Return a Style with italic formatting enabled Read more
Source§

fn dim(self) -> Style
where Self: Sized,

Return a Style with dim formatting enabled Read more
Source§

fn underline(self) -> Style
where Self: Sized,

Return a Style with underline formatting enabled Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AnsiStyleExt for T
where T: Display,

Source§

fn style(&self) -> Styled<String>

Creates a Styled wrapper around the string representation of this value. Read more
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> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToLine for T
where T: Display,

Source§

fn to_line(&self) -> Line<'_>

Converts the value to a Line.
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToSpan for T
where T: Display,

Source§

fn to_span(&self) -> Span<'_>

Converts the value to a Span.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToText for T
where T: Display,

Source§

fn to_text(&self) -> Text<'_>

Converts the value to a Text.
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.