added version line to interpreter mode and bumped version

This commit is contained in:
Valerie Wolfe 2022-06-08 21:17:13 -04:00
parent e66cd08374
commit b30a199ceb
3 changed files with 30 additions and 15 deletions

2
Cargo.lock generated
View file

@ -28,7 +28,7 @@ checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
[[package]]
name = "quickmaths"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"evalexpr",
"termion",

View file

@ -1,6 +1,6 @@
[package]
name = "quickmaths"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -1,13 +1,6 @@
use std::{env, io::stdin};
use evalexpr::{
//context_map,
eval_with_context_mut,
ContextWithMutableVariables,
HashMapContext,
Value,
};
use evalexpr::{eval_with_context_mut, HashMapContext, Value};
use termion::{color, style};
fn main() {
@ -15,12 +8,17 @@ fn main() {
let mut context = HashMapContext::new();
let expressions: Vec<String> = env::args().skip(1).collect();
if expressions.len() == 0 {
println!("{}quickmaths v0.1.1{}", style::Bold, style::Reset);
loop {
let mut i_line = String::new();
let line_result = stdin().read_line(&mut i_line);
if line_result.is_err() { break; }
if line_result.is_err() {
break;
}
let line = i_line.trim().to_string();
if line.is_empty() { break; }
if line.is_empty() {
break;
}
let result = do_eval(line, &mut context);
println!("{}{}{}", result.0, color::Fg(color::Reset), style::Reset);
}
@ -36,11 +34,28 @@ fn do_eval(i_expression: String, context: &mut HashMapContext) -> (String, Optio
let expression = i_expression.as_str();
let i_result = eval_with_context_mut(expression, context);
if i_result.is_err() {
return (format!("{}🞪 {}{}", color::Fg(color::Red), style::Bold, expression), None);
return (
format!("{}🞪 {}{}", color::Fg(color::Red), style::Bold, expression),
None,
);
}
let result = i_result.ok().unwrap();
if result.is_empty() {
return (format!("{}{}{}", color::Fg(color::Green), style::Bold, expression), None);
return (
format!("{}{}{}", color::Fg(color::Green), style::Bold, expression),
None,
);
}
return (format!("{}{}{}{} = {}{}", style::Faint, style::Italic, expression, style::Reset, style::Bold, result), Some(result));
return (
format!(
"{}{}{}{} = {}{}",
style::Faint,
style::Italic,
expression,
style::Reset,
style::Bold,
result
),
Some(result),
);
}