ansi_colors/
lib.rs

1///this mod public use is for you to understand the ansi escape codes:)
2pub mod colors;
3use std::fmt;
4use crate::colors::*;
5#[derive(Clone)]
6///This struct is the main way to utilize the coloring sceme in this crate.
7///
8///
9///This struct contains a number of parameters inquiring to the strings state, such as
10///style,color,base string, reset actions, background and several internal things.
11///this structs, as it say's below implements the fmt::Display trait, that means that you will not
12///need to do anything special in order to print after you have changed the color
13///you can use only one color but you can have even all the styles together!
14///
15///here is a blue,bold,underlined and blinking string example(just a fromatted output) :
16///```
17///use ansi_colors::*;
18///let mut str1 = ColouredStr::new("hello world");
19///str1.blue();
20///str1.bold();
21///str1.underline();
22///str1.blink();
23///let str2 = format!("{}{}{}","\u{1b}[1;4;5;49;34m","hello world","\u{1b}[0m");
24///assert_eq!(str1.coloured_string,str2);
25///```
26///here is a white,bold and hidden string example(good for passwords):
27///
28///
29///```
30///use ansi_colors::*;
31///let mut str1 = ColouredStr::new("hello world");
32///str1.white();
33///str1.bold();
34///str1.hidden();
35///let str2 = format!("{}{}{}","\u{1b}[1;8;49;97m","hello world","\u{1b}[0m");
36///assert_eq!(str1.coloured_string,str2);
37pub struct ColouredStr<'a>{
38    pub string:&'a str,
39    pub coloured_string:String,
40    colorer:String,
41    closer:String,
42    resets:Vec<Reset>,
43    text_color:TextColours,
44    background_color:BackColours,
45    styles:Vec<Styles>,
46}
47impl <'a> fmt::Display for ColouredStr<'a> {
48    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
49        write!(f, "{}", self.coloured_string)
50    }
51}
52impl <'a> ColouredStr<'a> {
53    ///This functions recieves one parameter - a string and creates a defult struct for it.
54    ///the color is natural(no change), as well as the styles and background.
55    ///
56    ///
57    ///```
58    ///use ansi_colors::*;
59    ///let str1 = ColouredStr::new("hello world");
60    ///assert_eq!(str1.string,"hello world");
61    ///```
62    pub fn new(string:&str)->ColouredStr{
63        let colorer = format!("{}{}",OPENING_COLOR,COLOR_CLOSER);
64        let closer = format!("{}{}{}",OPENING_COLOR,"0",COLOR_CLOSER);
65        let styles = vec![];
66        let resets = vec![Reset::All];
67        let coloured_string = format!("{}{}{}",&colorer[..],string,&closer[..]);
68        let col1 = ColouredStr{
69            string,coloured_string,colorer,closer,resets,text_color:TextColours::White,background_color:BackColours::NaN,styles
70        };
71        return col1;
72    }
73    /*
74    fn cpy(self)->Self{
75        let col1 = ColouredStr{
76            string:self.string,
77            coloured_string:self.coloured_string,
78            colorer:self.colorer,
79            closer:self.closer,
80            resets:self.resets,
81            text_color:self.text_color,
82            background_color:self.,
83            styles:self.styles};
84        col1
85        cc
86    }*/
87    fn refresh(&mut self){
88        let clo1 = &(self.set_closer())[..];
89        let col1 = &(self.set_colorer())[..];
90        let strr = self.string;
91        (*self).coloured_string = format!("{}{}{}",col1,strr,clo1);
92    }
93    fn set_colorer(&self)->String{
94        let mut tc = "".to_string();
95        if (self.text_color as u8) != 0{
96            tc = (self.text_color as u8).to_string();
97        }
98        let mut bc = "".to_string();
99        if (self.background_color as u8) != 0{
100            bc = (self.background_color as u8).to_string();
101        }
102        let mut strrr = "".to_string();
103        if self.styles.len()>1{
104            for i in 0..self.styles.len(){
105                strrr.push_str(&(self.styles[i] as u8).to_string()[..]);
106                strrr.push(';');
107            }
108        }else if self.styles.len()==1{
109            strrr = format!("{};",&(self.styles[0] as u8).to_string()[..]);
110        }
111        return format!("{}{}{};{}{}",OPENING_COLOR,&strrr[..],&bc[..],&tc[..],COLOR_CLOSER);
112    }
113    fn set_closer(&mut self)->String {
114        let mut res = "".to_string();
115        if self.resets[0]==Reset::All && self.resets.len()>1{
116            self.resets = self.resets[1..].to_vec();
117        }
118        if self.resets.len()>1{
119            for i in 0..self.resets.len(){
120                res.push_str(&(self.resets[i] as u8).to_string()[..]);
121                res.push(';');
122            }
123        }else if self.resets.len()==1{
124            res = format!("{}",&(self.resets[0] as u8).to_string()[..]);
125        }
126        return format!("{}{}{}",OPENING_COLOR,&res[..],COLOR_CLOSER);
127    }
128    ///This functions takes self and presents the color string in error format
129    pub fn to_error(&mut self){
130        self.red();
131        self.bold();
132        self.underline();
133        self.blink();
134    }
135    ///This functions takes self and presents the color string in success format
136    pub fn to_success(&mut self){
137        self.green();
138        self.bold();
139    }
140    ///This functions takes self and presents the color string in password format
141    pub fn to_password(&mut self){
142        self.hidden();
143    }
144    ///This functions takes self and changes coloured string color into blue
145    ///
146    ///
147    ///```
148    ///use ansi_colors::*;
149    ///let mut str1 = ColouredStr::new("hello world");
150    ///str1.blue();
151    ///let str2 = format!("{}{}{}","\u{1b}[49;34m","hello world","\u{1b}[0m");
152    ///assert_eq!(str1.coloured_string,str2);
153    ///```
154    pub fn blue(&mut self)->Self{
155        let mut strrr = self.clone();
156        self.text_color = TextColours::Blue; 
157        strrr.text_color = TextColours::Blue; 
158        self.refresh();
159        strrr.refresh();
160        strrr
161    }
162    ///This functions takes self and changes coloured string color into black
163    ///
164    ///
165    ///```
166    ///use ansi_colors::*;
167    ///let mut str1 = ColouredStr::new("hello world");
168    ///str1.black();
169    ///let str2 = format!("{}{}{}","\u{1b}[49;30m","hello world","\u{1b}[0m");
170    ///assert_eq!(str1.coloured_string,str2);
171    ///```
172    pub fn black(&mut self){
173        self.text_color = TextColours::Black;
174        self.refresh();
175    }
176    ///This functions takes self and changes coloured string color into red
177    ///
178    ///
179    ///```
180    ///use ansi_colors::*;
181    ///let mut str1 = ColouredStr::new("hello world");
182    ///str1.red();
183    ///let str2 = format!("{}{}{}","\u{1b}[49;31m","hello world","\u{1b}[0m");
184    ///assert_eq!(str1.coloured_string,str2);
185    ///```
186    pub fn red(&mut self){
187        self.text_color = TextColours::Red; 
188        self.refresh();
189    }
190    ///This functions takes self and changes coloured string color into green
191    ///
192    ///
193    ///```
194    ///use ansi_colors::*;
195    ///let mut str1 = ColouredStr::new("hello world");
196    ///str1.green();
197    ///let str2 = format!("{}{}{}","\u{1b}[49;32m","hello world","\u{1b}[0m");
198    ///assert_eq!(str1.coloured_string,str2);
199    ///```
200    pub fn green(&mut self){
201        self.text_color = TextColours::Green; 
202        self.refresh();
203    }
204    ///This functions takes self and changes coloured string color into yellow
205    ///
206    ///
207    ///```
208    ///use ansi_colors::*;
209    ///let mut str1 = ColouredStr::new("hello world");
210    ///str1.yellow();
211    ///let str2 = format!("{}{}{}","\u{1b}[49;33m","hello world","\u{1b}[0m");
212    ///assert_eq!(str1.coloured_string,str2);
213    ///```
214    pub fn yellow(&mut self){
215        self.text_color = TextColours::Yellow; 
216        self.refresh();
217    }
218    ///This functions takes self and changes coloured string color into magenta
219    ///
220    ///
221    ///```
222    ///use ansi_colors::*;
223    ///let mut str1 = ColouredStr::new("hello world");
224    ///str1.magenta();
225    ///let str2 = format!("{}{}{}","\u{1b}[49;35m","hello world","\u{1b}[0m");
226    ///assert_eq!(str1.coloured_string,str2);
227    ///```
228    pub fn magenta(&mut self){
229        self.text_color = TextColours::Magenta; 
230        self.refresh();
231    }
232    ///This functions takes self and changes coloured string color into cyan
233    ///
234    ///
235    ///```
236    ///use ansi_colors::*;
237    ///let mut str1 = ColouredStr::new("hello world");
238    ///str1.cyan();
239    ///let str2 = format!("{}{}{}","\u{1b}[49;36m","hello world","\u{1b}[0m");
240    ///assert_eq!(str1.coloured_string,str2);
241    ///```
242    pub fn cyan(&mut self){
243        self.text_color = TextColours::Cyan; 
244        self.refresh();
245    }
246    ///This functions takes self and changes coloured string color into gray
247    ///
248    ///
249    ///```
250    ///use ansi_colors::*;
251    ///let mut str1 = ColouredStr::new("hello world");
252    ///str1.gray();
253    ///let str2 = format!("{}{}{}","\u{1b}[49;37m","hello world","\u{1b}[0m");
254    ///assert_eq!(str1.coloured_string,str2);
255    ///```
256    pub fn gray(&mut self){
257        self.text_color = TextColours::Gray; 
258        self.refresh();
259    }
260    ///This functions takes self and changes coloured string color into dark gray
261    ///
262    ///
263    ///```
264    ///use ansi_colors::*;
265    ///let mut str1 = ColouredStr::new("hello world");
266    ///str1.dark_gray();
267    ///let str2 = format!("{}{}{}","\u{1b}[49;90m","hello world","\u{1b}[0m");
268    ///assert_eq!(str1.coloured_string,str2);
269    ///```
270    pub fn dark_gray(&mut self){
271        self.text_color = TextColours::DarkGray; 
272        self.refresh();
273    }
274    ///This functions takes self and changes coloured string color into light red
275    ///
276    ///
277    ///```
278    ///use ansi_colors::*;
279    ///let mut str1 = ColouredStr::new("hello world");
280    ///str1.light_red();
281    ///let str2 = format!("{}{}{}","\u{1b}[49;91m","hello world","\u{1b}[0m");
282    ///assert_eq!(str1.coloured_string,str2);
283    ///```
284    pub fn light_red(&mut self){
285        self.text_color = TextColours::LightRed; 
286        self.refresh();
287    }
288    ///This functions takes self and changes coloured string color into light green
289    ///
290    ///
291    ///```
292    ///use ansi_colors::*;
293    ///let mut str1 = ColouredStr::new("hello world");
294    ///str1.light_green();
295    ///let str2 = format!("{}{}{}","\u{1b}[49;92m","hello world","\u{1b}[0m");
296    ///assert_eq!(str1.coloured_string,str2);
297    ///```
298    pub fn light_green(&mut self){
299        self.text_color = TextColours::LightGreen; 
300        self.refresh();
301    }
302    ///This functions takes self and changes coloured string color into light yellow
303    ///
304    ///
305    ///```
306    ///use ansi_colors::*;
307    ///let mut str1 = ColouredStr::new("hello world");
308    ///str1.light_yellow();
309    ///let str2 = format!("{}{}{}","\u{1b}[49;93m","hello world","\u{1b}[0m");
310    ///assert_eq!(str1.coloured_string,str2);
311    ///```
312    pub fn light_yellow(&mut self){
313        self.text_color = TextColours::LightYellow; 
314        self.refresh();
315    }
316    ///This functions takes self and changes coloured string color into light blue
317    ///
318    ///
319    ///```
320    ///use ansi_colors::*;
321    ///let mut str1 = ColouredStr::new("hello world");
322    ///str1.light_blue();
323    ///let str2 = format!("{}{}{}","\u{1b}[49;94m","hello world","\u{1b}[0m");
324    ///assert_eq!(str1.coloured_string,str2);
325    ///```
326    pub fn light_blue(&mut self){
327        self.text_color = TextColours::LightBlue; 
328        self.refresh();
329    }
330    ///This functions takes self and changes coloured string color into pink
331    ///
332    ///
333    ///```
334    ///use ansi_colors::*;
335    ///let mut str1 = ColouredStr::new("hello world");
336    ///str1.pink();
337    ///let str2 = format!("{}{}{}","\u{1b}[49;95m","hello world","\u{1b}[0m");
338    ///assert_eq!(str1.coloured_string,str2);
339    ///```
340    pub fn pink(&mut self){
341        self.text_color = TextColours::Pink; 
342        self.refresh();
343    }
344    ///This functions takes self and changes coloured string color into light cyan
345    ///
346    ///
347    ///```
348    ///use ansi_colors::*;
349    ///let mut str1 = ColouredStr::new("hello world");
350    ///str1.light_cyan();
351    ///let str2 = format!("{}{}{}","\u{1b}[49;96m","hello world","\u{1b}[0m");
352    ///assert_eq!(str1.coloured_string,str2);
353    ///```
354    pub fn light_cyan(&mut self){
355        self.text_color = TextColours::LightCyan; 
356        self.refresh();
357    }
358    ///This functions takes self and changes coloured string color into white
359    ///
360    ///
361    ///```
362    ///use ansi_colors::*;
363    ///let mut str1 = ColouredStr::new("hello world");
364    ///str1.white();
365    ///let str2 = format!("{}{}{}","\u{1b}[49;97m","hello world","\u{1b}[0m");
366    ///assert_eq!(str1.coloured_string,str2);
367    ///```
368    pub fn white(&mut self){
369        self.text_color = TextColours::White; 
370        self.refresh();
371    }
372    ///This functions takes self and resets the string's color
373    ///
374    ///
375    ///```
376    ///use ansi_colors::*;
377    ///let mut str1 = ColouredStr::new("hello world");
378    ///str1.none();
379    ///let str2 = format!("{}{}{}","\u{1b}[49;39m","hello world","\u{1b}[0m");
380    ///assert_eq!(str1.coloured_string,str2);
381    ///```
382    pub fn none(&mut self){
383        self.text_color = TextColours::NaN; 
384        self.refresh();
385    }
386    ///This functions takes self and adds the bold style to the string
387    ///
388    ///
389    ///```
390    ///use ansi_colors::*;
391    ///let mut str1 = ColouredStr::new("hello world");
392    ///str1.bold();
393    ///let str2 = format!("{}{}{}","\u{1b}[1;49;97m","hello world","\u{1b}[0m");
394    ///assert_eq!(str1.coloured_string,str2);
395    ///```
396    pub fn bold(&mut self)->Self{
397        let mut strrr = (*self).clone();
398        self.styles.push(Styles::Bold); 
399        strrr.styles.push(Styles::Bold); 
400        self.refresh();
401        strrr.refresh();
402        strrr
403    }
404    ///This functions takes self and adds the dim style to the string
405    ///
406    ///
407    ///```
408    ///use ansi_colors::*;
409    ///let mut str1 = ColouredStr::new("hello world");
410    ///str1.dim();
411    ///let str2 = format!("{}{}{}","\u{1b}[2;49;97m","hello world","\u{1b}[0m");
412    ///assert_eq!(str1.coloured_string,str2);
413    ///```
414    pub fn dim(&mut self){
415        self.styles.push(Styles::Dim); 
416        self.refresh();
417    }
418    ///This functions takes self and adds the underline style to the string
419    ///
420    ///
421    ///```
422    ///use ansi_colors::*;
423    ///let mut str1 = ColouredStr::new("hello world");
424    ///str1.underline();
425    ///let str2 = format!("{}{}{}","\u{1b}[4;49;97m","hello world","\u{1b}[0m");
426    ///assert_eq!(str1.coloured_string,str2);
427    ///```
428    pub fn underline(&mut self)->Self{
429        let mut strrr = self.clone();
430        self.styles.push(Styles::Underline); 
431        strrr.styles.push(Styles::Bold); 
432        self.refresh();
433        strrr.refresh();
434        strrr
435    }
436    ///This functions takes self and adds the blinking style to the string
437    ///
438    ///
439    ///```
440    ///use ansi_colors::*;
441    ///let mut str1 = ColouredStr::new("hello world");
442    ///str1.blink();
443    ///let str2 = format!("{}{}{}","\u{1b}[5;49;97m","hello world","\u{1b}[0m");
444    ///assert_eq!(str1.coloured_string,str2);
445    ///```
446    pub fn blink(&mut self){
447        self.styles.push(Styles::Blink); 
448        self.refresh();
449    }
450    ///This functions takes self and adds the reverse style to the string
451    ///
452    ///
453    ///```
454    ///use ansi_colors::*;
455    ///let mut str1 = ColouredStr::new("hello world");
456    ///str1.reverse();
457    ///let str2 = format!("{}{}{}","\u{1b}[7;49;97m","hello world","\u{1b}[0m");
458    ///assert_eq!(str1.coloured_string,str2);
459    ///```
460    pub fn reverse(&mut self){
461        self.styles.push(Styles::Reverse); 
462        self.refresh();
463    }
464    ///This functions takes self and adds the hidden(   ) style to the string
465    ///
466    ///
467    ///```
468    ///use ansi_colors::*;
469    ///let mut str1 = ColouredStr::new("hello world");
470    ///str1.hidden();
471    ///let str2 = format!("{}{}{}","\u{1b}[8;49;97m","hello world","\u{1b}[0m");
472    ///assert_eq!(str1.coloured_string,str2);
473    ///```
474    pub fn hidden(&mut self){
475        self.styles.push(Styles::Hidden); 
476        self.refresh();
477    }
478    ///This functions takes self and changes the background to be black 
479    ///
480    ///
481    ///```
482    ///use ansi_colors::*;
483    ///let mut str1 = ColouredStr::new("hello world");
484    ///str1.white();
485    ///str1.back_black();
486    ///let str2 = format!("{}{}{}","\u{1b}[40;97m","hello world","\u{1b}[0m");
487    ///assert_eq!(str1.coloured_string,str2);
488    ///```
489    pub fn back_black(&mut self){
490        self.background_color = BackColours::Black;
491        self.refresh();
492    }
493    ///This functions takes self and changes the background to be red 
494    ///
495    ///
496    ///```
497    ///use ansi_colors::*;
498    ///let mut str1 = ColouredStr::new("hello world");
499    ///str1.blue();
500    ///str1.back_red();
501    ///let str2 = format!("{}{}{}","\u{1b}[41;34m","hello world","\u{1b}[0m");
502    ///assert_eq!(str1.coloured_string,str2);
503    ///```
504    pub fn back_red(&mut self){
505        self.background_color = BackColours::Red;
506        self.refresh();
507    }
508    ///This functions takes self and changes the background to be blue 
509    ///
510    ///
511    ///```
512    ///use ansi_colors::*;
513    ///let mut str1 = ColouredStr::new("hello world");
514    ///str1.red();
515    ///str1.back_blue();
516    ///let str2 = format!("{}{}{}","\u{1b}[44;31m","hello world","\u{1b}[0m");
517    ///assert_eq!(str1.coloured_string,str2);
518    ///```
519    pub fn back_blue(&mut self){
520        self.background_color = BackColours::Blue;
521        self.refresh();
522    }
523    ///This functions takes self and changes the background to be green 
524    ///
525    ///
526    ///```
527    ///use ansi_colors::*;
528    ///let mut str1 = ColouredStr::new("hello world");
529    ///str1.red();
530    ///str1.back_green();
531    ///let str2 = format!("{}{}{}","\u{1b}[42;31m","hello world","\u{1b}[0m");
532    ///assert_eq!(str1.coloured_string,str2);
533    ///```
534    pub fn back_green(&mut self){
535        self.background_color = BackColours::Green;
536        self.refresh();
537    }
538    ///This functions takes self and changes the background to be yellow
539    ///
540    ///
541    ///```
542    ///use ansi_colors::*;
543    ///let mut str1 = ColouredStr::new("hello world");
544    ///str1.magenta();
545    ///str1.back_yellow();
546    ///let str2 = format!("{}{}{}","\u{1b}[43;35m","hello world","\u{1b}[0m");
547    ///assert_eq!(str1.coloured_string,str2);
548    ///```
549    pub fn back_yellow(&mut self){
550        self.background_color = BackColours::Yellow;
551        self.refresh();
552    }
553    ///This functions takes self and changes the background to be magenta
554    ///
555    ///
556    ///```
557    ///use ansi_colors::*;
558    ///let mut str1 = ColouredStr::new("hello world");
559    ///str1.black();
560    ///str1.back_magenta();
561    ///let str2 = format!("{}{}{}","\u{1b}[45;30m","hello world","\u{1b}[0m");
562    ///assert_eq!(str1.coloured_string,str2);
563    ///```
564    pub fn back_magenta(&mut self){
565        self.background_color = BackColours::Magenta;
566        self.refresh();
567    }
568    ///This functions takes self and changes the background to be cyan  
569    ///
570    ///
571    ///```
572    ///use ansi_colors::*;
573    ///let mut str1 = ColouredStr::new("hello world");
574    ///str1.red();
575    ///str1.back_cyan();
576    ///let str2 = format!("{}{}{}","\u{1b}[46;31m","hello world","\u{1b}[0m");
577    ///assert_eq!(str1.coloured_string,str2);
578    ///```
579    pub fn back_cyan(&mut self){
580        self.background_color = BackColours::Cyan;
581        self.refresh();
582    }
583    ///This functions takes self and changes the background to be gray  
584    ///
585    ///
586    ///```
587    ///use ansi_colors::*;
588    ///let mut str1 = ColouredStr::new("hello world");
589    ///str1.yellow();
590    ///str1.back_gray();
591    ///let str2 = format!("{}{}{}","\u{1b}[47;33m","hello world","\u{1b}[0m");
592    ///assert_eq!(str1.coloured_string,str2);
593    ///```
594    pub fn back_gray(&mut self){
595        self.background_color = BackColours::Gray;
596        self.refresh();
597    }
598    ///This functions takes self and changes the background to be dark gray
599    ///
600    ///
601    ///```
602    ///use ansi_colors::*;
603    ///let mut str1 = ColouredStr::new("hello world");
604    ///str1.white();
605    ///str1.back_dark_gray();
606    ///let str2 = format!("{}{}{}","\u{1b}[100;97m","hello world","\u{1b}[0m");
607    ///assert_eq!(str1.coloured_string,str2);
608    ///```
609    pub fn back_dark_gray(&mut self){
610        self.background_color = BackColours::DarkGray;
611        self.refresh();
612    }
613    ///This functions takes self and changes the background to be light red
614    ///
615    ///
616    ///```
617    ///use ansi_colors::*;
618    ///let mut str1 = ColouredStr::new("hello world");
619    ///str1.black();
620    ///str1.back_light_red();
621    ///let str2 = format!("{}{}{}","\u{1b}[101;30m","hello world","\u{1b}[0m");
622    ///assert_eq!(str1.coloured_string,str2);
623    ///```
624    pub fn back_light_red(&mut self){
625        self.background_color = BackColours::LightRed;
626        self.refresh();
627    }
628    ///This functions takes self and changes the background to be light green 
629    ///
630    ///
631    ///```
632    ///use ansi_colors::*;
633    ///let mut str1 = ColouredStr::new("hello world");
634    ///str1.red();
635    ///str1.back_light_green();
636    ///let str2 = format!("{}{}{}","\u{1b}[102;31m","hello world","\u{1b}[0m");
637    ///assert_eq!(str1.coloured_string,str2);
638    ///```
639    pub fn back_light_green(&mut self){
640        self.background_color = BackColours::LightGreen;
641        self.refresh();
642    }
643    ///This functions takes self and changes the background to be light yellow
644    ///
645    ///
646    ///```
647    ///use ansi_colors::*;
648    ///let mut str1 = ColouredStr::new("hello world");
649    ///str1.blue();
650    ///str1.back_light_yellow();
651    ///let str2 = format!("{}{}{}","\u{1b}[103;34m","hello world","\u{1b}[0m");
652    ///assert_eq!(str1.coloured_string,str2);
653    ///```
654    pub fn back_light_yellow(&mut self){
655        self.background_color = BackColours::LightYellow;
656        self.refresh();
657    }
658    ///This functions takes self and changes the background to be light blue 
659    ///
660    ///
661    ///```
662    ///use ansi_colors::*;
663    ///let mut str1 = ColouredStr::new("hello world");
664    ///str1.black();
665    ///str1.back_light_blue();
666    ///let str2 = format!("{}{}{}","\u{1b}[104;30m","hello world","\u{1b}[0m");
667    ///assert_eq!(str1.coloured_string,str2);
668    ///```
669    pub fn back_light_blue(&mut self){
670        self.background_color = BackColours::LightBlue;
671        self.refresh();
672    }
673    ///This functions takes self and changes the background to be pink        
674    ///
675    ///
676    ///```
677    ///use ansi_colors::*;
678    ///let mut str1 = ColouredStr::new("hello world");
679    ///str1.black();
680    ///str1.back_pink();
681    ///let str2 = format!("{}{}{}","\u{1b}[105;30m","hello world","\u{1b}[0m");
682    ///assert_eq!(str1.coloured_string,str2);
683    ///```
684    pub fn back_pink(&mut self){
685        self.background_color = BackColours::Pink;
686        self.refresh();
687    }
688    ///This functions takes self and changes the background to be light cyan 
689    ///
690    ///
691    ///```
692    ///use ansi_colors::*;
693    ///let mut str1 = ColouredStr::new("hello world");
694    ///str1.red();
695    ///str1.back_light_green();
696    ///let str2 = format!("{}{}{}","\u{1b}[102;31m","hello world","\u{1b}[0m");
697    ///assert_eq!(str1.coloured_string,str2);
698    ///```
699    pub fn back_light_cyan(&mut self){
700        self.background_color = BackColours::LightCyan;
701        self.refresh();
702    }
703    ///This functions takes self and changes the background to be white 
704    ///
705    ///
706    ///```
707    ///use ansi_colors::*;
708    ///let mut str1 = ColouredStr::new("hello world");
709    ///str1.black();
710    ///str1.back_white();
711    ///let str2 = format!("{}{}{}","\u{1b}[107;30m","hello world","\u{1b}[0m");
712    ///assert_eq!(str1.coloured_string,str2);
713    ///```
714    pub fn back_white(&mut self){
715        self.background_color = BackColours::White;
716        self.refresh();
717    }
718    ///This functions takes self and changes the background to be none 
719    ///
720    ///
721    ///```
722    ///use ansi_colors::*;
723    ///let mut str1 = ColouredStr::new("hello world");
724    ///str1.red();
725    ///str1.back_none();
726    ///let str2 = format!("{}{}{}","\u{1b}[49;31m","hello world","\u{1b}[0m");
727    ///assert_eq!(str1.coloured_string,str2);
728    ///```
729    pub fn back_none(&mut self){
730        self.background_color = BackColours::NaN;
731        self.refresh();
732    }
733    ///This functions takes self and adds the reset all operation to the reset
734    ///
735    ///
736    ///```
737    ///use ansi_colors::*;
738    ///let mut str1 = ColouredStr::new("hello world");
739    ///str1.blink();
740    ///str1.reset_all();
741    ///let str2 = format!("{}{}{}","\u{1b}[5;49;97m","hello world","\u{1b}[0m");
742    ///assert_eq!(str1.coloured_string,str2);
743    ///```
744    pub fn reset_all(&mut self){
745        self.resets.push(Reset::All); 
746        self.refresh();
747    }
748    ///This functions takes self and adds the reset bold operation to the reset
749    ///it means it resets only the bold style, not any other active styles or colors.
750    ///
751    ///```
752    ///use ansi_colors::*;
753    ///let mut str1 = ColouredStr::new("hello world");
754    ///str1.bold();
755    ///str1.red();
756    ///str1.reset_bold();
757    ///let str2 = format!("{}{}{}","\u{1b}[1;49;31m","hello world","\u{1b}[21m");
758    ///assert_eq!(str1.coloured_string,str2);
759    ///```
760    pub fn reset_bold(&mut self){
761        self.resets.push(Reset::Bold);
762        self.refresh();
763    }
764    ///This functions takes self and adds the reset dim operation to the reset
765    ///it means it resets only the dim style, not any other active styles or colors.
766    ///
767    ///```
768    ///use ansi_colors::*;
769    ///let mut str1 = ColouredStr::new("hello world");
770    ///str1.dim();
771    ///str1.bold();
772    ///str1.reset_dim();
773    ///let str2 = format!("{}{}{}","\u{1b}[2;1;49;97m","hello world","\u{1b}[22m");
774    ///assert_eq!(str1.coloured_string,str2);
775    ///```
776    pub fn reset_dim(&mut self){
777        self.resets.push(Reset::Dim);
778        self.refresh();
779    }
780    ///This functions takes self and adds the reset underline operation to the reset
781    ///it means it resets only the underline style, not any other active styles or colors.
782    ///
783    ///```
784    ///use ansi_colors::*;
785    ///let mut str1 = ColouredStr::new("hello world");
786    ///str1.underline();
787    ///str1.back_green();
788    ///str1.reset_underline();
789    ///let str2 = format!("{}{}{}","\u{1b}[4;42;97m","hello world","\u{1b}[24m");
790    ///assert_eq!(str1.coloured_string,str2);
791    ///```
792    pub fn reset_underline(&mut self){
793        self.resets.push(Reset::Underline);
794        self.refresh();
795    }
796    ///This functions takes self and adds the reset blink operation to the reset
797    ///it means it resets only the blink style, not any other active styles or colors.
798    ///
799    ///```
800    ///use ansi_colors::*;
801    ///let mut str1 = ColouredStr::new("hello world");
802    ///str1.blink();
803    ///str1.red();
804    ///str1.reset_blink();
805    ///let str2 = format!("{}{}{}","\u{1b}[5;49;31m","hello world","\u{1b}[25m");
806    ///assert_eq!(str1.coloured_string,str2);
807    ///```
808    pub fn reset_blink(&mut self){
809        self.resets.push(Reset::Blink);
810        self.refresh();
811    }
812    ///This functions takes self and adds the reset reverse operation to the reset
813    ///it means it resets only the reverse style, not any other active styles or colors.
814    ///
815    ///```
816    ///use ansi_colors::*;
817    ///let mut str1 = ColouredStr::new("hello world");
818    ///str1.reverse();
819    ///str1.back_red();
820    ///str1.reset_reverse();
821    ///let str2 = format!("{}{}{}","\u{1b}[7;41;97m","hello world","\u{1b}[27m");
822    ///assert_eq!(str1.coloured_string,str2);
823    ///```
824    pub fn reset_reverse(&mut self){
825        self.resets.push(Reset::Reverse);
826        self.refresh();
827    }
828    ///This functions takes self and adds the reset hidden operation to the reset
829    ///it means it resets only the hidden style, not any other active styles or colors.
830    ///
831    ///```
832    ///use ansi_colors::*;
833    ///let mut str1 = ColouredStr::new("hello world");
834    ///str1.hidden();
835    ///str1.back_black();
836    ///str1.reset_hidden();
837    ///let str2 = format!("{}{}{}","\u{1b}[8;40;97m","hello world","\u{1b}[28m");
838    ///assert_eq!(str1.coloured_string,str2);
839    ///```
840    pub fn reset_hidden(&mut self){
841        self.resets.push(Reset::Hidden);
842        self.refresh();
843    }
844}