Format and cleanup
This commit is contained in:
parent
2ec4e2ea1a
commit
a845c5044f
@ -77,7 +77,7 @@ pub fn separated(f: f64, sep: char) -> String {
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn test_fmt_scientific() {
|
||||
fn test_scientific() {
|
||||
for (f, p, s) in vec![
|
||||
// Basic
|
||||
(1.0, 0, " 1 E+00"),
|
||||
@ -102,12 +102,12 @@ mod tests {
|
||||
(1.5, 1, " 1.5 E+00"),
|
||||
(1.5, 0, " 2 E+00"),
|
||||
] {
|
||||
assert_eq!(fmt_scientific(f, p), s);
|
||||
assert_eq!(scientific(f, p), s);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fmt_separated() {
|
||||
fn test_separated() {
|
||||
for (f, c, s) in vec![
|
||||
(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"),
|
||||
] {
|
||||
assert_eq!(fmt_separated(f, c), s);
|
||||
assert_eq!(separated(f, c), s);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fmt_engineering() {
|
||||
fn test_engineering() {
|
||||
for (f, c, s) in vec![
|
||||
(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, 0, " 2. E+00"),
|
||||
] {
|
||||
assert_eq!(fmt_engineering(f, c), s);
|
||||
assert_eq!(engineering(f, c), s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ use calc::constants::{CalculatorDisplayMode, CalculatorState, RegisterState};
|
||||
use calc::errors::CalculatorResult;
|
||||
use calc::Calculator;
|
||||
use crossterm::{
|
||||
event::{self, DisableMouseCapture, Event as CEvent, KeyCode, KeyEvent, KeyModifiers},
|
||||
event::{DisableMouseCapture, KeyCode, KeyEvent, KeyModifiers},
|
||||
execute,
|
||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||
};
|
||||
@ -18,8 +18,7 @@ use io::stdout;
|
||||
use std::cmp;
|
||||
use std::convert::TryFrom;
|
||||
use std::io::Write;
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
|
||||
use std::{error::Error, io};
|
||||
use tui::{
|
||||
backend::CrosstermBackend,
|
||||
@ -370,7 +369,7 @@ fn handle_key(app: &mut App, key: KeyEvent) -> CalculatorResult<CalculatorRespon
|
||||
code: KeyCode::Char(c),
|
||||
modifiers: KeyModifiers::SHIFT,
|
||||
} => {
|
||||
for c in (c.to_uppercase()) {
|
||||
for c in c.to_uppercase() {
|
||||
app.calculator.take_input(c)?;
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,11 @@
|
||||
use std::io;
|
||||
use std::iter;
|
||||
use std::sync::mpsc;
|
||||
use std::sync::mpsc::{Iter, TryIter};
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc,
|
||||
};
|
||||
use std::sync::mpsc::TryIter;
|
||||
|
||||
use std::thread;
|
||||
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> {
|
||||
Input(I),
|
||||
@ -57,7 +53,12 @@ impl Events {
|
||||
|
||||
/// 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.
|
||||
pub fn blocking_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())
|
||||
pub fn blocking_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())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user