From 5d5a3e4a21ca54c51474d6a35dd269693e5533d4 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Wed, 19 May 2021 18:06:15 -0400 Subject: [PATCH] Separate calculator display code --- src/main.rs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/main.rs b/src/main.rs index 80658b7..dc92d59 100644 --- a/src/main.rs +++ b/src/main.rs @@ -225,23 +225,22 @@ impl App { .enumerate() .rev() .map(|(i, m)| { - let content = vec![Spans::from(Span::raw( - match self.calculator.get_display_mode() { - CalculatorDisplayMode::Default => format!("{:>2}: {}", i, *m), - CalculatorDisplayMode::Separated { separator } => { - format!("{:>2}: {}", i, format::separated(*m, *separator)) - } - CalculatorDisplayMode::Scientific { precision } => { - format!("{:>2}: {}", i, format::scientific(*m, *precision)) - } - CalculatorDisplayMode::Engineering { precision } => { - format!("{:>2}: {}", i, format::engineering(*m, *precision)) - } - CalculatorDisplayMode::Fixed { precision } => { - format!("{:>2}: {:.precision$}", i, m, precision = precision) - } - }, - ))]; + let number = match self.calculator.get_display_mode() { + CalculatorDisplayMode::Default => format!("{}", m), + CalculatorDisplayMode::Separated { separator } => { + format::separated(*m, *separator) + } + CalculatorDisplayMode::Scientific { precision } => { + format::scientific(*m, *precision) + } + CalculatorDisplayMode::Engineering { precision } => { + format::engineering(*m, *precision) + } + CalculatorDisplayMode::Fixed { precision } => { + format!("{:0>.precision$}", m, precision = precision) + } + }; + let content = vec![Spans::from(Span::raw(format!("{:>2}: {}", i, number)))]; ListItem::new(content) }) .collect();