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]]
|
||||
name = "quickmaths"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"evalexpr",
|
||||
"termion",
|
||||
|
|
|
@ -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
|
||||
|
|
41
src/main.rs
41
src/main.rs
|
@ -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),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue