From c06fecdc75b01a113bb99fade74e0b264acebd6b Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Mon, 1 Feb 2021 14:17:23 -0300 Subject: [PATCH] Some playing with Console --- cons/Cargo.toml | 9 +++++++++ cons/README.md | 4 ++++ cons/src/main.rs | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 cons/Cargo.toml create mode 100644 cons/README.md create mode 100644 cons/src/main.rs diff --git a/cons/Cargo.toml b/cons/Cargo.toml new file mode 100644 index 0000000..ec0b866 --- /dev/null +++ b/cons/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "cons" +version = "0.1.0" +description = "Tests and experimentations with Console" +authors = ["Julio Biason "] +edition = "2018" + +[dependencies] +console = "0.14" diff --git a/cons/README.md b/cons/README.md new file mode 100644 index 0000000..a542638 --- /dev/null +++ b/cons/README.md @@ -0,0 +1,4 @@ +# Cons + +Tests and experimentation with the +[console](https://docs.rs/console/0.14.0/console/index.html) crate. diff --git a/cons/src/main.rs b/cons/src/main.rs new file mode 100644 index 0000000..10f5fe1 --- /dev/null +++ b/cons/src/main.rs @@ -0,0 +1,21 @@ +use console::Style; +use console::Term; + +fn main() { + let term = Term::stdout(); + let (_rows, columns) = term.size(); + let success = Style::new().green().underlined(); + let error = Style::new().red().underlined(); + println!("Total width: {}", columns); + + println!( + "{value:>width$}", + value = success.apply_to("Some value"), + width = columns as usize + ); + println!( + "{value:>width$}", + value = error.apply_to("Invalid"), + width = (columns / 2) as usize + ) +}