From e47e4bbb004e0a18a3e8611a7be730789afefa29 Mon Sep 17 00:00:00 2001 From: Nathaniel Clark Date: Tue, 18 Jun 2024 11:04:38 -0400 Subject: [PATCH] Add #about command and update copyright Add more tests to numbers.rs Signed-off-by: Nathaniel Clark --- Cargo.toml | 4 +++- src/fixtures/help.html | 6 ++++-- src/main.rs | 6 +++++- src/numbers.rs | 22 ++++++++++++++++++++-- src/stack.rs | 2 +- src/ui.rs | 13 ++++++++++++- src/ui/fltk.rs | 13 +++++++------ src/ui/readline.rs | 8 ++++++-- src/ui/tui.rs | 8 ++++++-- 9 files changed, 64 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 868acfc..69a05e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,12 @@ [package] name = "rpn-rs" version = "0.1.5" -authors = ["Nathaniel Clark "] +authors = ["Nathaniel Clark"] edition = "2021" keywords = [ "fltk", "rpn", "calculator", "tui" ] categories = [ "gui", "mathematics", "command-line-utilities" ] +license = "GPL-2.0-only" +readme = "README.md" [dependencies] clap = { version = "4", features = ["derive", "wrap_help"] } diff --git a/src/fixtures/help.html b/src/fixtures/help.html index c522d2c..0b31771 100644 --- a/src/fixtures/help.html +++ b/src/fixtures/help.html @@ -3,6 +3,7 @@ RPN-rs Graphical Reverse Polish Notation Calculator +

RPN-rs is a graphical reverse polish notation (RPN) calculator

@@ -35,8 +36,9 @@

RPN-rs is a graphical reverse polish notation (RPN) calculator

- - + + + diff --git a/src/main.rs b/src/main.rs index 4d882a9..24f4a5c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -/* RPN-rs (c) 2023 Nathaniel Clark +/* RPN-rs (c) 2024 Nathaniel Clark * * This source code is subject to the terms of the GPL v2. See LICENCE file. */ @@ -69,6 +69,10 @@ fn main() { ui.help(); Return::Noop } + "about" | "#about" => { + ui.about(); + Return::Noop + } // Stack Operations "undo" | "u" | "#undo" => { if stacks.len() > 2 { diff --git a/src/numbers.rs b/src/numbers.rs index cc7ba47..7a7d5a2 100644 --- a/src/numbers.rs +++ b/src/numbers.rs @@ -1,4 +1,4 @@ -/* RPN-rs (c) 2023 Nathaniel Clark +/* RPN-rs (c) 2024 Nathaniel Clark * * This source code is subject to the terms of the GPL v2. See LICENCE file. */ @@ -1692,7 +1692,25 @@ mod test { } #[test] - fn matrix_plus_one() { + fn value_lines() { + let a: Value = Matrix::from_vec( + 3, + 3, + [1, 2, 3, 4, 5, 6, 7, 8, 9] + .into_iter() + .map(Scalar::from) + .collect(), + ) + .unwrap() + .into(); + let one: Value = 1.into(); + + assert_eq!(a.lines(), 3); + assert_eq!(one.lines(), 1); + } + + #[test] + fn value_matrix_scaler_multiplication() { let a: Value = Matrix::from_vec( 3, 3, diff --git a/src/stack.rs b/src/stack.rs index e1ae23b..5ba53c4 100644 --- a/src/stack.rs +++ b/src/stack.rs @@ -1,4 +1,4 @@ -/* RPN-rs (c) 2023 Nathaniel Clark +/* RPN-rs (c) 2024 Nathaniel Clark * * This source code is subject to the terms of the GPL v2. See LICENCE file. */ diff --git a/src/ui.rs b/src/ui.rs index 9c6e905..3f4ea1f 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,4 +1,4 @@ -/* RPN-rs (c) 2023 Nathaniel Clark +/* RPN-rs (c) 2024 Nathaniel Clark * * This source code is subject to the terms of the GPL v2. See LICENCE file. */ @@ -12,6 +12,14 @@ pub mod tui; pub(crate) const HELP_HTML: &str = include_str!("fixtures/help.html"); +pub(crate) fn about_txt() -> String { + format!( + "RPN Calculator {} (c) 2024 {}", + env!("CARGO_PKG_VERSION"), + env!("CARGO_PKG_AUTHORS") + ) +} + #[derive(clap::ValueEnum, Default, Debug, Copy, Clone, strum_macros::Display, PartialEq)] #[clap(rename_all = "lower")] #[strum(serialize_all = "lowercase")] @@ -65,6 +73,9 @@ pub trait CalcDisplay { /// Show Help Text fn help(&mut self); + /// Show About Text + fn about(&mut self); + /// Cleanup and quit fn quit(&mut self); } diff --git a/src/ui/fltk.rs b/src/ui/fltk.rs index c206fe8..8cdd820 100644 --- a/src/ui/fltk.rs +++ b/src/ui/fltk.rs @@ -1,4 +1,4 @@ -/* RPN-rs (c) 2023 Nathaniel Clark +/* RPN-rs (c) 2024 Nathaniel Clark * * This source code is subject to the terms of the GPL v2. See LICENCE file. */ @@ -8,7 +8,7 @@ use crate::{ numbers::{Radix, Value}, - ui::{CalcDisplay, Message, HELP_HTML}, + ui::{about_txt, CalcDisplay, Message, HELP_HTML}, }; use copypasta::{ClipboardContext, ClipboardProvider}; use fltk::{ @@ -234,10 +234,7 @@ impl CalcDisplay for FltkCalcDisplay { self.table.set_rational(item.value()); self.table.redraw(); } - FltkMessage::About => self.dialog(format!( - "RPN Calculator {} (c) 2023", - env!("CARGO_PKG_VERSION") - )), + FltkMessage::About => self.about(), FltkMessage::Copy => { if let Err(e) = self .table @@ -284,6 +281,10 @@ impl CalcDisplay for FltkCalcDisplay { self.error.set_value(err.unwrap_or_default().as_str()); } + fn about(&mut self) { + self.dialog(about_txt()); + } + fn help(&mut self) { self.help.show(); } diff --git a/src/ui/readline.rs b/src/ui/readline.rs index 5b55542..f345c66 100644 --- a/src/ui/readline.rs +++ b/src/ui/readline.rs @@ -1,11 +1,11 @@ -/* RPN-rs (c) 2023 Nathaniel Clark +/* RPN-rs (c) 2024 Nathaniel Clark * * This source code is subject to the terms of the GPL v2. See LICENCE file. */ use crate::{ numbers::{Radix, Value}, - ui::{help_text, CalcDisplay, Message}, + ui::{about_txt, help_text, CalcDisplay, Message}, }; use rustyline::{error::ReadlineError, DefaultEditor}; @@ -112,6 +112,10 @@ impl CalcDisplay for ReadlineCalcUI { println!("{}", help_text(80)); } + fn about(&mut self) { + println!("{}", about_txt()); + } + /// Cleanup and quit fn quit(&mut self) {} } diff --git a/src/ui/tui.rs b/src/ui/tui.rs index 0f49bcb..c721baa 100644 --- a/src/ui/tui.rs +++ b/src/ui/tui.rs @@ -1,11 +1,11 @@ -/* RPN-rs (c) 2023 Nathaniel Clark +/* RPN-rs (c) 2024 Nathaniel Clark * * This source code is subject to the terms of the GPL v2. See LICENCE file. */ use crate::{ numbers::{Radix, Value}, - ui::{help_text, CalcDisplay, Message}, + ui::{about_txt, help_text, CalcDisplay, Message}, }; use crossterm::{ @@ -305,6 +305,10 @@ impl CalcDisplay for TuiCalcUI { } } + fn about(&mut self) { + self.info.error = Some(about_txt()); + } + /// Show Help Text fn help(&mut self) { self.info.help_popup = true;
CommandStack ConsumedDescriptionRepresentation
quit | exit | qN/AQuit application
help | ?N/ADisplay this help
(#)quit | (#)exit | qN/AQuit application
(#)help | ?N/ADisplay this help
(#)aboutN/ADisplay program copyright info
#binN/ASet display to Binary
#octN/ASet display to Octal
#decN/ASet display to Decimal