SGRString

Struct SGRString 

Source
pub struct SGRString {
Show 15 fields pub text: String, pub clean: CleanKind, pub custom_places: Vec<u8>, pub custom_cleans: Vec<u8>, pub foreground: ColorKind, pub background: ColorKind, pub reset: bool, pub bold: StyleKind, pub dim: StyleKind, pub italic: StyleKind, pub underline: StyleKind, pub blinking: StyleKind, pub inverse: StyleKind, pub hidden: StyleKind, pub strikethrough: StyleKind,
}
Expand description

A String encapsulating the usage of SGR codes

SGR codes are applied when the Display trait is used, or when the SGRString::place_all or SGRString::clean_all functions are called.

Writing is done through the use of the writing module

§Examples

use easy_sgr::{ColorKind, SGRString, StyleKind};

let mut string = SGRString::default();
string.text = String::from("This is my text");
string.bold = StyleKind::Place;
string.foreground = ColorKind::Red;
println!("{string}");

Fields§

§text: String

The actual text

§clean: CleanKind

The type of clean to apply when SGRString::clean_all is called

By default CleanKind::None, meaning nothing is done

§custom_places: Vec<u8>

Any custom codes added

These codes are written before the string when the Display trait is called

§custom_cleans: Vec<u8>

Any custom codes added

These codes are written after the string when the Display trait is called

§foreground: ColorKind

The color of the foreground

By default ColorKind::None, meaning nothing is applied. Not to be confused with ColorKind::Default, where the default SGR code for the foreground is applied.

§background: ColorKind

The color of the background

By default ColorKind::None, meaning nothing is applied. Not to be confused with ColorKind::Default, where the default SGR code for the background is applied.

§reset: bool

Determines whether the clear code 0 is to be applied to the beginning

Not be confused with [SGRString.clean], this effects SGRString::place_all

§bold: StyleKind

Refer to StyleKind

§dim: StyleKind

Refer to StyleKind

§italic: StyleKind

Refer to StyleKind

§underline: StyleKind

Refer to StyleKind

§blinking: StyleKind

Refer to StyleKind

§inverse: StyleKind

Refer to StyleKind

§hidden: StyleKind

Refer to StyleKind

§strikethrough: StyleKind

Refer to StyleKind

Implementations§

Source§

impl SGRString

Source

pub fn place_all(&self, builder: &mut SGRBuilder)

Writes all contained SGR codes to the given SGRBuilder

Does not perform any IO operations

Source

pub fn place_colors(&self, builder: &mut SGRBuilder)

Writes contained SGR color codes to the given SGRWriter

Does not perform any IO operations

Source

pub fn place_styles(&self, builder: &mut SGRBuilder)

Writes SGR style codes to the given SGRWriter

Does not perform any IO operations

Source

pub fn place_custom(&self, builder: &mut SGRBuilder)

Writes custom SGR codes to the given SGRWriter

Does not perform any IO operations

Source

pub fn clean_all(&self, builder: &mut SGRBuilder)

Writes contained SGR codes to the given SGRWriter

Reverses the effects of SGRString::place_all

Does not perform any IO operations

Source

pub fn clean_colors(&self, builder: &mut SGRBuilder)

Writes SGR color codes to the given SGRWriter

Reverses the effects of SGRString::place_colors

Does not perform any IO operations

Source

pub fn clean_styles(&self, builder: &mut SGRBuilder)

Writes SGR style codes to the given SGRWriter

Reverses the effects of SGRString::place_styles

Does not perform any IO operations

Source

pub fn clean_custom(&self, builder: &mut SGRBuilder)

Writes SGR codes to the given SGRWriter

Reverses the effects of SGRString::place_custom

Does not perform any IO operations

Trait Implementations§

Source§

impl Clone for SGRString

Source§

fn clone(&self) -> SGRString

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 SGRString

Source§

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

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

impl Default for SGRString

Source§

fn default() -> SGRString

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

impl Display for SGRString

Source§

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

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

impl EasyWrite for SGRString

Source§

fn sgr(&self, builder: &mut SGRBuilder)

Writes a set of codes to the builder

Uses SGRString::place_all

Source§

impl From<&String> for SGRString

Source§

fn from(value: &String) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for SGRString

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Color> for SGRString

Source§

fn from(value: Color) -> Self

Converts to this type from the input type.
Source§

impl From<String> for SGRString

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<Style> for SGRString

Source§

fn from(value: Style) -> Self

Converts to this type from the input type.

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> 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<I> EasySGR for I
where I: Into<SGRString>,

Source§

fn to_sgr(self) -> SGRString

Turns self into SGRString Read more
Source§

fn text(self, text: impl Into<String>) -> SGRString

Sets the normal text of the returned SGRString
Source§

fn style(self, style: impl Into<Style>) -> SGRString

Adds a style to the returned SGRString
Source§

fn color(self, color: impl Into<Color>) -> SGRString

Adds a color(foreground or background) to the returned SGRString
Source§

fn custom(self, code: impl Into<u8>) -> SGRString

Adds a custom code to the returned SGRString Read more
Source§

fn clean(self, clean: impl Into<CleanKind>) -> SGRString

Sets the CleanKind variant of the returned SGRString
Source§

fn custom_place(self, code: impl Into<u8>) -> SGRString

Adds a custom code to be written before the returned SGRString’s text
Source§

fn custom_clean(self, code: impl Into<u8>) -> SGRString

Adds a custom code to be written after the returned SGRString’s text
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.