+ // 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! ("{}", 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());
+ }
+ }
+ // save the history
+ let hist_file = get_history_file ();
+ if ! hist_file.is_err () {
+ if rl.save_history (&hist_file.unwrap()).is_err () {
+ eprintln! ("{}", SAVE_HISTORY_ERROR);
+ }
+ } else {
+ eprintln! ("{}", &hist_file.unwrap_err());
+ }
+}
+
+fn main() {
+ // collect the command line arguments - if any
+ let args : Vec<String> = env::args().collect ();
+ // regular expression to match a number
+ let match_num = Regex::new (r"^\-?\d+?\.*?\d*?$").unwrap ();
+
+ if args.len () > 1 {
+ // if arguments are provided run in command line mode - i.e. print the
+ // result and exit
+ run_command_line (&args, &match_num);
+
+ } else {
+ // if arguments are not provided run in interactive mode -
+ // display a prompt and get the expression
+ // repeat until the user quits
+ run_interactive_mode (&match_num);
+