Struct erg_common::style::StyledStrings
source · 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§
source§impl StyledStrings
impl StyledStrings
sourcepub fn push_str(&mut self, s: &str)
pub fn push_str(&mut self, s: &str)
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
*/
sourcepub fn push_str_with_color<'a, S: Into<Cow<'a, str>>>(
&mut self,
s: S,
color: Color
)
pub fn push_str_with_color<'a, S: Into<Cow<'a, str>>>(
&mut self,
s: S,
color: Color
)
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);
sourcepub fn push_str_with_color_and_attribute<'a, S: Into<Cow<'a, str>>>(
&mut self,
s: S,
color: Color,
attr: Attribute
)
pub fn push_str_with_color_and_attribute<'a, S: Into<Cow<'a, str>>>(
&mut self,
s: S,
color: Color,
attr: Attribute
)
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);
Trait Implementations§
source§impl Debug for StyledStrings
impl Debug for StyledStrings
source§impl Default for StyledStrings
impl Default for StyledStrings
source§fn default() -> StyledStrings
fn default() -> StyledStrings
Returns the “default value” for a type. Read more
source§impl Display for StyledStrings
impl Display for StyledStrings
source§impl From<StyledStrings> for String
impl From<StyledStrings> for String
source§fn from(s: StyledStrings) -> Self
fn from(s: StyledStrings) -> Self
Converts to this type from the input type.