Struct OutputFormatter

Source
pub struct OutputFormatter { /* private fields */ }

Implementations§

Source§

impl OutputFormatter

This struct is used to create the builder for CLI-colors the following example creates a string “hi”, that has white (as hex-color) foreground and green background

Example

use terminal_color_builder::*;
let str = OutputFormatter::new().fg().hex("#fff").bg().green().text("Hi".to_string()).print();
Source

pub fn new() -> Self

Source

pub fn fg(self) -> OutputColor

Set the current context to foreground

Source

pub fn bg(self) -> OutputColor

Set the current context to foreground

Source

pub fn custom(self, fg: COLORS, bg: COLORS) -> OutputFormatter

apply custom color with the COLORS-enum

Example

use terminal_color_builder::*;
use terminal_color_builder::color::COLORS;
let c = OutputFormatter::new().custom(COLORS::White, COLORS::Green).text("Hi".to_string());
Source

pub fn text(self, message: String) -> Self

add text to apply color for

Source

pub fn text_str(self, message: &str) -> Self

add text as str to apply color for

Source

pub fn print(&self) -> String

render the builder into a string

Auto Trait Implementations§

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