initial build & commit
This commit is contained in:
commit
e195668eb8
4 changed files with 138 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target
|
65
Cargo.lock
generated
Normal file
65
Cargo.lock
generated
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "1.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "evalexpr"
|
||||||
|
version = "7.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1d4fd7bd9e32c1205549decf6f36772d7b606a579b26afaffa335ae148151a5d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.126"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "numtoa"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quickmaths"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"evalexpr",
|
||||||
|
"termion",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "redox_syscall"
|
||||||
|
version = "0.2.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "redox_termios"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f"
|
||||||
|
dependencies = [
|
||||||
|
"redox_syscall",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "termion"
|
||||||
|
version = "1.5.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"numtoa",
|
||||||
|
"redox_syscall",
|
||||||
|
"redox_termios",
|
||||||
|
]
|
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[package]
|
||||||
|
name = "quickmaths"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
evalexpr = "7.2.0"
|
||||||
|
termion = "1.5.6"
|
62
src/main.rs
Normal file
62
src/main.rs
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
use std::{env, io::stdin};
|
||||||
|
|
||||||
|
use evalexpr::{
|
||||||
|
//context_map,
|
||||||
|
eval_with_context_mut,
|
||||||
|
|
||||||
|
ContextWithMutableVariables,
|
||||||
|
HashMapContext,
|
||||||
|
Value,
|
||||||
|
};
|
||||||
|
use termion::{color, style};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
//let mut context = context_map! {}.unwrap();
|
||||||
|
let mut context = HashMapContext::new();
|
||||||
|
let expressions: Vec<String> = env::args().skip(1).collect();
|
||||||
|
if expressions.len() == 0 {
|
||||||
|
loop {
|
||||||
|
let mut i_line = String::new();
|
||||||
|
let line_result = stdin().read_line(&mut i_line);
|
||||||
|
if line_result.is_err() { break; }
|
||||||
|
let line = i_line.trim().to_string();
|
||||||
|
if line.is_empty() { break; }
|
||||||
|
let result = do_eval(line, &mut context);
|
||||||
|
println!("{}{}{}", result.0, color::Fg(color::Reset), style::Reset);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for expression in expressions {
|
||||||
|
let result = do_eval(expression, &mut context);
|
||||||
|
println!("{}{}{}", result.0, color::Fg(color::Reset), style::Reset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn do_eval(i_expression: String, context: &mut HashMapContext) -> (String, Option<Value>) {
|
||||||
|
let expression = i_expression.as_str();
|
||||||
|
let i_result = eval_with_context_mut(expression, context);
|
||||||
|
if i_result.is_err() {
|
||||||
|
return (
|
||||||
|
format!("{}🞪 {}{}", color::Fg(color::Red), style::Bold, expression),
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let result = i_result.ok().unwrap();
|
||||||
|
if result.is_empty() {
|
||||||
|
return (
|
||||||
|
format!("{}✓ {}{}", color::Fg(color::Green), style::Bold, expression),
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
format!(
|
||||||
|
"{}{}{}{} = {}",
|
||||||
|
style::Faint,
|
||||||
|
style::Italic,
|
||||||
|
expression,
|
||||||
|
style::Reset,
|
||||||
|
result
|
||||||
|
),
|
||||||
|
Some(result),
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in a new issue