1extern crate term_painter;
2
3use term_painter::{ToStyle, Color};
4use term_painter::Color::*;
5use term_painter::Attr::*;
6
7fn main() {
8 struct_sizes();
9
10 simple_examples();
11 with_example();
12 doc_examples();
13
14 all_styles(
15 &[NotSet, Black, Red, Green, Yellow, Blue, Magenta, Cyan, White]);
16 all_styles(
17 &[BrightBlack, BrightRed, BrightGreen, BrightYellow, BrightBlue,
18 BrightMagenta, BrightCyan, BrightWhite]);
19}
20
21fn struct_sizes() {
22 use std::mem::size_of;
23
24 println!("size_of(Style): {}", size_of::<term_painter::Style>());
25 println!("size_of(Color): {}", size_of::<Color>());
26 println!("size_of(Attr): {}", size_of::<term_painter::Attr>());
27}
28
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 println!("{} or {} or {}",
56 Red.paint("Red"),
57 Bold.paint("Bold"),
58 Red.bold().paint("Both!"));
59
60 let x = 5;
62
63 println!("{} | {}", x, Plain.paint(x));
65
66 println!("{} | {}", Red.paint(x), Plain.fg(Red).paint(x));
68
69 let non_copy = "cake".to_string(); let copy = 27; println!("{}", Plain.paint(&non_copy));
74 println!("{}", Plain.paint(©));
75 println!("{}", Plain.paint(non_copy));
79 println!("{}", Plain.paint(copy));
80 }
83
84fn all_styles(colors: &[Color]) {
85 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 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 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 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 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 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 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}