pub struct StyledStrings { /* private fields */ }
Expand description

StyledStrings is vector of StyledString and almost the same as Vec<String>. It is possible to change the color and attribute of each String. That’s why, if you don’t change any color or attribute, you should use ‘StyledString’ not StyledStrings

Example

let mut texts = StyledStrings::default();
texts.push_str("Default color is gray, ");
texts.push_str_with_color("and it is possible to color text.\n", Color::Red);
texts.push_str("Basically, this `StyledStrings` is one sentence, ");
texts.push_str_with_color("so if you want to multiline sentences, you need to add `\n`.", Color::Magenta);
println!("{}", texts); // Pushed colored text are displayed

Basically,initialize by default with mutable. Then, &str(s) are pushed to the Vec, specifying colors or attributes.

Implementations§

It is possible push &str type with gray color to Vector.

Example
let mut texts = StyledStrings::default();
texts.push_str("sample text");
texts.push_str("\n");
texts.push_str("new text here");
println!("{}", texts);
 /*
    sample text
    new text here
 */

It is possible to push &str type with specify color to Vector.

Example
let mut texts = StyledStrings::default();
texts.push_str_with_color("Cyan color text", Color::Cyan);
texts.push_str_with_color("Red color text", Color::Red);
texts.push_str_with_color(", pushed texts become a single String.", Color::Yellow);
texts.push_str_with_color("\n If you want to add break lines, you should add `\n`.", Color::Magenta);
println!("{}", texts);

Text can be pushed color and attribute to Vector. When color or attribute are different, it will be pushed as different String.

Example
let mut texts = StyledStrings::default();
texts.push_str_with_color_and_attribute("Magenta and bold text\n", Color::Magenta, Attribute::Bold);
texts.push_str_with_color_and_attribute("White and underlined text", Color::White, Attribute::Underline);
// texts.push_str_with_color_and_attribute("Must be specify the color and attribute", None, Attribute::Underline);
println!("{}", texts);

Determine if all strings in Vec are empty Returns False if any string is present.

Trait Implementations§

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.