changed equals sign (=) for string and boolean operations to use fat arrow (=>) and "is" respectively.
This commit is contained in:
parent
b30a199ceb
commit
c575e0bf4d
1 changed files with 26 additions and 25 deletions
51
src/main.rs
51
src/main.rs
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue