From c575e0bf4dff184939f4eba1ff73d5260d069707 Mon Sep 17 00:00:00 2001 From: Valerie Date: Thu, 9 Jun 2022 13:37:56 -0400 Subject: [PATCH] changed equals sign (=) for string and boolean operations to use fat arrow (=>) and "is" respectively. --- src/main.rs | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4eda91b..05c4dd0 100644 --- a/src/main.rs +++ b/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 = 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)); } +