Trait term_painter::ToStyle
source · 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?
examples/main.rs (line 67)
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
fn doc_examples() {
// --- Doc example 1
println!("{} or {} or {}",
Red.paint("Red"),
Bold.paint("Bold"),
Red.bold().paint("Both!"));
// --- Doc example 2
let x = 5;
// These two are equivalent
println!("{} | {}", x, Plain.paint(x));
// These two are equivalent, too
println!("{} | {}", Red.paint(x), Plain.fg(Red).paint(x));
// --- Doc example 3
let non_copy = "cake".to_string(); // String is *not* Copy
let copy = 27; // usize/isize *is* Copy
println!("{}", Plain.paint(&non_copy));
println!("{}", Plain.paint(©));
// non_copy is still usable here...
// copy is still usable here...
println!("{}", Plain.paint(non_copy));
println!("{}", Plain.paint(copy));
// non_copy was moved into paint, so it not usable anymore...
// copy is still usable here...
}
sourcefn bg(self, c: Color) -> Style
fn bg(self, c: Color) -> Style
Sets the background color.
Examples found in repository?
examples/main.rs (line 31)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
fn simple_examples() {
println!("{} | {} | {} | {} | {}",
Red.bg(Green).bold().paint("Red-Green-Bold"),
Blue.paint("Blue"),
Blue.bold().paint("BlueBold"),
Blue.bg(Magenta).paint("BlueMagentaBG"),
Plain.underline().paint("Underline"));
}
fn with_example() {
Red.with(|| {
print!("JustRed");
Bold.with(|| {
print!(" BoldRed {} BoldRed ", Underline.paint("Underline"));
});
print!("JustRed ");
print!("{}", Blue.paint("Blue (overwrite) "));
Green.with(|| {
println!("Green (overwrite)");
});
});
}
fn doc_examples() {
// --- Doc example 1
println!("{} or {} or {}",
Red.paint("Red"),
Bold.paint("Bold"),
Red.bold().paint("Both!"));
// --- Doc example 2
let x = 5;
// These two are equivalent
println!("{} | {}", x, Plain.paint(x));
// These two are equivalent, too
println!("{} | {}", Red.paint(x), Plain.fg(Red).paint(x));
// --- Doc example 3
let non_copy = "cake".to_string(); // String is *not* Copy
let copy = 27; // usize/isize *is* Copy
println!("{}", Plain.paint(&non_copy));
println!("{}", Plain.paint(©));
// non_copy is still usable here...
// copy is still usable here...
println!("{}", Plain.paint(non_copy));
println!("{}", Plain.paint(copy));
// non_copy was moved into paint, so it not usable anymore...
// copy is still usable here...
}
fn all_styles(colors: &[Color]) {
// Normal test
for c in colors { print!("{:?} ", c.paint(c)); }
println!(" (fg)");
for c in colors { print!("{:?} ", Plain.bg(*c).paint(c)); }
println!(" (bg)");
// Bold text
for c in colors { print!("{:?} ", c.bold().paint(c)); }
println!(" (bold fg)");
for c in colors { print!("{:?} ", Bold.bg(*c).paint(c)); }
println!(" (bold bg)");
// Dim text
for c in colors { print!("{:?} ", c.dim().paint(c)); }
println!(" (dim fg)");
for c in colors { print!("{:?} ", Dim.bg(*c).paint(c)); }
println!(" (dim bg)");
// Underlined text
for c in colors { print!("{:?} ", c.underline().paint(c)); }
println!(" (underline fg)");
for c in colors { print!("{:?} ", Underline.bg(*c).paint(c)); }
println!(" (underline bg)");
// Blinking text
for c in colors { print!("{:?} ", c.blink().paint(c)); }
println!(" (blink fg)");
for c in colors { print!("{:?} ", Blink.bg(*c).paint(c)); }
println!(" (blink bg)");
// Reverse text
for c in colors { print!("{:?} ", c.reverse().paint(c)); }
println!(" (reverse fg)");
for c in colors { print!("{:?} ", Reverse.bg(*c).paint(c)); }
println!(" (reverse bg)");
// Secure text
for c in colors { print!("{:?} ", c.secure().paint(c)); }
println!(" (secure fg)");
for c in colors { print!("{:?} ", Secure.bg(*c).paint(c)); }
println!(" (secure bg)");
}
More examples
examples/custom.rs (line 20)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
fn main() {
// print 16 colors each line
for line in 0..16 {
// foreground
print!("FG: ");
for c in (0..16).map(|i| 16*line + i) {
print!("{: <2x} ", Custom(c).paint(c));
}
println!("");
// background
print!("BG: ");
for c in (0..16).map(|i| 16*line + i) {
print!("{: <2x} ", Plain.bg(Custom(c)).paint(c));
}
println!("");
}
}
sourcefn bold(self) -> Style
fn bold(self) -> Style
Makes the text bold.
Examples found in repository?
examples/main.rs (line 31)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
fn simple_examples() {
println!("{} | {} | {} | {} | {}",
Red.bg(Green).bold().paint("Red-Green-Bold"),
Blue.paint("Blue"),
Blue.bold().paint("BlueBold"),
Blue.bg(Magenta).paint("BlueMagentaBG"),
Plain.underline().paint("Underline"));
}
fn with_example() {
Red.with(|| {
print!("JustRed");
Bold.with(|| {
print!(" BoldRed {} BoldRed ", Underline.paint("Underline"));
});
print!("JustRed ");
print!("{}", Blue.paint("Blue (overwrite) "));
Green.with(|| {
println!("Green (overwrite)");
});
});
}
fn doc_examples() {
// --- Doc example 1
println!("{} or {} or {}",
Red.paint("Red"),
Bold.paint("Bold"),
Red.bold().paint("Both!"));
// --- Doc example 2
let x = 5;
// These two are equivalent
println!("{} | {}", x, Plain.paint(x));
// These two are equivalent, too
println!("{} | {}", Red.paint(x), Plain.fg(Red).paint(x));
// --- Doc example 3
let non_copy = "cake".to_string(); // String is *not* Copy
let copy = 27; // usize/isize *is* Copy
println!("{}", Plain.paint(&non_copy));
println!("{}", Plain.paint(©));
// non_copy is still usable here...
// copy is still usable here...
println!("{}", Plain.paint(non_copy));
println!("{}", Plain.paint(copy));
// non_copy was moved into paint, so it not usable anymore...
// copy is still usable here...
}
fn all_styles(colors: &[Color]) {
// Normal test
for c in colors { print!("{:?} ", c.paint(c)); }
println!(" (fg)");
for c in colors { print!("{:?} ", Plain.bg(*c).paint(c)); }
println!(" (bg)");
// Bold text
for c in colors { print!("{:?} ", c.bold().paint(c)); }
println!(" (bold fg)");
for c in colors { print!("{:?} ", Bold.bg(*c).paint(c)); }
println!(" (bold bg)");
// Dim text
for c in colors { print!("{:?} ", c.dim().paint(c)); }
println!(" (dim fg)");
for c in colors { print!("{:?} ", Dim.bg(*c).paint(c)); }
println!(" (dim bg)");
// Underlined text
for c in colors { print!("{:?} ", c.underline().paint(c)); }
println!(" (underline fg)");
for c in colors { print!("{:?} ", Underline.bg(*c).paint(c)); }
println!(" (underline bg)");
// Blinking text
for c in colors { print!("{:?} ", c.blink().paint(c)); }
println!(" (blink fg)");
for c in colors { print!("{:?} ", Blink.bg(*c).paint(c)); }
println!(" (blink bg)");
// Reverse text
for c in colors { print!("{:?} ", c.reverse().paint(c)); }
println!(" (reverse fg)");
for c in colors { print!("{:?} ", Reverse.bg(*c).paint(c)); }
println!(" (reverse bg)");
// Secure text
for c in colors { print!("{:?} ", c.secure().paint(c)); }
println!(" (secure fg)");
for c in colors { print!("{:?} ", Secure.bg(*c).paint(c)); }
println!(" (secure bg)");
}
sourcefn dim(self) -> Style
fn dim(self) -> Style
Dim mode.
Examples found in repository?
examples/main.rs (line 98)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
fn all_styles(colors: &[Color]) {
// Normal test
for c in colors { print!("{:?} ", c.paint(c)); }
println!(" (fg)");
for c in colors { print!("{:?} ", Plain.bg(*c).paint(c)); }
println!(" (bg)");
// Bold text
for c in colors { print!("{:?} ", c.bold().paint(c)); }
println!(" (bold fg)");
for c in colors { print!("{:?} ", Bold.bg(*c).paint(c)); }
println!(" (bold bg)");
// Dim text
for c in colors { print!("{:?} ", c.dim().paint(c)); }
println!(" (dim fg)");
for c in colors { print!("{:?} ", Dim.bg(*c).paint(c)); }
println!(" (dim bg)");
// Underlined text
for c in colors { print!("{:?} ", c.underline().paint(c)); }
println!(" (underline fg)");
for c in colors { print!("{:?} ", Underline.bg(*c).paint(c)); }
println!(" (underline bg)");
// Blinking text
for c in colors { print!("{:?} ", c.blink().paint(c)); }
println!(" (blink fg)");
for c in colors { print!("{:?} ", Blink.bg(*c).paint(c)); }
println!(" (blink bg)");
// Reverse text
for c in colors { print!("{:?} ", c.reverse().paint(c)); }
println!(" (reverse fg)");
for c in colors { print!("{:?} ", Reverse.bg(*c).paint(c)); }
println!(" (reverse bg)");
// Secure text
for c in colors { print!("{:?} ", c.secure().paint(c)); }
println!(" (secure fg)");
for c in colors { print!("{:?} ", Secure.bg(*c).paint(c)); }
println!(" (secure bg)");
}
sourcefn underline(self) -> Style
fn underline(self) -> Style
Underlines the text.
Examples found in repository?
examples/main.rs (line 35)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
fn simple_examples() {
println!("{} | {} | {} | {} | {}",
Red.bg(Green).bold().paint("Red-Green-Bold"),
Blue.paint("Blue"),
Blue.bold().paint("BlueBold"),
Blue.bg(Magenta).paint("BlueMagentaBG"),
Plain.underline().paint("Underline"));
}
fn with_example() {
Red.with(|| {
print!("JustRed");
Bold.with(|| {
print!(" BoldRed {} BoldRed ", Underline.paint("Underline"));
});
print!("JustRed ");
print!("{}", Blue.paint("Blue (overwrite) "));
Green.with(|| {
println!("Green (overwrite)");
});
});
}
fn doc_examples() {
// --- Doc example 1
println!("{} or {} or {}",
Red.paint("Red"),
Bold.paint("Bold"),
Red.bold().paint("Both!"));
// --- Doc example 2
let x = 5;
// These two are equivalent
println!("{} | {}", x, Plain.paint(x));
// These two are equivalent, too
println!("{} | {}", Red.paint(x), Plain.fg(Red).paint(x));
// --- Doc example 3
let non_copy = "cake".to_string(); // String is *not* Copy
let copy = 27; // usize/isize *is* Copy
println!("{}", Plain.paint(&non_copy));
println!("{}", Plain.paint(©));
// non_copy is still usable here...
// copy is still usable here...
println!("{}", Plain.paint(non_copy));
println!("{}", Plain.paint(copy));
// non_copy was moved into paint, so it not usable anymore...
// copy is still usable here...
}
fn all_styles(colors: &[Color]) {
// Normal test
for c in colors { print!("{:?} ", c.paint(c)); }
println!(" (fg)");
for c in colors { print!("{:?} ", Plain.bg(*c).paint(c)); }
println!(" (bg)");
// Bold text
for c in colors { print!("{:?} ", c.bold().paint(c)); }
println!(" (bold fg)");
for c in colors { print!("{:?} ", Bold.bg(*c).paint(c)); }
println!(" (bold bg)");
// Dim text
for c in colors { print!("{:?} ", c.dim().paint(c)); }
println!(" (dim fg)");
for c in colors { print!("{:?} ", Dim.bg(*c).paint(c)); }
println!(" (dim bg)");
// Underlined text
for c in colors { print!("{:?} ", c.underline().paint(c)); }
println!(" (underline fg)");
for c in colors { print!("{:?} ", Underline.bg(*c).paint(c)); }
println!(" (underline bg)");
// Blinking text
for c in colors { print!("{:?} ", c.blink().paint(c)); }
println!(" (blink fg)");
for c in colors { print!("{:?} ", Blink.bg(*c).paint(c)); }
println!(" (blink bg)");
// Reverse text
for c in colors { print!("{:?} ", c.reverse().paint(c)); }
println!(" (reverse fg)");
for c in colors { print!("{:?} ", Reverse.bg(*c).paint(c)); }
println!(" (reverse bg)");
// Secure text
for c in colors { print!("{:?} ", c.secure().paint(c)); }
println!(" (secure fg)");
for c in colors { print!("{:?} ", Secure.bg(*c).paint(c)); }
println!(" (secure bg)");
}
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?
examples/main.rs (line 110)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
fn all_styles(colors: &[Color]) {
// Normal test
for c in colors { print!("{:?} ", c.paint(c)); }
println!(" (fg)");
for c in colors { print!("{:?} ", Plain.bg(*c).paint(c)); }
println!(" (bg)");
// Bold text
for c in colors { print!("{:?} ", c.bold().paint(c)); }
println!(" (bold fg)");
for c in colors { print!("{:?} ", Bold.bg(*c).paint(c)); }
println!(" (bold bg)");
// Dim text
for c in colors { print!("{:?} ", c.dim().paint(c)); }
println!(" (dim fg)");
for c in colors { print!("{:?} ", Dim.bg(*c).paint(c)); }
println!(" (dim bg)");
// Underlined text
for c in colors { print!("{:?} ", c.underline().paint(c)); }
println!(" (underline fg)");
for c in colors { print!("{:?} ", Underline.bg(*c).paint(c)); }
println!(" (underline bg)");
// Blinking text
for c in colors { print!("{:?} ", c.blink().paint(c)); }
println!(" (blink fg)");
for c in colors { print!("{:?} ", Blink.bg(*c).paint(c)); }
println!(" (blink bg)");
// Reverse text
for c in colors { print!("{:?} ", c.reverse().paint(c)); }
println!(" (reverse fg)");
for c in colors { print!("{:?} ", Reverse.bg(*c).paint(c)); }
println!(" (reverse bg)");
// Secure text
for c in colors { print!("{:?} ", c.secure().paint(c)); }
println!(" (secure fg)");
for c in colors { print!("{:?} ", Secure.bg(*c).paint(c)); }
println!(" (secure bg)");
}
sourcefn reverse(self) -> Style
fn reverse(self) -> Style
Underlines the text.
Examples found in repository?
examples/main.rs (line 116)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
fn all_styles(colors: &[Color]) {
// Normal test
for c in colors { print!("{:?} ", c.paint(c)); }
println!(" (fg)");
for c in colors { print!("{:?} ", Plain.bg(*c).paint(c)); }
println!(" (bg)");
// Bold text
for c in colors { print!("{:?} ", c.bold().paint(c)); }
println!(" (bold fg)");
for c in colors { print!("{:?} ", Bold.bg(*c).paint(c)); }
println!(" (bold bg)");
// Dim text
for c in colors { print!("{:?} ", c.dim().paint(c)); }
println!(" (dim fg)");
for c in colors { print!("{:?} ", Dim.bg(*c).paint(c)); }
println!(" (dim bg)");
// Underlined text
for c in colors { print!("{:?} ", c.underline().paint(c)); }
println!(" (underline fg)");
for c in colors { print!("{:?} ", Underline.bg(*c).paint(c)); }
println!(" (underline bg)");
// Blinking text
for c in colors { print!("{:?} ", c.blink().paint(c)); }
println!(" (blink fg)");
for c in colors { print!("{:?} ", Blink.bg(*c).paint(c)); }
println!(" (blink bg)");
// Reverse text
for c in colors { print!("{:?} ", c.reverse().paint(c)); }
println!(" (reverse fg)");
for c in colors { print!("{:?} ", Reverse.bg(*c).paint(c)); }
println!(" (reverse bg)");
// Secure text
for c in colors { print!("{:?} ", c.secure().paint(c)); }
println!(" (secure fg)");
for c in colors { print!("{:?} ", Secure.bg(*c).paint(c)); }
println!(" (secure bg)");
}
sourcefn secure(self) -> Style
fn secure(self) -> Style
Secure mode.
Examples found in repository?
examples/main.rs (line 122)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
fn all_styles(colors: &[Color]) {
// Normal test
for c in colors { print!("{:?} ", c.paint(c)); }
println!(" (fg)");
for c in colors { print!("{:?} ", Plain.bg(*c).paint(c)); }
println!(" (bg)");
// Bold text
for c in colors { print!("{:?} ", c.bold().paint(c)); }
println!(" (bold fg)");
for c in colors { print!("{:?} ", Bold.bg(*c).paint(c)); }
println!(" (bold bg)");
// Dim text
for c in colors { print!("{:?} ", c.dim().paint(c)); }
println!(" (dim fg)");
for c in colors { print!("{:?} ", Dim.bg(*c).paint(c)); }
println!(" (dim bg)");
// Underlined text
for c in colors { print!("{:?} ", c.underline().paint(c)); }
println!(" (underline fg)");
for c in colors { print!("{:?} ", Underline.bg(*c).paint(c)); }
println!(" (underline bg)");
// Blinking text
for c in colors { print!("{:?} ", c.blink().paint(c)); }
println!(" (blink fg)");
for c in colors { print!("{:?} ", Blink.bg(*c).paint(c)); }
println!(" (blink bg)");
// Reverse text
for c in colors { print!("{:?} ", c.reverse().paint(c)); }
println!(" (reverse fg)");
for c in colors { print!("{:?} ", Reverse.bg(*c).paint(c)); }
println!(" (reverse bg)");
// Secure text
for c in colors { print!("{:?} ", c.secure().paint(c)); }
println!(" (secure fg)");
for c in colors { print!("{:?} ", Secure.bg(*c).paint(c)); }
println!(" (secure bg)");
}
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?
examples/main.rs (line 31)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
fn simple_examples() {
println!("{} | {} | {} | {} | {}",
Red.bg(Green).bold().paint("Red-Green-Bold"),
Blue.paint("Blue"),
Blue.bold().paint("BlueBold"),
Blue.bg(Magenta).paint("BlueMagentaBG"),
Plain.underline().paint("Underline"));
}
fn with_example() {
Red.with(|| {
print!("JustRed");
Bold.with(|| {
print!(" BoldRed {} BoldRed ", Underline.paint("Underline"));
});
print!("JustRed ");
print!("{}", Blue.paint("Blue (overwrite) "));
Green.with(|| {
println!("Green (overwrite)");
});
});
}
fn doc_examples() {
// --- Doc example 1
println!("{} or {} or {}",
Red.paint("Red"),
Bold.paint("Bold"),
Red.bold().paint("Both!"));
// --- Doc example 2
let x = 5;
// These two are equivalent
println!("{} | {}", x, Plain.paint(x));
// These two are equivalent, too
println!("{} | {}", Red.paint(x), Plain.fg(Red).paint(x));
// --- Doc example 3
let non_copy = "cake".to_string(); // String is *not* Copy
let copy = 27; // usize/isize *is* Copy
println!("{}", Plain.paint(&non_copy));
println!("{}", Plain.paint(©));
// non_copy is still usable here...
// copy is still usable here...
println!("{}", Plain.paint(non_copy));
println!("{}", Plain.paint(copy));
// non_copy was moved into paint, so it not usable anymore...
// copy is still usable here...
}
fn all_styles(colors: &[Color]) {
// Normal test
for c in colors { print!("{:?} ", c.paint(c)); }
println!(" (fg)");
for c in colors { print!("{:?} ", Plain.bg(*c).paint(c)); }
println!(" (bg)");
// Bold text
for c in colors { print!("{:?} ", c.bold().paint(c)); }
println!(" (bold fg)");
for c in colors { print!("{:?} ", Bold.bg(*c).paint(c)); }
println!(" (bold bg)");
// Dim text
for c in colors { print!("{:?} ", c.dim().paint(c)); }
println!(" (dim fg)");
for c in colors { print!("{:?} ", Dim.bg(*c).paint(c)); }
println!(" (dim bg)");
// Underlined text
for c in colors { print!("{:?} ", c.underline().paint(c)); }
println!(" (underline fg)");
for c in colors { print!("{:?} ", Underline.bg(*c).paint(c)); }
println!(" (underline bg)");
// Blinking text
for c in colors { print!("{:?} ", c.blink().paint(c)); }
println!(" (blink fg)");
for c in colors { print!("{:?} ", Blink.bg(*c).paint(c)); }
println!(" (blink bg)");
// Reverse text
for c in colors { print!("{:?} ", c.reverse().paint(c)); }
println!(" (reverse fg)");
for c in colors { print!("{:?} ", Reverse.bg(*c).paint(c)); }
println!(" (reverse bg)");
// Secure text
for c in colors { print!("{:?} ", c.secure().paint(c)); }
println!(" (secure fg)");
for c in colors { print!("{:?} ", Secure.bg(*c).paint(c)); }
println!(" (secure bg)");
}
More examples
examples/custom.rs (line 13)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
fn main() {
// print 16 colors each line
for line in 0..16 {
// foreground
print!("FG: ");
for c in (0..16).map(|i| 16*line + i) {
print!("{: <2x} ", Custom(c).paint(c));
}
println!("");
// background
print!("BG: ");
for c in (0..16).map(|i| 16*line + i) {
print!("{: <2x} ", Plain.bg(Custom(c)).paint(c));
}
println!("");
}
}
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?
examples/main.rs (lines 39-50)
38 39 40 41 42 43 44 45 46 47 48 49 50 51
fn with_example() {
Red.with(|| {
print!("JustRed");
Bold.with(|| {
print!(" BoldRed {} BoldRed ", Underline.paint("Underline"));
});
print!("JustRed ");
print!("{}", Blue.paint("Blue (overwrite) "));
Green.with(|| {
println!("Green (overwrite)");
});
});
}
Object Safety§
This trait is not object safe.