From 4d1e44fd4c6237228c6d366ba371d9c88a9311e1 Mon Sep 17 00:00:00 2001 From: Vla Mai Date: Tue, 2 Apr 2019 03:37:15 +0500 Subject: add print function --- src/main.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 5219c6d..94cbc1e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,7 +49,7 @@ fn main() { if CONFIGURATION.input.len() > 0 { let evaled = eval_math_expression(&CONFIGURATION.input[..]); match evaled { - Ok(ans) => println!("{:.*}", CONFIGURATION.fix, ans), + Ok(ans) => pprint(ans), Err(e) => { eprintln!("{}", handler(e)); std::process::exit(1); @@ -74,7 +74,7 @@ fn main() { rl.add_history_entry(line.as_ref()); let evaled = eval_math_expression(&line[..]); match evaled { - Ok(ans) => println!("{:.*}", CONFIGURATION.fix, ans), + Ok(ans) => pprint(ans), Err(e) => println!("{}", handler(e)), }; }, @@ -96,6 +96,10 @@ fn main() { } } +fn pprint(ans: f64) { + println!("{a:width$}", width = CONFIGURATION.fix, a = ans) +} + fn parse_arguments() -> Configuration { let config = App::new(env!("CARGO_PKG_NAME")) .version(env!("CARGO_PKG_VERSION")) @@ -119,7 +123,7 @@ fn parse_arguments() -> Configuration { let mut input = String::new(); if let Some(i) = config.value_of("INPUT") { input.push_str(i); - }; + }; Configuration { radian_mode: config.is_present("radian"), fix: config.value_of("fix") @@ -166,7 +170,7 @@ fn eval_math_expression(input: &str) -> Result { Ok(evaled) } -#[cfg(test)] +#[cfg(test)] mod tests { use super::*; -- cgit v1.2.3