changed equals sign (=) for string and boolean operations to use fat arrow (=>) and "is" respectively.

This commit is contained in:
Valerie Wolfe 2022-06-09 13:37:56 -04:00
parent b30a199ceb
commit c575e0bf4d

View file

@ -1,14 +1,25 @@
use std::{env, io::stdin};
use std::{
env,
io::stdin
};
use evalexpr::{eval_with_context_mut, HashMapContext, Value};
use termion::{color, style};
use evalexpr::{
eval_with_context_mut,
HashMapContext,
Value,
ValueType
};
use termion::{
color,
style
};
fn main() {
//let mut context = context_map! {}.unwrap();
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);
println!("{}quickmaths v0.1.1{}\n{}Interactive Mode{}", style::Bold, style::Reset, style::Faint, style::Reset);
loop {
let mut i_line = String::new();
let line_result = stdin().read_line(&mut i_line);
@ -34,28 +45,18 @@ 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),
);
let delimiter;
match result {
Value::Boolean(_bool) => delimiter = "is",
Value::String(ref _str) => delimiter = "=>",
_ => delimiter = "="
}
return (format!("{}{}{}{} {} {}{}", style::Faint, style::Italic, expression, style::Reset, delimiter, style::Bold, result), Some(result));
}