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 evalexpr::{
use termion::{color, style}; eval_with_context_mut,
HashMapContext,
Value,
ValueType
};
use termion::{
color,
style
};
fn main() { fn main() {
//let mut context = context_map! {}.unwrap();
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); println!("{}quickmaths v0.1.1{}\n{}Interactive Mode{}", style::Bold, style::Reset, style::Faint, 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);
@ -34,28 +45,18 @@ 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 ( return (format!("{}🞪 {}{}", color::Fg(color::Red), style::Bold, expression), None);
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 ( return (format!("{}{}{}", color::Fg(color::Green), style::Bold, expression), None);
format!("{}{}{}", color::Fg(color::Green), style::Bold, expression),
None,
);
} }
return ( let delimiter;
format!( match result {
"{}{}{}{} = {}{}", Value::Boolean(_bool) => delimiter = "is",
style::Faint, Value::String(ref _str) => delimiter = "=>",
style::Italic, _ => delimiter = "="
expression, }
style::Reset, return (format!("{}{}{}{} {} {}{}", style::Faint, style::Italic, expression, style::Reset, delimiter, style::Bold, result), Some(result));
style::Bold,
result
),
Some(result),
);
} }