Skip to content

Commit

Permalink
Add #about command and update copyright
Browse files Browse the repository at this point in the history
Add more tests to numbers.rs

Signed-off-by: Nathaniel Clark <Nathaniel.Clark@misrule.us>
  • Loading branch information
utopiabound committed Jun 18, 2024
1 parent 90d7789 commit e47e4bb
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 18 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[package]
name = "rpn-rs"
version = "0.1.5"
authors = ["Nathaniel Clark <Nathaniel.Clark@misrule.us>"]
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"] }
Expand Down
6 changes: 4 additions & 2 deletions src/fixtures/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<html>
<head>
<title>RPN-rs Graphical Reverse Polish Notation Calculator</title>
<meta name="author" content="Nathaniel Clark" />
</head>
<body>
<h1>RPN-rs is a graphical reverse polish notation (RPN) calculator</h1>
Expand Down Expand Up @@ -35,8 +36,9 @@ <h1>RPN-rs is a graphical reverse polish notation (RPN) calculator</h1>

<table>
<tr><th align="left">Command</th><th align="left">Stack Consumed</th><th align="left">Description</th><th>Representation</th></tr>
<tr><td>quit | exit | q</td><td><i>N/A</i></td><td colspan=2>Quit application</td></tr>
<tr><td>help | ?</td><td><i>N/A</i></td><td colspan=2>Display this help</td></tr>
<tr><td>(#)quit | (#)exit | q</td><td><i>N/A</i></td><td colspan=2>Quit application</td></tr>
<tr><td>(#)help | ?</td><td><i>N/A</i></td><td colspan=2>Display this help</td></tr>
<tr><td>(#)about</td><td><i>N/A</i></td><td colspan=2>Display program copyright info</td></tr>
<tr><td>#bin</td><td><i>N/A</i></td><td colspan=2>Set display to <a href="https://en.wikipedia.org/wiki/Binary_number">Binary</a></td></tr>
<tr><td>#oct</td><td><i>N/A</i></td><td colspan=2>Set display to <a href="https://en.wikipedia.org/wiki/Octal">Octal</a></td></tr>
<tr><td>#dec</td><td><i>N/A</i></td><td colspan=2>Set display to <a href="https://en.wikipedia.org/wiki/Decimal">Decimal</a></td></tr>
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand Down Expand Up @@ -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 {
Expand Down
22 changes: 20 additions & 2 deletions src/numbers.rs
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/stack.rs
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand Down
13 changes: 12 additions & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand All @@ -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")]
Expand Down Expand Up @@ -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);
}
Expand Down
13 changes: 7 additions & 6 deletions src/ui/fltk.rs
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand All @@ -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::{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down
8 changes: 6 additions & 2 deletions src/ui/readline.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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) {}
}
8 changes: 6 additions & 2 deletions src/ui/tui.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e47e4bb

Please sign in to comment.