main.rs: add formatting to shell mode and edit help message

Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
Ivan Bushchik 2023-02-03 15:47:26 +03:00
parent aa996ec3ef
commit 96e88f02fa
No known key found for this signature in database
GPG key ID: 9F6DDABE11A2674D

View file

@ -1,10 +1,13 @@
use evalexpr;
use std::{env::args, io::{stdin, stdout, Write}};
mod tasks;
use evalexpr;
use crate::tasks::tasks::all;
mod tasks;
fn help() {
println!(r#"feval: evaluate expressions
println!(r#"feval: help
usage: provide exactly one argument (with expression) or no arguments for shell mode.
example: feval "math::sin(30 * math::pi / 180)""#);
}
@ -14,7 +17,7 @@ fn main_loop() {
stdout().flush().unwrap();
let mut input = String::new();
while stdin().read_line(&mut input).unwrap() != 0 {
let result = evalexpr::eval(&input.trim());
let result = evalexpr::eval(&all(input.trim().to_string()));
match result {
Ok(succ_res) => println!("{}", succ_res),
Err(err) => println!("Error: {}", err)
@ -33,7 +36,10 @@ fn main() {
let result = evalexpr::eval(&expr.trim());
match result {
Ok(succ_res) => println!("{}", succ_res),
Err(err) => println!("Error: {}", err)
Err(err) => {
println!("Error: {}", err);
std::process::exit(127);
}
}
},
1 => {main_loop()},
@ -41,11 +47,9 @@ fn main() {
if args.len() > 2 {
println!("Too many args.");
help();
return
} else if args.len() < 1 {
println!("Too few args.");
help();
return
}
}
}