diff options
Diffstat (limited to 'vendor/colored/examples')
-rwxr-xr-x | vendor/colored/examples/control.rs | 53 | ||||
-rwxr-xr-x | vendor/colored/examples/dynamic_colors.rs | 14 | ||||
-rwxr-xr-x | vendor/colored/examples/most_simple.rs | 24 | ||||
-rwxr-xr-x | vendor/colored/examples/nested_colors.rs | 16 |
4 files changed, 107 insertions, 0 deletions
diff --git a/vendor/colored/examples/control.rs b/vendor/colored/examples/control.rs new file mode 100755 index 000000000..b50b42691 --- /dev/null +++ b/vendor/colored/examples/control.rs @@ -0,0 +1,53 @@ +extern crate colored; +use colored::*; + +#[cfg(not(windows))] +fn main() { + both() +} + +#[cfg(windows)] +fn main() { + both(); + + // additional control setting using windows set_virtual_terminal + colored::control::set_virtual_terminal(true); + println!("{}", "stdout: Virtual Terminal is in use".bright_green()); + colored::control::set_virtual_terminal(false); + println!( + "{}", + "stderr: Virtual Terminal is NOT in use, escape chars should be visible".bright_red() + ); + colored::control::set_virtual_terminal(true); + println!( + "{}", + "stdout: Virtual Terminal is in use AGAIN and should be green!".bright_green() + ); + colored::control::set_virtual_terminal(true); + + // again with stderr + eprintln!("{}", "stderr: Virtual Terminal is in use".bright_green()); + colored::control::set_virtual_terminal(false); + eprintln!( + "{}", + "stderr: Virtual Terminal is NOT in use, escape chars should be visible".bright_red() + ); + colored::control::set_virtual_terminal(true); + eprintln!( + "{}", + "stderr: Virtual Terminal is in use AGAIN and should be green!".bright_green() + ); +} + +fn both() { + // this will be yellow if your environment allow it + println!("{}", "some warning".yellow()); + // now , this will be always yellow + colored::control::set_override(true); + println!("{}", "some warning".yellow()); + // now, this will be never yellow + colored::control::set_override(false); + println!("{}", "some warning".yellow()); + // let the environment decide again + colored::control::unset_override(); +} diff --git a/vendor/colored/examples/dynamic_colors.rs b/vendor/colored/examples/dynamic_colors.rs new file mode 100755 index 000000000..d9861f425 --- /dev/null +++ b/vendor/colored/examples/dynamic_colors.rs @@ -0,0 +1,14 @@ +extern crate colored; +use colored::*; + +fn main() { + // the easy way + "blue string yo".color("blue"); + + // this will default to white + "white string".color("zorglub"); + + // the safer way via a Result + let color_res = "zorglub".parse(); // <- this returns a Result<Color, ()> + "red string".color(color_res.unwrap_or(Color::Red)); +} diff --git a/vendor/colored/examples/most_simple.rs b/vendor/colored/examples/most_simple.rs new file mode 100755 index 000000000..b94a2b36a --- /dev/null +++ b/vendor/colored/examples/most_simple.rs @@ -0,0 +1,24 @@ +extern crate colored; + +use colored::*; + +fn main() { + // TADAA ! + println!( + "{} {} {}!", + "it".green(), + "works".blue().bold(), + "great".bold().yellow() + ); + + println!("{}", String::from("this also works!").green().bold()); + + let mut s = String::new(); + s.push_str(&"why not ".red().to_string()); + s.push_str(&"push things ".blue().to_string()); + s.push_str(&"a little further ?".green().to_string()); + println!("{}", s); + + let s = format!("{} {} {}", "this".red(), "is".blue(), "easier".green()); + println!("{}", s); +} diff --git a/vendor/colored/examples/nested_colors.rs b/vendor/colored/examples/nested_colors.rs new file mode 100755 index 000000000..de1124916 --- /dev/null +++ b/vendor/colored/examples/nested_colors.rs @@ -0,0 +1,16 @@ +extern crate colored; + +use colored::*; + +/* + * This example use colored strings in a nested way (at line 14). It shows that colored is able to + * keep the correct color on the “!lalalala” part. + */ + +fn main() { + let world = "world".bold(); + let hello_world = format!("Hello, {}!", world); + println!("{}", hello_world); + let hello_world = format!("Hello, {}!lalalala", world).red(); + println!("{}", hello_world); +} |