- // loop until a blank line is received
- loop {
- expr.clear ();
- print!("{}", "evpf>".bold() );
- io::stdout().flush ().expect (ERR_FLUSHING);
- // read a line of text
- io::stdin().read_line (&mut expr).expect (ERR_READING_LINE);
- // trim the text
- let expr = expr.trim ();
-
- if expr == "q" || expr == "Q" {
- // quit if the expression is q or Qs
- break;
- } else if expr == "?" || expr == "h" || expr == "H" {
- // display help text
- for text in HELP_TEXT.iter() {
- println! ("{}", text.cyan() );
- }
-
- continue;
- } else if expr == "" {
- // continue without proceeding
- continue;
- }
-
- // Evaluate result
- let res = evaluate (&expr, &match_num);
-
- // if Result is OK then print the result in green
- if res.is_ok () {
- let restxt = format! ("{}: {}", RESULT,
- res.unwrap());
- println! ("{}", restxt.green ());
- } else {
- // print the error in purple
- let errtxt = format! ("{}: {}", ERROR,
- res.unwrap_err());
- eprintln! ("{}", errtxt.purple());
- eprintln! ("{}", ERROR_HELP.purple());
- }
- }