-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.rs
127 lines (103 loc) · 3.62 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
extern crate term_painter;
use term_painter::{ToStyle, Color};
use term_painter::Color::*;
use term_painter::Attr::*;
fn main() {
struct_sizes();
simple_examples();
with_example();
doc_examples();
all_styles(
&[NotSet, Black, Red, Green, Yellow, Blue, Magenta, Cyan, White]);
all_styles(
&[BrightBlack, BrightRed, BrightGreen, BrightYellow, BrightBlue,
BrightMagenta, BrightCyan, BrightWhite]);
}
fn struct_sizes() {
use std::mem::size_of;
println!("size_of(Style): {}", size_of::<term_painter::Style>());
println!("size_of(Color): {}", size_of::<Color>());
println!("size_of(Attr): {}", size_of::<term_painter::Attr>());
}
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)");
}