diff --git a/src/main.rs b/src/main.rs index 84dfe16..e80c10f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +mod tui; + mod cli; use cli::{Commands, CLI}; @@ -9,6 +11,8 @@ use clap::Parser; fn main() { let cli = CLI::parse(); + print!("\n"); + match &cli.command { Some(Commands::Square(square::Command { base, height })) => square::view(*base, *height), Some(Commands::Circle(circle::Command { radius })) => circle::view(*radius), diff --git a/src/shapes/circle/view.rs b/src/shapes/circle/view.rs index 87932c1..ab0e809 100644 --- a/src/shapes/circle/view.rs +++ b/src/shapes/circle/view.rs @@ -1,7 +1,12 @@ use crate::shapes::circle::Circle; +use crate::tui; pub fn view(radius: f64) { let circle = Circle { radius }; - println!("{}cm", circle.get_area()); + println!( + "{}{}", + tui::title("Area"), + tui::content(circle.get_area().to_string().as_str()) + ); } diff --git a/src/shapes/rhombus/view.rs b/src/shapes/rhombus/view.rs index cb087d9..675aa89 100644 --- a/src/shapes/rhombus/view.rs +++ b/src/shapes/rhombus/view.rs @@ -1,4 +1,4 @@ -use crate::shapes::rhombus::Rhombus; +use crate::{shapes::rhombus::Rhombus, tui}; pub fn view(s_diagonal: f32, l_diagonal: f32) { let rhombus = Rhombus { @@ -6,5 +6,9 @@ pub fn view(s_diagonal: f32, l_diagonal: f32) { s_diagonal, }; - println!("{}cm", rhombus.get_area()) + println!( + "{}{}", + tui::title("Area"), + tui::content(rhombus.get_area().to_string().as_str()) + ) } diff --git a/src/shapes/square/view.rs b/src/shapes/square/view.rs index 45aaa46..a2f2387 100644 --- a/src/shapes/square/view.rs +++ b/src/shapes/square/view.rs @@ -1,7 +1,11 @@ -use crate::shapes::square::Square; +use crate::{shapes::square::Square, tui}; pub fn view(base: i32, height: i32) { let square = Square { base, height }; - println!("{}cm", square.get_area()); + println!( + "{}{}", + tui::title("Area"), + tui::content(square.get_area().to_string().as_str()) + ); } diff --git a/src/shapes/trapezoid/view.rs b/src/shapes/trapezoid/view.rs index 1abd67b..eb49991 100644 --- a/src/shapes/trapezoid/view.rs +++ b/src/shapes/trapezoid/view.rs @@ -1,4 +1,4 @@ -use crate::shapes::trapezoid::Trapezoid; +use crate::{shapes::trapezoid::Trapezoid, tui}; pub fn view(s_base: f32, l_base: f32, height: f32) { let trapezoid = Trapezoid { @@ -7,5 +7,9 @@ pub fn view(s_base: f32, l_base: f32, height: f32) { s_base, }; - println!("Area: {}cm", trapezoid.get_area()) + println!( + "{}{}", + tui::title("Area"), + tui::content(trapezoid.get_area().to_string().as_str()) + ) } diff --git a/src/shapes/triangle/view.rs b/src/shapes/triangle/view.rs index 6e9b0a3..3eecdba 100644 --- a/src/shapes/triangle/view.rs +++ b/src/shapes/triangle/view.rs @@ -1,4 +1,7 @@ -use crate::shapes::triangle::{SidesTriangle, SimpleTriangle}; +use crate::{ + shapes::triangle::{SidesTriangle, SimpleTriangle}, + tui, +}; pub fn view( base: Option, @@ -11,7 +14,11 @@ pub fn view( if let (Some(base), Some(height)) = (base, height) { let triangle = SimpleTriangle { base, height }; - println!("Area: {}cm", triangle.get_area()); + println!( + "{}{}", + tui::title("Area"), + tui::content(triangle.get_area().to_string().as_str()) + ); } else if let (Some(side_a), Some(side_b), Some(side_c)) = (side_a, side_b, side_c) { let triangle = SidesTriangle { side_a, @@ -19,7 +26,16 @@ pub fn view( side_c, }; - println!("Area: {}cm", triangle.get_area()); - println!("Perimeter: {}cm", triangle.get_semi_perimeter()); + println!( + "{}{}", + tui::title("Area"), + tui::content(triangle.get_area().to_string().as_str()) + ); + print!("\n"); + println!( + "{}{}", + tui::title("Perimeter"), + tui::content(triangle.get_semi_perimeter().to_string().as_str()) + ); } } diff --git a/src/tui.rs b/src/tui.rs new file mode 100644 index 0000000..5263ff4 --- /dev/null +++ b/src/tui.rs @@ -0,0 +1,15 @@ +use colored::*; + +pub fn title(title: &str) -> ColoredString { + format!(" {} ", title) + .bold() + .truecolor(42, 157, 143) + .on_truecolor(38, 70, 83) +} + +pub fn content(value: &str) -> ColoredString { + format!(" {} ", value) + .truecolor(42, 157, 143) + .on_truecolor(42, 157, 143) + .bold() +}