Format and cleanup

This commit is contained in:
Austen Adler 2021-05-14 20:02:41 -04:00
parent 2ec4e2ea1a
commit a845c5044f
3 changed files with 19 additions and 19 deletions

View File

@ -77,7 +77,7 @@ pub fn separated(f: f64, sep: char) -> String {
mod tests { mod tests {
use super::*; use super::*;
#[test] #[test]
fn test_fmt_scientific() { fn test_scientific() {
for (f, p, s) in vec![ for (f, p, s) in vec![
// Basic // Basic
(1.0, 0, " 1 E+00"), (1.0, 0, " 1 E+00"),
@ -102,12 +102,12 @@ mod tests {
(1.5, 1, " 1.5 E+00"), (1.5, 1, " 1.5 E+00"),
(1.5, 0, " 2 E+00"), (1.5, 0, " 2 E+00"),
] { ] {
assert_eq!(fmt_scientific(f, p), s); assert_eq!(scientific(f, p), s);
} }
} }
#[test] #[test]
fn test_fmt_separated() { fn test_separated() {
for (f, c, s) in vec![ for (f, c, s) in vec![
(100.0, ',', "100"), (100.0, ',', "100"),
(100.0, ',', "100"), (100.0, ',', "100"),
@ -125,12 +125,12 @@ mod tests {
(1_000_000.123456789, ' ', "1 000 000.123456789"), (1_000_000.123456789, ' ', "1 000 000.123456789"),
(1_000_000.123456789, ' ', "1 000 000.123456789"), (1_000_000.123456789, ' ', "1 000 000.123456789"),
] { ] {
assert_eq!(fmt_separated(f, c), s); assert_eq!(separated(f, c), s);
} }
} }
#[test] #[test]
fn test_fmt_engineering() { fn test_engineering() {
for (f, c, s) in vec![ for (f, c, s) in vec![
(100.0, 3, " 100.000 E+00"), (100.0, 3, " 100.000 E+00"),
(100.0, 3, " 100.000 E+00"), (100.0, 3, " 100.000 E+00"),
@ -149,7 +149,7 @@ mod tests {
(1.5, 1, " 1.5 E+00"), (1.5, 1, " 1.5 E+00"),
(1.5, 0, " 2. E+00"), (1.5, 0, " 2. E+00"),
] { ] {
assert_eq!(fmt_engineering(f, c), s); assert_eq!(engineering(f, c), s);
} }
} }
} }

View File

@ -10,7 +10,7 @@ use calc::constants::{CalculatorDisplayMode, CalculatorState, RegisterState};
use calc::errors::CalculatorResult; use calc::errors::CalculatorResult;
use calc::Calculator; use calc::Calculator;
use crossterm::{ use crossterm::{
event::{self, DisableMouseCapture, Event as CEvent, KeyCode, KeyEvent, KeyModifiers}, event::{DisableMouseCapture, KeyCode, KeyEvent, KeyModifiers},
execute, execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
}; };
@ -18,8 +18,7 @@ use io::stdout;
use std::cmp; use std::cmp;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::io::Write; use std::io::Write;
use std::sync::mpsc;
use std::thread;
use std::{error::Error, io}; use std::{error::Error, io};
use tui::{ use tui::{
backend::CrosstermBackend, backend::CrosstermBackend,
@ -370,7 +369,7 @@ fn handle_key(app: &mut App, key: KeyEvent) -> CalculatorResult<CalculatorRespon
code: KeyCode::Char(c), code: KeyCode::Char(c),
modifiers: KeyModifiers::SHIFT, modifiers: KeyModifiers::SHIFT,
} => { } => {
for c in (c.to_uppercase()) { for c in c.to_uppercase() {
app.calculator.take_input(c)?; app.calculator.take_input(c)?;
} }
} }

View File

@ -1,15 +1,11 @@
use std::io;
use std::iter; use std::iter;
use std::sync::mpsc; use std::sync::mpsc;
use std::sync::mpsc::{Iter, TryIter}; use std::sync::mpsc::TryIter;
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
use std::thread; use std::thread;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use crossterm::event::{self, Event as CEvent, KeyCode, KeyEvent, KeyModifiers}; use crossterm::event::{self, Event as CEvent, KeyEvent};
pub enum Event<I> { pub enum Event<I> {
Input(I), Input(I),
@ -57,7 +53,12 @@ impl Events {
/// Returns a chain of the next element (blocking) and a TryIter of everything after it. /// Returns a chain of the next element (blocking) and a TryIter of everything after it.
/// Useful for reading a single Iterator of all elements once after blocking, so there are not too many UI redraws. /// Useful for reading a single Iterator of all elements once after blocking, so there are not too many UI redraws.
pub fn blocking_iter(&self) -> Result<iter::Chain<iter::Once<Event<KeyEvent>>,TryIter<Event<KeyEvent>>>, mpsc::RecvError> { pub fn blocking_iter(
Ok(iter::once(self.rx.recv()?).chain(self.rx.try_iter()).into_iter()) &self,
) -> Result<iter::Chain<iter::Once<Event<KeyEvent>>, TryIter<Event<KeyEvent>>>, mpsc::RecvError>
{
Ok(iter::once(self.rx.recv()?)
.chain(self.rx.try_iter())
.into_iter())
} }
} }