Skip to main content

Text

Struct Text 

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

Styled text.

Implementations§

Source§

impl Text

Source

pub fn new(cm: ColorMode) -> Self

Examples found in repository?
examples/switch.rs (line 10)
5fn main() {
6  let args = std::env::args().collect::<Vec<String>>();
7  let color_mode = if args.len() != 2 { ColorMode::default() } else { ColorMode::new(&args[1]) };
8  println!(
9    "{}",
10    Text::new(color_mode)
11      .s("Switching colors:\n")
12      .black()
13      .s(" 0 ")
14      .red()
15      .s(" 1 ")
16      .green()
17      .s(" 2 ")
18      .yellow()
19      .s(" 3 ")
20      .blue()
21      .s(" 4 ")
22      .magenta()
23      .s(" 5 ")
24      .cyan()
25      .s(" 6 ")
26      .white()
27      .s(" 7 ")
28      .reset()
29  );
30}
Source

pub fn auto() -> Self

Examples found in repository?
examples/hello-world.rs (line 6)
5fn main() {
6  let greeting = Text::auto().yellow().s("Hello").reset().s(' ').green().s("world").reset().s('!');
7  println!("{}", greeting);
8}
More examples
Hide additional examples
examples/basic.rs (line 22)
19fn main() {
20  println!(
21    "{}",
22    Text::auto()
23      .s("Foreground colors:\n")
24      .black()
25      .s(" 0 ")
26      .red()
27      .s(" 1 ")
28      .green()
29      .s(" 2 ")
30      .yellow()
31      .s(" 3 ")
32      .blue()
33      .s(" 4 ")
34      .magenta()
35      .s(" 5 ")
36      .cyan()
37      .s(" 6 ")
38      .white()
39      .s(" 7 ")
40      .reset()
41  );
42}
Source

pub fn on() -> Self

Examples found in repository?
examples/always.rs (line 20)
17fn main() {
18  println!(
19    "{}",
20    Text::on()
21      .s("Always colored:\n")
22      .black()
23      .s(" 0 ")
24      .red()
25      .s(" 1 ")
26      .green()
27      .s(" 2 ")
28      .yellow()
29      .s(" 3 ")
30      .blue()
31      .s(" 4 ")
32      .magenta()
33      .s(" 5 ")
34      .cyan()
35      .s(" 6 ")
36      .white()
37      .s(" 7 ")
38      .reset()
39  );
40}
Source

pub fn off() -> Self

Examples found in repository?
examples/never.rs (line 20)
17fn main() {
18  println!(
19    "{}",
20    Text::off()
21      .s("Never colored:\n")
22      .black()
23      .s(" 0 ")
24      .red()
25      .s(" 1 ")
26      .green()
27      .s(" 2 ")
28      .yellow()
29      .s(" 3 ")
30      .blue()
31      .s(" 4 ")
32      .magenta()
33      .s(" 5 ")
34      .cyan()
35      .s(" 6 ")
36      .white()
37      .s(" 7 ")
38      .reset()
39  );
40}

Trait Implementations§

Source§

impl Add<&Text> for &str

Source§

type Output = Text

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Text) -> Text

Performs the + operation. Read more
Source§

impl Add<&Text> for Text

Source§

type Output = Text

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Text) -> Text

Performs the + operation. Read more
Source§

impl Add<&str> for Text

Source§

type Output = Text

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &str) -> Text

Performs the + operation. Read more
Source§

impl Add<Text> for &str

Source§

type Output = Text

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Text) -> Text

Performs the + operation. Read more
Source§

impl Add for Text

Source§

type Output = Text

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Text) -> Text

Performs the + operation. Read more
Source§

impl AddAssign<&Text> for Text

Source§

fn add_assign(&mut self, rhs: &Text)

Performs the += operation. Read more
Source§

impl AddAssign<&str> for Text

Source§

fn add_assign(&mut self, rhs: &str)

Performs the += operation. Read more
Source§

impl AddAssign for Text

Source§

fn add_assign(&mut self, rhs: Text)

Performs the += operation. Read more
Source§

impl Clone for Text

Source§

fn clone(&self) -> Text

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 Text

Source§

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

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

impl Default for Text

Source§

fn default() -> Self

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

impl Display for Text

Source§

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

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

impl From<ColorMode> for Text

Source§

fn from(cm: ColorMode) -> Self

Converts to this type from the input type.
Source§

impl StyledText for Text

Source§

fn s<T: Display>(self, s: T) -> Self

Adds content to text.
Source§

fn reset(self) -> Self

Resets all colors and styling flags.
Source§

fn repeat<T: Display>(self, s: T, n: usize) -> Self

Adds repeated content to text.
Source§

fn plural<T: Display>(self, s: T, n: usize) -> Self

Adds s suffix to the content when the number is not 1.
Source§

fn align_left<T: Display>(self, s: T, width: usize) -> Self

Adds the content aligned left with specified width.
Source§

fn align_right<T: Display>(self, s: T, width: usize) -> Self

Adds the content aligned right with specified width.
Source§

fn align_center<T: Display>(self, s: T, width: usize) -> Self

Adds the content centered with specified width.
Source§

fn pad<T: Display>(self, ch: char, padding: usize, s: T) -> Self

Pads the content with specified character.
Source§

fn pad_left<T: Display>(self, ch: char, s: T, width: usize) -> Self

Pads the content aligned the left with specified width.
Source§

fn pad_right<T: Display>(self, ch: char, s: T, width: usize) -> Self

Pads the content aligned right with specified width.
Source§

fn pad_center<T: Display>(self, ch: char, s: T, width: usize) -> Self

Pads the content centered with specified width.
Source§

fn choose<T: Display>( self, condition: bool, when_true: T, when_false: T, ) -> Self

Adds new content based on the condition.
Source§

fn indent<T: Display>(self, indent: usize, s: T) -> Self

Adds indented content.
Source§

fn bold(self) -> Self

Style text as bold.
Source§

fn italic(self) -> Self

Style text as italic.
Source§

fn underline(self) -> Self

Style text as underlined.
Source§

fn black(self) -> Self

Sets the foreground color to black.
Source§

fn bright_black(self) -> Self

Sets the foreground color to bright black.
Source§

fn red(self) -> Self

Sets the foreground color to red.
Source§

fn bright_red(self) -> Self

Sets the foreground color to bright red.
Source§

fn green(self) -> Self

Sets the foreground color to green.
Source§

fn bright_green(self) -> Self

Sets the foreground color to bright green.
Source§

fn yellow(self) -> Self

Sets the foreground color to yellow.
Source§

fn bright_yellow(self) -> Self

Sets the foreground color to bright yellow.
Source§

fn blue(self) -> Self

Sets the foreground color to blue.
Source§

fn bright_blue(self) -> Self

Sets the foreground color to bright blue.
Source§

fn magenta(self) -> Self

Sets the foreground color to magenta.
Source§

fn bright_magenta(self) -> Self

Sets the foreground color to bright magenta.
Source§

fn cyan(self) -> Self

Sets the foreground color to cyan.
Source§

fn bright_cyan(self) -> Self

Sets the foreground color to bright cyan.
Source§

fn white(self) -> Self

Sets the foreground color to white.
Source§

fn bright_white(self) -> Self

Sets the foreground color to bright white.
Source§

fn bg_black(self) -> Self

Sets the background color to black.
Source§

fn bg_bright_black(self) -> Self

Sets the background color to bright black.
Source§

fn bg_red(self) -> Self

Sets the background color to red.
Source§

fn bg_bright_red(self) -> Self

Sets the background color to bright red.
Source§

fn bg_green(self) -> Self

Sets the background color to green.
Source§

fn bg_bright_green(self) -> Self

Sets the background color to bright green.
Source§

fn bg_yellow(self) -> Self

Sets the background color to yellow.
Source§

fn bg_bright_yellow(self) -> Self

Sets the background color to bright yellow.
Source§

fn bg_blue(self) -> Self

Sets the background color to blue.
Source§

fn bg_bright_blue(self) -> Self

Sets the background color to bright blue.
Source§

fn bg_magenta(self) -> Self

Sets the background color to magenta.
Source§

fn bg_bright_magenta(self) -> Self

Sets the background color to bright magenta.
Source§

fn bg_cyan(self) -> Self

Sets the background color to cyan.
Source§

fn bg_bright_cyan(self) -> Self

Sets the background color to bright cyan.
Source§

fn bg_white(self) -> Self

Sets the background color to white.
Source§

fn bg_bright_white(self) -> Self

Sets the background color to bright white.
Source§

fn color(self, c: Color) -> Self

Sets the color by color enumeration.
Source§

fn bright_color(self, c: Color) -> Self

Sets the bright color by color enumeration.
Source§

fn bg_color(self, c: Color) -> Self

Sets the background color by color enumeration.
Source§

fn bg_bright_color(self, c: Color) -> Self

Sets the background bright color by color enumeration.
Source§

fn color_8(self, c: u8) -> Self

Sets the color by color index.
Source§

fn bright_color_8(self, c: u8) -> Self

Sets the bright color by color index.
Source§

fn bg_color_8(self, c: u8) -> Self

Sets the background color by color index.
Source§

fn bg_bright_color_8(self, c: u8) -> Self

Sets the background bright color by color index.
Source§

fn color_256(self, c: u8) -> Self

Source§

fn bg_color_256(self, c: u8) -> Self

Source§

fn color_rgb(self, c: RgbColor) -> Self

Source§

fn bg_color_rgb(self, c: RgbColor) -> Self

Source§

fn r<T: Display>(self, s: T) -> Self

Resets all styling and then appends formatted content. Read more

Auto Trait Implementations§

§

impl Freeze for Text

§

impl RefUnwindSafe for Text

§

impl Send for Text

§

impl Sync for Text

§

impl Unpin for Text

§

impl UnsafeUnpin for Text

§

impl UnwindSafe for Text

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