diff --git a/src/calc.rs b/src/calc.rs index 2bdbb47..6dc04b6 100644 --- a/src/calc.rs +++ b/src/calc.rs @@ -4,9 +4,8 @@ pub mod operations; use confy::{load, store}; use constants::{ - CalculatorAngleMode, CalculatorConstant, CalculatorConstants, CalculatorConstantsIter, - CalculatorDisplayMode, CalculatorMacro, CalculatorMacros, CalculatorMacrosIter, - CalculatorRegisters, CalculatorRegistersIter, CalculatorState, RegisterState, + CalculatorAngleMode, CalculatorConstant, CalculatorConstants, CalculatorDisplayMode, + CalculatorMacro, CalculatorMacros, CalculatorRegisters, CalculatorState, RegisterState, }; use errors::{CalculatorError, CalculatorResult}; use operations::{CalculatorOperation, CalculatorStateChange, MacroState, OpArgs}; @@ -37,23 +36,23 @@ pub struct Calculator { #[serde(skip)] l: String, save_on_close: bool, - stack: VecDeque, + pub stack: VecDeque, #[serde(serialize_with = "ordered_char_map")] - macros: CalculatorMacros, + pub macros: CalculatorMacros, #[serde(skip)] active_macros: HashSet, #[serde(serialize_with = "ordered_char_map")] - constants: CalculatorConstants, + pub constants: CalculatorConstants, #[serde(skip)] - registers: CalculatorRegisters, + pub registers: CalculatorRegisters, #[serde(skip)] undo_buf: Vec, #[serde(skip)] redo_buf: Vec, #[serde(skip)] - state: CalculatorState, - angle_mode: CalculatorAngleMode, - display_mode: CalculatorDisplayMode, + pub state: CalculatorState, + pub angle_mode: CalculatorAngleMode, + pub display_mode: CalculatorDisplayMode, // calculator_alignment: CalculatorAlignment, } @@ -382,37 +381,12 @@ impl Calculator { pub fn get_status_line(&self) -> String { format!( "[{}] [{}] [{}]", - self.get_display_mode(), - self.get_angle_mode(), - if self.get_save_on_close() { "W" } else { "w" } + self.display_mode, + self.angle_mode, + if self.save_on_close { "W" } else { "w" } ) } - pub fn get_state(&self) -> &CalculatorState { - &self.state - } - pub fn get_constants_iter(&self) -> CalculatorConstantsIter { - self.constants.iter() - } - pub fn get_macros_iter(&self) -> CalculatorMacrosIter { - self.macros.iter() - } - pub fn get_registers_iter(&self) -> CalculatorRegistersIter { - self.registers.iter() - } - pub fn get_stack(&self) -> &VecDeque { - &self.stack - } - pub fn get_angle_mode(&self) -> &CalculatorAngleMode { - &self.angle_mode - } - pub fn get_display_mode(&self) -> &CalculatorDisplayMode { - &self.display_mode - } - pub fn get_save_on_close(&self) -> bool { - self.save_on_close - } - pub fn flush_l(&mut self) -> CalculatorResult { if self.l.is_empty() { Ok(false) diff --git a/src/calc/constants.rs b/src/calc/constants.rs index 34fd732..dffd2d0 100644 --- a/src/calc/constants.rs +++ b/src/calc/constants.rs @@ -1,5 +1,4 @@ use serde::{Deserialize, Serialize}; -use std::collections::hash_map::Iter; use std::collections::HashMap; use std::fmt; @@ -39,13 +38,10 @@ pub struct CalculatorMacro { } pub type CalculatorConstants = HashMap; -pub type CalculatorConstantsIter<'a> = Iter<'a, char, CalculatorConstant>; pub type CalculatorMacros = HashMap; -pub type CalculatorMacrosIter<'a> = Iter<'a, char, CalculatorMacro>; pub type CalculatorRegisters = HashMap; -pub type CalculatorRegistersIter<'a> = Iter<'a, char, f64>; #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(tag = "angle_mode")] diff --git a/src/main.rs b/src/main.rs index 6e44c26..3a0dcdd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,7 +65,7 @@ impl Default for App { } impl App { fn draw_clippy_dialogs(&mut self, f: &mut Frame>) { - match (&self.state, self.calculator.get_state()) { + match (&self.state, &self.calculator.state) { (AppState::Help, _) => { draw_clippy_rect( ClippyRectangle { @@ -99,7 +99,8 @@ impl App { title: "Constants", msg: self .calculator - .get_constants_iter() + .constants + .iter() .map(|(key, constant)| { format!("{}: {} ({})", key, constant.help, constant.value) }) @@ -119,7 +120,8 @@ impl App { title, msg: self .calculator - .get_registers_iter() + .registers + .iter() .map(|(key, value)| format!("{}: {}", key, value)) .fold(String::new(), |acc, s| acc + &s + "\n") .trim_end(), @@ -133,7 +135,8 @@ impl App { title: "Macros", msg: self .calculator - .get_macros_iter() + .macros + .iter() .map(|(key, mac)| format!("{}: {}", key, mac.help)) .fold(String::new(), |acc, s| acc + &s + "\n") .trim_end(), @@ -194,7 +197,7 @@ impl App { Span::styled("q", Style::default().add_modifier(Modifier::BOLD)), Span::raw(" to exit, "), Span::styled("h", Style::default().add_modifier(Modifier::BOLD)), - Span::raw(format!(" for help - {}", self.calculator.get_status_line(),)), + Span::raw(format!(" for help - {}", self.calculator.get_status_line())), ] } (None, _) => vec![ @@ -210,22 +213,22 @@ impl App { // Stack let mut stack: Vec = self .calculator - .get_stack() + .stack .iter() .take(chunks[1].height as usize - 2) .enumerate() .rev() .map(|(i, m)| { - let number = match self.calculator.get_display_mode() { + let number = match self.calculator.display_mode { CalculatorDisplayMode::Default => format!("{}", m), CalculatorDisplayMode::Separated { separator } => { - format::separated(*m, *separator) + format::separated(*m, separator) } CalculatorDisplayMode::Scientific { precision } => { - format::scientific(*m, *precision) + format::scientific(*m, precision) } CalculatorDisplayMode::Engineering { precision } => { - format::engineering(*m, *precision) + format::engineering(*m, precision) } CalculatorDisplayMode::Fixed { precision } => { format!("{:0>.precision$}", m, precision = precision) @@ -303,7 +306,7 @@ fn main() -> Result<(), Box> { } fn handle_key(app: &mut App, key: KeyEvent) -> CalculatorResult { - match (&app.state, app.calculator.get_state()) { + match (&app.state, &app.calculator.state) { (AppState::Calculator, CalculatorState::Normal) => match key { KeyEvent { code: KeyCode::Char('q'),