diff --git a/Cargo.toml b/Cargo.toml index 65064ff..5df8849 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "feval" -version = "0.4.1" +version = "0.4.2" edition = "2021" description = "clt for fast evaluations" readme = "README.md" @@ -10,3 +10,4 @@ authors = ["Ivan ivabus Bushchik"] [dependencies] evalexpr = "10.0.0" +linefeed = "0.6.0" diff --git a/src/main.rs b/src/main.rs index 8da748a..168ebb8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use std::{ use evalexpr; use evalexpr::HashMapContext; +use linefeed::{Interface, ReadResult}; use crate::tasks::tasks::all; @@ -19,19 +20,15 @@ example: feval "math::sin(30 * math::pi / 180)""# } fn main_loop() { - print!(">>> "); - stdout().flush().unwrap(); - let mut input = String::new(); + let mut reader = Interface::new("feval").unwrap(); + reader.set_prompt(">>> ").unwrap(); let mut context = HashMapContext::new(); - while stdin().read_line(&mut input).unwrap() != 0 { + while let ReadResult::Input(input) = reader.read_line().unwrap() { let result = evalexpr::eval_with_context_mut(&all(input.trim().to_string()), &mut context); match result { Ok(succ_res) => println!("{}", succ_res), Err(err) => println!("Error: {}", err), } - input.clear(); - print!(">>> "); - stdout().flush().unwrap(); } }