diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | src/main.rs | 12 |
2 files changed, 9 insertions, 4 deletions
@@ -11,3 +11,4 @@ Cargo.lock | |||
11 | 11 | ||
12 | # ignore history used by rustyline | 12 | # ignore history used by rustyline |
13 | history.txt | 13 | history.txt |
14 | ./.idea \ No newline at end of file | ||
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() { | |||
49 | if CONFIGURATION.input.len() > 0 { | 49 | if CONFIGURATION.input.len() > 0 { |
50 | let evaled = eval_math_expression(&CONFIGURATION.input[..]); | 50 | let evaled = eval_math_expression(&CONFIGURATION.input[..]); |
51 | match evaled { | 51 | match evaled { |
52 | Ok(ans) => println!("{:.*}", CONFIGURATION.fix, ans), | 52 | Ok(ans) => pprint(ans), |
53 | Err(e) => { | 53 | Err(e) => { |
54 | eprintln!("{}", handler(e)); | 54 | eprintln!("{}", handler(e)); |
55 | std::process::exit(1); | 55 | std::process::exit(1); |
@@ -74,7 +74,7 @@ fn main() { | |||
74 | rl.add_history_entry(line.as_ref()); | 74 | rl.add_history_entry(line.as_ref()); |
75 | let evaled = eval_math_expression(&line[..]); | 75 | let evaled = eval_math_expression(&line[..]); |
76 | match evaled { | 76 | match evaled { |
77 | Ok(ans) => println!("{:.*}", CONFIGURATION.fix, ans), | 77 | Ok(ans) => pprint(ans), |
78 | Err(e) => println!("{}", handler(e)), | 78 | Err(e) => println!("{}", handler(e)), |
79 | }; | 79 | }; |
80 | }, | 80 | }, |
@@ -96,6 +96,10 @@ fn main() { | |||
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 | ||
99 | fn pprint(ans: f64) { | ||
100 | println!("{a:width$}", width = CONFIGURATION.fix, a = ans) | ||
101 | } | ||
102 | |||
99 | fn parse_arguments() -> Configuration { | 103 | fn parse_arguments() -> Configuration { |
100 | let config = App::new(env!("CARGO_PKG_NAME")) | 104 | let config = App::new(env!("CARGO_PKG_NAME")) |
101 | .version(env!("CARGO_PKG_VERSION")) | 105 | .version(env!("CARGO_PKG_VERSION")) |
@@ -119,7 +123,7 @@ fn parse_arguments() -> Configuration { | |||
119 | let mut input = String::new(); | 123 | let mut input = String::new(); |
120 | if let Some(i) = config.value_of("INPUT") { | 124 | if let Some(i) = config.value_of("INPUT") { |
121 | input.push_str(i); | 125 | input.push_str(i); |
122 | }; | 126 | }; |
123 | Configuration { | 127 | Configuration { |
124 | radian_mode: config.is_present("radian"), | 128 | radian_mode: config.is_present("radian"), |
125 | fix: config.value_of("fix") | 129 | fix: config.value_of("fix") |
@@ -166,7 +170,7 @@ fn eval_math_expression(input: &str) -> Result<f64, CalcError> { | |||
166 | Ok(evaled) | 170 | Ok(evaled) |
167 | } | 171 | } |
168 | 172 | ||
169 | #[cfg(test)] | 173 | #[cfg(test)] |
170 | mod tests { | 174 | mod tests { |
171 | use super::*; | 175 | use super::*; |
172 | 176 | ||