Skip to content

Commit 4e7991b

Browse files
committed
feature to run one off computations instead of launching prompt
1 parent 98c9072 commit 4e7991b

File tree

4 files changed

+183
-11
lines changed

4 files changed

+183
-11
lines changed

Cargo.lock

Lines changed: 143 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "csc"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
edition = "2021"
55
authors = ["Zahash <zahash.z@gmail.com>"]
66
description = "Command Line Scientific Calculator"
@@ -10,6 +10,7 @@ repository = "https://github.com/zahash/csc"
1010
[dependencies]
1111
regex = { version = "1" }
1212
lazy_static = { version = "1" }
13+
clap = { version = "4", features = ["derive"] }
1314
rustyline = { version = "12" }
1415

1516
[dev-dependencies]

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
<div align="center">
22

3-
# csc
3+
<pre>
4+
██████╗███████╗ ██████╗
5+
██╔════╝██╔════╝██╔════╝
6+
██║ ███████╗██║
7+
██║ ╚════██║██║
8+
╚██████╗███████║╚██████╗
9+
╚═════╝╚══════╝ ╚═════╝
10+
------------------------
11+
Command Line Scientific Calculator. Free Forever. Made with ❤️ using 🦀
12+
</pre>
413

514
[![Crates.io](https://img.shields.io/crates/v/csc.svg)](https://crates.io/crates/csc)
615
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
716

817
</div>
918

10-
> Command Line Scientific Calculator.
11-
1219
## Download
1320

1421
[https://github.com/zahash/csc/releases](https://github.com/zahash/csc/releases)
1522

23+
( or )
24+
25+
```
26+
cargo install csc
27+
```
28+
1629
## Usage examples
1730

1831
```sh
@@ -36,4 +49,3 @@ Distributed under the MIT license. See `LICENSE` for more information.
3649
3. Commit your changes (`git commit -am 'Add some fooBar'`)
3750
4. Push to the branch (`git push origin feature/fooBar`)
3851
5. Create a new Pull Request
39-

src/prompt.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
use crate::eval::*;
22

3+
use clap::Parser;
34
use rustyline::error::ReadlineError;
45

56
const LOGO: &'static str = r#"
6-
███████ ██████ ██ █████ █████ ██ ██████
7-
██ ██ ██ ██ ██ ██ ██ ██
8-
███████ ██ ██ ██ ███████ ██ ██
9-
██ ██ ██ ██ ██ ██ ██ ██
10-
███████ ██████ ██ ██████ ██ ██ ███████ ██████
7+
██████ ███████ █████
8+
██ ██ ██
9+
██ ███████ ██
10+
██ ██ ██
11+
██████ ███████ ██████
1112
"#;
1213

14+
/// CSC
15+
#[derive(Parser)]
16+
struct Cli {
17+
/// run one off computations instead of launching the prompt
18+
expr: Option<Vec<String>>,
19+
}
20+
1321
pub fn run() {
22+
if let Some(expr) = Cli::parse().expr {
23+
let expr = expr.join(" ");
24+
match eval(expr.as_str(), &mut State::new()) {
25+
Ok(res) => println!("{}", res),
26+
Err(e) => eprintln!("{:?}", e),
27+
}
28+
return;
29+
}
30+
1431
println!("{}", LOGO);
1532
println!(env!("CARGO_PKG_VERSION"));
1633

0 commit comments

Comments
 (0)