added version line to interpreter mode and bumped version
This commit is contained in:
parent
e66cd08374
commit
b30a199ceb
3 changed files with 30 additions and 15 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -28,7 +28,7 @@ checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quickmaths"
|
name = "quickmaths"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"evalexpr",
|
"evalexpr",
|
||||||
"termion",
|
"termion",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "quickmaths"
|
name = "quickmaths"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
41
src/main.rs
41
src/main.rs
|
@ -1,13 +1,6 @@
|
||||||
use std::{env, io::stdin};
|
use std::{env, io::stdin};
|
||||||
|
|
||||||
use evalexpr::{
|
use evalexpr::{eval_with_context_mut, HashMapContext, Value};
|
||||||
//context_map,
|
|
||||||
eval_with_context_mut,
|
|
||||||
|
|
||||||
ContextWithMutableVariables,
|
|
||||||
HashMapContext,
|
|
||||||
Value,
|
|
||||||
};
|
|
||||||
use termion::{color, style};
|
use termion::{color, style};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -15,12 +8,17 @@ fn main() {
|
||||||
let mut context = HashMapContext::new();
|
let mut context = HashMapContext::new();
|
||||||
let expressions: Vec<String> = env::args().skip(1).collect();
|
let expressions: Vec<String> = env::args().skip(1).collect();
|
||||||
if expressions.len() == 0 {
|
if expressions.len() == 0 {
|
||||||
|
println!("{}quickmaths v0.1.1{}", style::Bold, style::Reset);
|
||||||
loop {
|
loop {
|
||||||
let mut i_line = String::new();
|
let mut i_line = String::new();
|
||||||
let line_result = stdin().read_line(&mut i_line);
|
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();
|
let line = i_line.trim().to_string();
|
||||||
if line.is_empty() { break; }
|
if line.is_empty() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
let result = do_eval(line, &mut context);
|
let result = do_eval(line, &mut context);
|
||||||
println!("{}{}{}", result.0, color::Fg(color::Reset), style::Reset);
|
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 expression = i_expression.as_str();
|
||||||
let i_result = eval_with_context_mut(expression, context);
|
let i_result = eval_with_context_mut(expression, context);
|
||||||
if i_result.is_err() {
|
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();
|
let result = i_result.ok().unwrap();
|
||||||
if result.is_empty() {
|
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),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue