mirror of
https://github.com/ivabus/feval
synced 2024-12-04 20:55:06 +03:00
0.4.2: Use linefeed for input in shell mode.
Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
parent
4d2e302389
commit
2c669375c8
2 changed files with 6 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "feval"
|
name = "feval"
|
||||||
version = "0.4.1"
|
version = "0.4.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "clt for fast evaluations"
|
description = "clt for fast evaluations"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -10,3 +10,4 @@ authors = ["Ivan ivabus Bushchik"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
evalexpr = "10.0.0"
|
evalexpr = "10.0.0"
|
||||||
|
linefeed = "0.6.0"
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -5,6 +5,7 @@ use std::{
|
||||||
|
|
||||||
use evalexpr;
|
use evalexpr;
|
||||||
use evalexpr::HashMapContext;
|
use evalexpr::HashMapContext;
|
||||||
|
use linefeed::{Interface, ReadResult};
|
||||||
|
|
||||||
use crate::tasks::tasks::all;
|
use crate::tasks::tasks::all;
|
||||||
|
|
||||||
|
@ -19,19 +20,15 @@ example: feval "math::sin(30 * math::pi / 180)""#
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main_loop() {
|
fn main_loop() {
|
||||||
print!(">>> ");
|
let mut reader = Interface::new("feval").unwrap();
|
||||||
stdout().flush().unwrap();
|
reader.set_prompt(">>> ").unwrap();
|
||||||
let mut input = String::new();
|
|
||||||
let mut context = HashMapContext::new();
|
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);
|
let result = evalexpr::eval_with_context_mut(&all(input.trim().to_string()), &mut context);
|
||||||
match result {
|
match result {
|
||||||
Ok(succ_res) => println!("{}", succ_res),
|
Ok(succ_res) => println!("{}", succ_res),
|
||||||
Err(err) => println!("Error: {}", err),
|
Err(err) => println!("Error: {}", err),
|
||||||
}
|
}
|
||||||
input.clear();
|
|
||||||
print!(">>> ");
|
|
||||||
stdout().flush().unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue