Debian Codegraph @

examples/control.rs

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