0.4.2: Use linefeed for input in shell mode.

Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
Ivan Bushchik 2023-06-04 09:54:23 +03:00
parent 4d2e302389
commit 2c669375c8
No known key found for this signature in database
GPG key ID: 9F6DDABE11A2674D
2 changed files with 6 additions and 8 deletions

View file

@ -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"

View file

@ -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();
}
}