Debian Codegraph @

examples/control.rs

raw symbols SCIP
1 #![allow(unused_must_use)]
2 extern crate colored;
3 use colored::Colorize;
4
5 #[cfg(not(windows))]
6 fn main() {
7 both();
8 }
9
10 #[cfg(windows)]
11 fn main() {
12 both();
13
14 // additional control setting using windows set_virtual_terminal
15 colored::control::set_virtual_terminal(true);
16 println!("{}", "stdout: Virtual Terminal is in use".bright_green());
17 colored::control::set_virtual_terminal(false);
18 println!(
19 "{}",
20 "stderr: Virtual Terminal is NOT in use, escape chars should be visible".bright_red()
21 );
22 colored::control::set_virtual_terminal(true);
23 println!(
24 "{}",
25 "stdout: Virtual Terminal is in use AGAIN and should be green!".bright_green()
26 );
27 colored::control::set_virtual_terminal(true);
28
29 // again with stderr
30 eprintln!("{}", "stderr: Virtual Terminal is in use".bright_green());
31 colored::control::set_virtual_terminal(false);
32 eprintln!(
33 "{}",
34 "stderr: Virtual Terminal is NOT in use, escape chars should be visible".bright_red()
35 );
36 colored::control::set_virtual_terminal(true);
37 eprintln!(
38 "{}",
39 "stderr: Virtual Terminal is in use AGAIN and should be green!".bright_green()
40 );
41 }
42
43 fn both() {
44 // this will be yellow if your environment allow it
45 println!("{}", "some warning".yellow());
46 // now , this will be always yellow
47 colored::control::set_override(true);
48 println!("{}", "some warning".yellow());
49 // now, this will be never yellow
50 colored::control::set_override(false);
51 println!("{}", "some warning".yellow());
52 // let the environment decide again
53 colored::control::unset_override();
54 }