[−][src]Struct ansi_colors::ColouredStr
This struct is the main way to utilize the coloring sceme in this crate.
This struct contains a number of parameters inquiring to the strings state, such as style,color,base string, reset actions, background and several internal things. this structs, as it say's below implements the fmt::Display trait, that means that you will not need to do anything special in order to print after you have changed the color you can use only one color but you can have even all the styles together!
here is a blue,bold,underlined and blinking string example(just a fromatted output) :
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.blue(); str1.bold(); str1.underline(); str1.blink(); let str2 = format!("{}{}{}","\u{1b}[1;4;5;49;34m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
here is a white,bold and hidden string example(good for passwords):
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.white(); str1.bold(); str1.hidden(); let str2 = format!("{}{}{}","\u{1b}[1;8;49;97m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
Fields
string: &'a str
coloured_string: String
Methods
impl<'a> ColouredStr<'a>
[src]
pub fn new(string: &str) -> ColouredStr
[src]
This functions recieves one parameter - a string and creates a defult struct for it. the color is natural(no change), as well as the styles and background.
use ansi_colors::*; let str1 = ColouredStr::new("hello world"); assert_eq!(str1.string,"hello world");
pub fn blue(&mut self)
[src]
This functions takes self and changes coloured string color into blue
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.blue(); let str2 = format!("{}{}{}","\u{1b}[49;34m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn black(&mut self)
[src]
This functions takes self and changes coloured string color into black
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.black(); let str2 = format!("{}{}{}","\u{1b}[49;30m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn red(&mut self)
[src]
This functions takes self and changes coloured string color into red
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.red(); let str2 = format!("{}{}{}","\u{1b}[49;31m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn green(&mut self)
[src]
This functions takes self and changes coloured string color into green
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.green(); let str2 = format!("{}{}{}","\u{1b}[49;32m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn yellow(&mut self)
[src]
This functions takes self and changes coloured string color into yellow
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.yellow(); let str2 = format!("{}{}{}","\u{1b}[49;33m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn magenta(&mut self)
[src]
This functions takes self and changes coloured string color into magenta
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.magenta(); let str2 = format!("{}{}{}","\u{1b}[49;35m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn cyan(&mut self)
[src]
This functions takes self and changes coloured string color into cyan
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.cyan(); let str2 = format!("{}{}{}","\u{1b}[49;36m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn gray(&mut self)
[src]
This functions takes self and changes coloured string color into gray
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.gray(); let str2 = format!("{}{}{}","\u{1b}[49;37m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn dark_gray(&mut self)
[src]
This functions takes self and changes coloured string color into dark gray
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.dark_gray(); let str2 = format!("{}{}{}","\u{1b}[49;90m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn light_red(&mut self)
[src]
This functions takes self and changes coloured string color into light red
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.light_red(); let str2 = format!("{}{}{}","\u{1b}[49;91m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn light_green(&mut self)
[src]
This functions takes self and changes coloured string color into light green
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.light_green(); let str2 = format!("{}{}{}","\u{1b}[49;92m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn light_yellow(&mut self)
[src]
This functions takes self and changes coloured string color into light yellow
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.light_yellow(); let str2 = format!("{}{}{}","\u{1b}[49;93m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn light_blue(&mut self)
[src]
This functions takes self and changes coloured string color into light blue
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.light_blue(); let str2 = format!("{}{}{}","\u{1b}[49;94m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn pink(&mut self)
[src]
This functions takes self and changes coloured string color into pink
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.pink(); let str2 = format!("{}{}{}","\u{1b}[49;95m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn light_cyan(&mut self)
[src]
This functions takes self and changes coloured string color into light cyan
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.light_cyan(); let str2 = format!("{}{}{}","\u{1b}[49;96m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn white(&mut self)
[src]
This functions takes self and changes coloured string color into white
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.white(); let str2 = format!("{}{}{}","\u{1b}[49;97m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn none(&mut self)
[src]
This functions takes self and resets the string's color
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.none(); let str2 = format!("{}{}{}","\u{1b}[49;39m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn bold(&mut self)
[src]
This functions takes self and adds the bold style to the string
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.bold(); let str2 = format!("{}{}{}","\u{1b}[1;49;97m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn dim(&mut self)
[src]
This functions takes self and adds the dim style to the string
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.dim(); let str2 = format!("{}{}{}","\u{1b}[2;49;97m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn underline(&mut self)
[src]
This functions takes self and adds the underline style to the string
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.underline(); let str2 = format!("{}{}{}","\u{1b}[4;49;97m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn blink(&mut self)
[src]
This functions takes self and adds the blinking style to the string
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.blink(); let str2 = format!("{}{}{}","\u{1b}[5;49;97m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn reverse(&mut self)
[src]
This functions takes self and adds the reverse style to the string
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.reverse(); let str2 = format!("{}{}{}","\u{1b}[7;49;97m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
[src]
This functions takes self and adds the hidden( ) style to the string
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.hidden(); let str2 = format!("{}{}{}","\u{1b}[8;49;97m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn back_black(&mut self)
[src]
This functions takes self and changes the background to be black
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.white(); str1.back_black(); let str2 = format!("{}{}{}","\u{1b}[40;97m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn back_red(&mut self)
[src]
This functions takes self and changes the background to be red
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.blue(); str1.back_red(); let str2 = format!("{}{}{}","\u{1b}[41;34m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn back_blue(&mut self)
[src]
This functions takes self and changes the background to be blue
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.red(); str1.back_blue(); let str2 = format!("{}{}{}","\u{1b}[44;31m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn back_green(&mut self)
[src]
This functions takes self and changes the background to be green
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.red(); str1.back_green(); let str2 = format!("{}{}{}","\u{1b}[42;31m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn back_yellow(&mut self)
[src]
This functions takes self and changes the background to be yellow
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.magenta(); str1.back_yellow(); let str2 = format!("{}{}{}","\u{1b}[43;35m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn back_magenta(&mut self)
[src]
This functions takes self and changes the background to be magenta
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.black(); str1.back_magenta(); let str2 = format!("{}{}{}","\u{1b}[45;30m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn back_cyan(&mut self)
[src]
This functions takes self and changes the background to be cyan
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.red(); str1.back_cyan(); let str2 = format!("{}{}{}","\u{1b}[46;31m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn back_gray(&mut self)
[src]
This functions takes self and changes the background to be gray
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.yellow(); str1.back_gray(); let str2 = format!("{}{}{}","\u{1b}[47;33m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn back_dark_gray(&mut self)
[src]
This functions takes self and changes the background to be dark gray
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.white(); str1.back_dark_gray(); let str2 = format!("{}{}{}","\u{1b}[100;97m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn back_light_red(&mut self)
[src]
This functions takes self and changes the background to be light red
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.black(); str1.back_light_red(); let str2 = format!("{}{}{}","\u{1b}[101;30m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn back_light_green(&mut self)
[src]
This functions takes self and changes the background to be light green
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.red(); str1.back_light_green(); let str2 = format!("{}{}{}","\u{1b}[102;31m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn back_light_yellow(&mut self)
[src]
This functions takes self and changes the background to be light yellow
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.blue(); str1.back_light_yellow(); let str2 = format!("{}{}{}","\u{1b}[103;34m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn back_light_blue(&mut self)
[src]
This functions takes self and changes the background to be light blue
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.black(); str1.back_light_blue(); let str2 = format!("{}{}{}","\u{1b}[104;30m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn back_pink(&mut self)
[src]
This functions takes self and changes the background to be pink
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.black(); str1.back_pink(); let str2 = format!("{}{}{}","\u{1b}[105;30m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn back_light_cyan(&mut self)
[src]
This functions takes self and changes the background to be light cyan
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.red(); str1.back_light_green(); let str2 = format!("{}{}{}","\u{1b}[102;31m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn back_white(&mut self)
[src]
This functions takes self and changes the background to be white
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.black(); str1.back_white(); let str2 = format!("{}{}{}","\u{1b}[107;30m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn back_none(&mut self)
[src]
This functions takes self and changes the background to be none
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.red(); str1.back_none(); let str2 = format!("{}{}{}","\u{1b}[49;31m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn reset_all(&mut self)
[src]
This functions takes self and adds the reset all operation to the reset
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.blink(); str1.reset_all(); let str2 = format!("{}{}{}","\u{1b}[5;49;97m","hello world","\u{1b}[0m"); assert_eq!(str1.coloured_string,str2);
pub fn reset_bold(&mut self)
[src]
This functions takes self and adds the reset bold operation to the reset it means it resets only the bold style, not any other active styles or colors.
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.bold(); str1.red(); str1.reset_bold(); let str2 = format!("{}{}{}","\u{1b}[1;49;31m","hello world","\u{1b}[21m"); assert_eq!(str1.coloured_string,str2);
pub fn reset_dim(&mut self)
[src]
This functions takes self and adds the reset dim operation to the reset it means it resets only the dim style, not any other active styles or colors.
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.dim(); str1.bold(); str1.reset_dim(); let str2 = format!("{}{}{}","\u{1b}[2;1;49;97m","hello world","\u{1b}[22m"); assert_eq!(str1.coloured_string,str2);
pub fn reset_underline(&mut self)
[src]
This functions takes self and adds the reset underline operation to the reset it means it resets only the underline style, not any other active styles or colors.
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.underline(); str1.back_green(); str1.reset_underline(); let str2 = format!("{}{}{}","\u{1b}[4;42;97m","hello world","\u{1b}[24m"); assert_eq!(str1.coloured_string,str2);
pub fn reset_blink(&mut self)
[src]
This functions takes self and adds the reset blink operation to the reset it means it resets only the blink style, not any other active styles or colors.
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.blink(); str1.red(); str1.reset_blink(); let str2 = format!("{}{}{}","\u{1b}[5;49;31m","hello world","\u{1b}[25m"); assert_eq!(str1.coloured_string,str2);
pub fn reset_reverse(&mut self)
[src]
This functions takes self and adds the reset reverse operation to the reset it means it resets only the reverse style, not any other active styles or colors.
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.reverse(); str1.back_red(); str1.reset_reverse(); let str2 = format!("{}{}{}","\u{1b}[7;41;97m","hello world","\u{1b}[27m"); assert_eq!(str1.coloured_string,str2);
[src]
This functions takes self and adds the reset hidden operation to the reset it means it resets only the hidden style, not any other active styles or colors.
use ansi_colors::*; let mut str1 = ColouredStr::new("hello world"); str1.hidden(); str1.back_black(); str1.reset_hidden(); let str2 = format!("{}{}{}","\u{1b}[8;40;97m","hello world","\u{1b}[28m"); assert_eq!(str1.coloured_string,str2);
Trait Implementations
impl<'a> Clone for ColouredStr<'a>
[src]
fn clone(&self) -> ColouredStr<'a>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a> Display for ColouredStr<'a>
[src]
Auto Trait Implementations
impl<'a> Sync for ColouredStr<'a>
impl<'a> Unpin for ColouredStr<'a>
impl<'a> Send for ColouredStr<'a>
impl<'a> UnwindSafe for ColouredStr<'a>
impl<'a> RefUnwindSafe for ColouredStr<'a>
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,