pub trait ToStyle: Sized {
Show 13 methods
// Required method
fn to_style(self) -> Style;
// Provided methods
fn to_mapped_style<F>(self, func: F) -> Style
where F: FnOnce(&mut Style) { ... }
fn fg(self, c: Color) -> Style { ... }
fn bg(self, c: Color) -> Style { ... }
fn bold(self) -> Style { ... }
fn dim(self) -> Style { ... }
fn underline(self) -> Style { ... }
fn not_underline(self) -> Style { ... }
fn blink(self) -> Style { ... }
fn reverse(self) -> Style { ... }
fn secure(self) -> Style { ... }
fn paint<T>(&self, obj: T) -> Painted<T>
where Self: Clone { ... }
fn with<F, R>(&self, f: F) -> R
where F: FnOnce() -> R,
Self: Clone { ... }
}Expand description
Everything that can be seen as part of a style. This is the core of this crate. All functions (“style modifier”) consume self and return a modified version of the style.
Required Methods§
Provided Methods§
Sourcefn to_mapped_style<F>(self, func: F) -> Style
fn to_mapped_style<F>(self, func: F) -> Style
Convenience method for modifying the style before it’s returned.
Sourcefn fg(self, c: Color) -> Style
fn fg(self, c: Color) -> Style
Sets the foreground (text) color.
Examples found in repository?
53fn doc_examples() {
54 // --- Doc example 1
55 println!("{} or {} or {}",
56 Red.paint("Red"),
57 Bold.paint("Bold"),
58 Red.bold().paint("Both!"));
59
60 // --- Doc example 2
61 let x = 5;
62
63 // These two are equivalent
64 println!("{} | {}", x, Plain.paint(x));
65
66 // These two are equivalent, too
67 println!("{} | {}", Red.paint(x), Plain.fg(Red).paint(x));
68
69 // --- Doc example 3
70 let non_copy = "cake".to_string(); // String is *not* Copy
71 let copy = 27; // usize/isize *is* Copy
72
73 println!("{}", Plain.paint(&non_copy));
74 println!("{}", Plain.paint(©));
75 // non_copy is still usable here...
76 // copy is still usable here...
77
78 println!("{}", Plain.paint(non_copy));
79 println!("{}", Plain.paint(copy));
80 // non_copy was moved into paint, so it not usable anymore...
81 // copy is still usable here...
82}Sourcefn bg(self, c: Color) -> Style
fn bg(self, c: Color) -> Style
Sets the background color.
Examples found in repository?
29fn simple_examples() {
30 println!("{} | {} | {} | {} | {}",
31 Red.bg(Green).bold().paint("Red-Green-Bold"),
32 Blue.paint("Blue"),
33 Blue.bold().paint("BlueBold"),
34 Blue.bg(Magenta).paint("BlueMagentaBG"),
35 Plain.underline().paint("Underline"));
36}
37
38fn with_example() {
39 Red.with(|| {
40 print!("JustRed");
41 Bold.with(|| {
42 print!(" BoldRed {} BoldRed ", Underline.paint("Underline"));
43 });
44 print!("JustRed ");
45
46 print!("{}", Blue.paint("Blue (overwrite) "));
47 Green.with(|| {
48 println!("Green (overwrite)");
49 });
50 });
51}
52
53fn doc_examples() {
54 // --- Doc example 1
55 println!("{} or {} or {}",
56 Red.paint("Red"),
57 Bold.paint("Bold"),
58 Red.bold().paint("Both!"));
59
60 // --- Doc example 2
61 let x = 5;
62
63 // These two are equivalent
64 println!("{} | {}", x, Plain.paint(x));
65
66 // These two are equivalent, too
67 println!("{} | {}", Red.paint(x), Plain.fg(Red).paint(x));
68
69 // --- Doc example 3
70 let non_copy = "cake".to_string(); // String is *not* Copy
71 let copy = 27; // usize/isize *is* Copy
72
73 println!("{}", Plain.paint(&non_copy));
74 println!("{}", Plain.paint(©));
75 // non_copy is still usable here...
76 // copy is still usable here...
77
78 println!("{}", Plain.paint(non_copy));
79 println!("{}", Plain.paint(copy));
80 // non_copy was moved into paint, so it not usable anymore...
81 // copy is still usable here...
82}
83
84fn all_styles(colors: &[Color]) {
85 // Normal test
86 for c in colors { print!("{:?} ", c.paint(c)); }
87 println!(" (fg)");
88 for c in colors { print!("{:?} ", Plain.bg(*c).paint(c)); }
89 println!(" (bg)");
90
91 // Bold text
92 for c in colors { print!("{:?} ", c.bold().paint(c)); }
93 println!(" (bold fg)");
94 for c in colors { print!("{:?} ", Bold.bg(*c).paint(c)); }
95 println!(" (bold bg)");
96
97 // Dim text
98 for c in colors { print!("{:?} ", c.dim().paint(c)); }
99 println!(" (dim fg)");
100 for c in colors { print!("{:?} ", Dim.bg(*c).paint(c)); }
101 println!(" (dim bg)");
102
103 // Underlined text
104 for c in colors { print!("{:?} ", c.underline().paint(c)); }
105 println!(" (underline fg)");
106 for c in colors { print!("{:?} ", Underline.bg(*c).paint(c)); }
107 println!(" (underline bg)");
108
109 // Blinking text
110 for c in colors { print!("{:?} ", c.blink().paint(c)); }
111 println!(" (blink fg)");
112 for c in colors { print!("{:?} ", Blink.bg(*c).paint(c)); }
113 println!(" (blink bg)");
114
115 // Reverse text
116 for c in colors { print!("{:?} ", c.reverse().paint(c)); }
117 println!(" (reverse fg)");
118 for c in colors { print!("{:?} ", Reverse.bg(*c).paint(c)); }
119 println!(" (reverse bg)");
120
121 // Secure text
122 for c in colors { print!("{:?} ", c.secure().paint(c)); }
123 println!(" (secure fg)");
124 for c in colors { print!("{:?} ", Secure.bg(*c).paint(c)); }
125 println!(" (secure bg)");
126
127}More examples
7fn main() {
8 // print 16 colors each line
9 for line in 0..16 {
10 // foreground
11 print!("FG: ");
12 for c in (0..16).map(|i| 16*line + i) {
13 print!("{: <2x} ", Custom(c).paint(c));
14 }
15 println!("");
16
17 // background
18 print!("BG: ");
19 for c in (0..16).map(|i| 16*line + i) {
20 print!("{: <2x} ", Plain.bg(Custom(c)).paint(c));
21 }
22 println!("");
23 }
24}Sourcefn bold(self) -> Style
fn bold(self) -> Style
Makes the text bold.
Examples found in repository?
29fn simple_examples() {
30 println!("{} | {} | {} | {} | {}",
31 Red.bg(Green).bold().paint("Red-Green-Bold"),
32 Blue.paint("Blue"),
33 Blue.bold().paint("BlueBold"),
34 Blue.bg(Magenta).paint("BlueMagentaBG"),
35 Plain.underline().paint("Underline"));
36}
37
38fn with_example() {
39 Red.with(|| {
40 print!("JustRed");
41 Bold.with(|| {
42 print!(" BoldRed {} BoldRed ", Underline.paint("Underline"));
43 });
44 print!("JustRed ");
45
46 print!("{}", Blue.paint("Blue (overwrite) "));
47 Green.with(|| {
48 println!("Green (overwrite)");
49 });
50 });
51}
52
53fn doc_examples() {
54 // --- Doc example 1
55 println!("{} or {} or {}",
56 Red.paint("Red"),
57 Bold.paint("Bold"),
58 Red.bold().paint("Both!"));
59
60 // --- Doc example 2
61 let x = 5;
62
63 // These two are equivalent
64 println!("{} | {}", x, Plain.paint(x));
65
66 // These two are equivalent, too
67 println!("{} | {}", Red.paint(x), Plain.fg(Red).paint(x));
68
69 // --- Doc example 3
70 let non_copy = "cake".to_string(); // String is *not* Copy
71 let copy = 27; // usize/isize *is* Copy
72
73 println!("{}", Plain.paint(&non_copy));
74 println!("{}", Plain.paint(©));
75 // non_copy is still usable here...
76 // copy is still usable here...
77
78 println!("{}", Plain.paint(non_copy));
79 println!("{}", Plain.paint(copy));
80 // non_copy was moved into paint, so it not usable anymore...
81 // copy is still usable here...
82}
83
84fn all_styles(colors: &[Color]) {
85 // Normal test
86 for c in colors { print!("{:?} ", c.paint(c)); }
87 println!(" (fg)");
88 for c in colors { print!("{:?} ", Plain.bg(*c).paint(c)); }
89 println!(" (bg)");
90
91 // Bold text
92 for c in colors { print!("{:?} ", c.bold().paint(c)); }
93 println!(" (bold fg)");
94 for c in colors { print!("{:?} ", Bold.bg(*c).paint(c)); }
95 println!(" (bold bg)");
96
97 // Dim text
98 for c in colors { print!("{:?} ", c.dim().paint(c)); }
99 println!(" (dim fg)");
100 for c in colors { print!("{:?} ", Dim.bg(*c).paint(c)); }
101 println!(" (dim bg)");
102
103 // Underlined text
104 for c in colors { print!("{:?} ", c.underline().paint(c)); }
105 println!(" (underline fg)");
106 for c in colors { print!("{:?} ", Underline.bg(*c).paint(c)); }
107 println!(" (underline bg)");
108
109 // Blinking text
110 for c in colors { print!("{:?} ", c.blink().paint(c)); }
111 println!(" (blink fg)");
112 for c in colors { print!("{:?} ", Blink.bg(*c).paint(c)); }
113 println!(" (blink bg)");
114
115 // Reverse text
116 for c in colors { print!("{:?} ", c.reverse().paint(c)); }
117 println!(" (reverse fg)");
118 for c in colors { print!("{:?} ", Reverse.bg(*c).paint(c)); }
119 println!(" (reverse bg)");
120
121 // Secure text
122 for c in colors { print!("{:?} ", c.secure().paint(c)); }
123 println!(" (secure fg)");
124 for c in colors { print!("{:?} ", Secure.bg(*c).paint(c)); }
125 println!(" (secure bg)");
126
127}Sourcefn dim(self) -> Style
fn dim(self) -> Style
Dim mode.
Examples found in repository?
84fn all_styles(colors: &[Color]) {
85 // Normal test
86 for c in colors { print!("{:?} ", c.paint(c)); }
87 println!(" (fg)");
88 for c in colors { print!("{:?} ", Plain.bg(*c).paint(c)); }
89 println!(" (bg)");
90
91 // Bold text
92 for c in colors { print!("{:?} ", c.bold().paint(c)); }
93 println!(" (bold fg)");
94 for c in colors { print!("{:?} ", Bold.bg(*c).paint(c)); }
95 println!(" (bold bg)");
96
97 // Dim text
98 for c in colors { print!("{:?} ", c.dim().paint(c)); }
99 println!(" (dim fg)");
100 for c in colors { print!("{:?} ", Dim.bg(*c).paint(c)); }
101 println!(" (dim bg)");
102
103 // Underlined text
104 for c in colors { print!("{:?} ", c.underline().paint(c)); }
105 println!(" (underline fg)");
106 for c in colors { print!("{:?} ", Underline.bg(*c).paint(c)); }
107 println!(" (underline bg)");
108
109 // Blinking text
110 for c in colors { print!("{:?} ", c.blink().paint(c)); }
111 println!(" (blink fg)");
112 for c in colors { print!("{:?} ", Blink.bg(*c).paint(c)); }
113 println!(" (blink bg)");
114
115 // Reverse text
116 for c in colors { print!("{:?} ", c.reverse().paint(c)); }
117 println!(" (reverse fg)");
118 for c in colors { print!("{:?} ", Reverse.bg(*c).paint(c)); }
119 println!(" (reverse bg)");
120
121 // Secure text
122 for c in colors { print!("{:?} ", c.secure().paint(c)); }
123 println!(" (secure fg)");
124 for c in colors { print!("{:?} ", Secure.bg(*c).paint(c)); }
125 println!(" (secure bg)");
126
127}Sourcefn underline(self) -> Style
fn underline(self) -> Style
Underlines the text.
Examples found in repository?
29fn simple_examples() {
30 println!("{} | {} | {} | {} | {}",
31 Red.bg(Green).bold().paint("Red-Green-Bold"),
32 Blue.paint("Blue"),
33 Blue.bold().paint("BlueBold"),
34 Blue.bg(Magenta).paint("BlueMagentaBG"),
35 Plain.underline().paint("Underline"));
36}
37
38fn with_example() {
39 Red.with(|| {
40 print!("JustRed");
41 Bold.with(|| {
42 print!(" BoldRed {} BoldRed ", Underline.paint("Underline"));
43 });
44 print!("JustRed ");
45
46 print!("{}", Blue.paint("Blue (overwrite) "));
47 Green.with(|| {
48 println!("Green (overwrite)");
49 });
50 });
51}
52
53fn doc_examples() {
54 // --- Doc example 1
55 println!("{} or {} or {}",
56 Red.paint("Red"),
57 Bold.paint("Bold"),
58 Red.bold().paint("Both!"));
59
60 // --- Doc example 2
61 let x = 5;
62
63 // These two are equivalent
64 println!("{} | {}", x, Plain.paint(x));
65
66 // These two are equivalent, too
67 println!("{} | {}", Red.paint(x), Plain.fg(Red).paint(x));
68
69 // --- Doc example 3
70 let non_copy = "cake".to_string(); // String is *not* Copy
71 let copy = 27; // usize/isize *is* Copy
72
73 println!("{}", Plain.paint(&non_copy));
74 println!("{}", Plain.paint(©));
75 // non_copy is still usable here...
76 // copy is still usable here...
77
78 println!("{}", Plain.paint(non_copy));
79 println!("{}", Plain.paint(copy));
80 // non_copy was moved into paint, so it not usable anymore...
81 // copy is still usable here...
82}
83
84fn all_styles(colors: &[Color]) {
85 // Normal test
86 for c in colors { print!("{:?} ", c.paint(c)); }
87 println!(" (fg)");
88 for c in colors { print!("{:?} ", Plain.bg(*c).paint(c)); }
89 println!(" (bg)");
90
91 // Bold text
92 for c in colors { print!("{:?} ", c.bold().paint(c)); }
93 println!(" (bold fg)");
94 for c in colors { print!("{:?} ", Bold.bg(*c).paint(c)); }
95 println!(" (bold bg)");
96
97 // Dim text
98 for c in colors { print!("{:?} ", c.dim().paint(c)); }
99 println!(" (dim fg)");
100 for c in colors { print!("{:?} ", Dim.bg(*c).paint(c)); }
101 println!(" (dim bg)");
102
103 // Underlined text
104 for c in colors { print!("{:?} ", c.underline().paint(c)); }
105 println!(" (underline fg)");
106 for c in colors { print!("{:?} ", Underline.bg(*c).paint(c)); }
107 println!(" (underline bg)");
108
109 // Blinking text
110 for c in colors { print!("{:?} ", c.blink().paint(c)); }
111 println!(" (blink fg)");
112 for c in colors { print!("{:?} ", Blink.bg(*c).paint(c)); }
113 println!(" (blink bg)");
114
115 // Reverse text
116 for c in colors { print!("{:?} ", c.reverse().paint(c)); }
117 println!(" (reverse fg)");
118 for c in colors { print!("{:?} ", Reverse.bg(*c).paint(c)); }
119 println!(" (reverse bg)");
120
121 // Secure text
122 for c in colors { print!("{:?} ", c.secure().paint(c)); }
123 println!(" (secure fg)");
124 for c in colors { print!("{:?} ", Secure.bg(*c).paint(c)); }
125 println!(" (secure bg)");
126
127}Sourcefn not_underline(self) -> Style
fn not_underline(self) -> Style
Removes underline-attribute.
Sourcefn blink(self) -> Style
fn blink(self) -> Style
Underlines the text.
Examples found in repository?
84fn all_styles(colors: &[Color]) {
85 // Normal test
86 for c in colors { print!("{:?} ", c.paint(c)); }
87 println!(" (fg)");
88 for c in colors { print!("{:?} ", Plain.bg(*c).paint(c)); }
89 println!(" (bg)");
90
91 // Bold text
92 for c in colors { print!("{:?} ", c.bold().paint(c)); }
93 println!(" (bold fg)");
94 for c in colors { print!("{:?} ", Bold.bg(*c).paint(c)); }
95 println!(" (bold bg)");
96
97 // Dim text
98 for c in colors { print!("{:?} ", c.dim().paint(c)); }
99 println!(" (dim fg)");
100 for c in colors { print!("{:?} ", Dim.bg(*c).paint(c)); }
101 println!(" (dim bg)");
102
103 // Underlined text
104 for c in colors { print!("{:?} ", c.underline().paint(c)); }
105 println!(" (underline fg)");
106 for c in colors { print!("{:?} ", Underline.bg(*c).paint(c)); }
107 println!(" (underline bg)");
108
109 // Blinking text
110 for c in colors { print!("{:?} ", c.blink().paint(c)); }
111 println!(" (blink fg)");
112 for c in colors { print!("{:?} ", Blink.bg(*c).paint(c)); }
113 println!(" (blink bg)");
114
115 // Reverse text
116 for c in colors { print!("{:?} ", c.reverse().paint(c)); }
117 println!(" (reverse fg)");
118 for c in colors { print!("{:?} ", Reverse.bg(*c).paint(c)); }
119 println!(" (reverse bg)");
120
121 // Secure text
122 for c in colors { print!("{:?} ", c.secure().paint(c)); }
123 println!(" (secure fg)");
124 for c in colors { print!("{:?} ", Secure.bg(*c).paint(c)); }
125 println!(" (secure bg)");
126
127}Sourcefn reverse(self) -> Style
fn reverse(self) -> Style
Underlines the text.
Examples found in repository?
84fn all_styles(colors: &[Color]) {
85 // Normal test
86 for c in colors { print!("{:?} ", c.paint(c)); }
87 println!(" (fg)");
88 for c in colors { print!("{:?} ", Plain.bg(*c).paint(c)); }
89 println!(" (bg)");
90
91 // Bold text
92 for c in colors { print!("{:?} ", c.bold().paint(c)); }
93 println!(" (bold fg)");
94 for c in colors { print!("{:?} ", Bold.bg(*c).paint(c)); }
95 println!(" (bold bg)");
96
97 // Dim text
98 for c in colors { print!("{:?} ", c.dim().paint(c)); }
99 println!(" (dim fg)");
100 for c in colors { print!("{:?} ", Dim.bg(*c).paint(c)); }
101 println!(" (dim bg)");
102
103 // Underlined text
104 for c in colors { print!("{:?} ", c.underline().paint(c)); }
105 println!(" (underline fg)");
106 for c in colors { print!("{:?} ", Underline.bg(*c).paint(c)); }
107 println!(" (underline bg)");
108
109 // Blinking text
110 for c in colors { print!("{:?} ", c.blink().paint(c)); }
111 println!(" (blink fg)");
112 for c in colors { print!("{:?} ", Blink.bg(*c).paint(c)); }
113 println!(" (blink bg)");
114
115 // Reverse text
116 for c in colors { print!("{:?} ", c.reverse().paint(c)); }
117 println!(" (reverse fg)");
118 for c in colors { print!("{:?} ", Reverse.bg(*c).paint(c)); }
119 println!(" (reverse bg)");
120
121 // Secure text
122 for c in colors { print!("{:?} ", c.secure().paint(c)); }
123 println!(" (secure fg)");
124 for c in colors { print!("{:?} ", Secure.bg(*c).paint(c)); }
125 println!(" (secure bg)");
126
127}Sourcefn secure(self) -> Style
fn secure(self) -> Style
Secure mode.
Examples found in repository?
84fn all_styles(colors: &[Color]) {
85 // Normal test
86 for c in colors { print!("{:?} ", c.paint(c)); }
87 println!(" (fg)");
88 for c in colors { print!("{:?} ", Plain.bg(*c).paint(c)); }
89 println!(" (bg)");
90
91 // Bold text
92 for c in colors { print!("{:?} ", c.bold().paint(c)); }
93 println!(" (bold fg)");
94 for c in colors { print!("{:?} ", Bold.bg(*c).paint(c)); }
95 println!(" (bold bg)");
96
97 // Dim text
98 for c in colors { print!("{:?} ", c.dim().paint(c)); }
99 println!(" (dim fg)");
100 for c in colors { print!("{:?} ", Dim.bg(*c).paint(c)); }
101 println!(" (dim bg)");
102
103 // Underlined text
104 for c in colors { print!("{:?} ", c.underline().paint(c)); }
105 println!(" (underline fg)");
106 for c in colors { print!("{:?} ", Underline.bg(*c).paint(c)); }
107 println!(" (underline bg)");
108
109 // Blinking text
110 for c in colors { print!("{:?} ", c.blink().paint(c)); }
111 println!(" (blink fg)");
112 for c in colors { print!("{:?} ", Blink.bg(*c).paint(c)); }
113 println!(" (blink bg)");
114
115 // Reverse text
116 for c in colors { print!("{:?} ", c.reverse().paint(c)); }
117 println!(" (reverse fg)");
118 for c in colors { print!("{:?} ", Reverse.bg(*c).paint(c)); }
119 println!(" (reverse bg)");
120
121 // Secure text
122 for c in colors { print!("{:?} ", c.secure().paint(c)); }
123 println!(" (secure fg)");
124 for c in colors { print!("{:?} ", Secure.bg(*c).paint(c)); }
125 println!(" (secure bg)");
126
127}Sourcefn paint<T>(&self, obj: T) -> Painted<T>where
Self: Clone,
fn paint<T>(&self, obj: T) -> Painted<T>where
Self: Clone,
Wraps the style specified in self and something of arbitrary type
into a Painted. When Painted is printed it will print the arbitrary
something with the given style.
Examples found in repository?
29fn simple_examples() {
30 println!("{} | {} | {} | {} | {}",
31 Red.bg(Green).bold().paint("Red-Green-Bold"),
32 Blue.paint("Blue"),
33 Blue.bold().paint("BlueBold"),
34 Blue.bg(Magenta).paint("BlueMagentaBG"),
35 Plain.underline().paint("Underline"));
36}
37
38fn with_example() {
39 Red.with(|| {
40 print!("JustRed");
41 Bold.with(|| {
42 print!(" BoldRed {} BoldRed ", Underline.paint("Underline"));
43 });
44 print!("JustRed ");
45
46 print!("{}", Blue.paint("Blue (overwrite) "));
47 Green.with(|| {
48 println!("Green (overwrite)");
49 });
50 });
51}
52
53fn doc_examples() {
54 // --- Doc example 1
55 println!("{} or {} or {}",
56 Red.paint("Red"),
57 Bold.paint("Bold"),
58 Red.bold().paint("Both!"));
59
60 // --- Doc example 2
61 let x = 5;
62
63 // These two are equivalent
64 println!("{} | {}", x, Plain.paint(x));
65
66 // These two are equivalent, too
67 println!("{} | {}", Red.paint(x), Plain.fg(Red).paint(x));
68
69 // --- Doc example 3
70 let non_copy = "cake".to_string(); // String is *not* Copy
71 let copy = 27; // usize/isize *is* Copy
72
73 println!("{}", Plain.paint(&non_copy));
74 println!("{}", Plain.paint(©));
75 // non_copy is still usable here...
76 // copy is still usable here...
77
78 println!("{}", Plain.paint(non_copy));
79 println!("{}", Plain.paint(copy));
80 // non_copy was moved into paint, so it not usable anymore...
81 // copy is still usable here...
82}
83
84fn all_styles(colors: &[Color]) {
85 // Normal test
86 for c in colors { print!("{:?} ", c.paint(c)); }
87 println!(" (fg)");
88 for c in colors { print!("{:?} ", Plain.bg(*c).paint(c)); }
89 println!(" (bg)");
90
91 // Bold text
92 for c in colors { print!("{:?} ", c.bold().paint(c)); }
93 println!(" (bold fg)");
94 for c in colors { print!("{:?} ", Bold.bg(*c).paint(c)); }
95 println!(" (bold bg)");
96
97 // Dim text
98 for c in colors { print!("{:?} ", c.dim().paint(c)); }
99 println!(" (dim fg)");
100 for c in colors { print!("{:?} ", Dim.bg(*c).paint(c)); }
101 println!(" (dim bg)");
102
103 // Underlined text
104 for c in colors { print!("{:?} ", c.underline().paint(c)); }
105 println!(" (underline fg)");
106 for c in colors { print!("{:?} ", Underline.bg(*c).paint(c)); }
107 println!(" (underline bg)");
108
109 // Blinking text
110 for c in colors { print!("{:?} ", c.blink().paint(c)); }
111 println!(" (blink fg)");
112 for c in colors { print!("{:?} ", Blink.bg(*c).paint(c)); }
113 println!(" (blink bg)");
114
115 // Reverse text
116 for c in colors { print!("{:?} ", c.reverse().paint(c)); }
117 println!(" (reverse fg)");
118 for c in colors { print!("{:?} ", Reverse.bg(*c).paint(c)); }
119 println!(" (reverse bg)");
120
121 // Secure text
122 for c in colors { print!("{:?} ", c.secure().paint(c)); }
123 println!(" (secure fg)");
124 for c in colors { print!("{:?} ", Secure.bg(*c).paint(c)); }
125 println!(" (secure bg)");
126
127}More examples
7fn main() {
8 // print 16 colors each line
9 for line in 0..16 {
10 // foreground
11 print!("FG: ");
12 for c in (0..16).map(|i| 16*line + i) {
13 print!("{: <2x} ", Custom(c).paint(c));
14 }
15 println!("");
16
17 // background
18 print!("BG: ");
19 for c in (0..16).map(|i| 16*line + i) {
20 print!("{: <2x} ", Plain.bg(Custom(c)).paint(c));
21 }
22 println!("");
23 }
24}Sourcefn with<F, R>(&self, f: F) -> R
fn with<F, R>(&self, f: F) -> R
Executes the given function, applying the style information before calling it and resetting after it finished.
Examples found in repository?
38fn with_example() {
39 Red.with(|| {
40 print!("JustRed");
41 Bold.with(|| {
42 print!(" BoldRed {} BoldRed ", Underline.paint("Underline"));
43 });
44 print!("JustRed ");
45
46 print!("{}", Blue.paint("Blue (overwrite) "));
47 Green.with(|| {
48 println!("Green (overwrite)");
49 });
50 });
51}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.