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]
|
||||
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"
|
||||
|
|
11
src/main.rs
11
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue