loony-bean / textplots-rs

Terminal plotting library for Rust
238 stars 24 forks source link

Add binary to the crate (#20) #27

Closed micouy closed 3 years ago

micouy commented 3 years ago

This PR adds a binary of the same name to the crate. It introduces a breaking change in the API. Resolves #21, resolves #20.

Changes

Behavior

Basic usage (prints the formula and displays the plot)

$ textplots 'e ^ (1 / x)'

Error info on no formula

$ textplots
error: The following required arguments were not provided:
    <FORMULA>

USAGE:
    textplots <FORMULA>

For more information try --help

--help

$ textplots --help
textplots 0.6.0
Alexey Suslov <alexey.suslov@gmail.com>
Terminal plotting library.

USAGE:
    textplots <FORMULA>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <FORMULA>    Formula to plot

Error info on unknown variable

$ textplots 'y'
Evaluation error: unknown variable `y`.

Error on unexpected token

$ textplots `100x`
Parse error: Unexpected token at byte 3.

Possible future development

loony-bean commented 3 years ago

Hi @micouy! I really like what you did, and the write-up is excellent. Thank you ❤️ I'd like to get this merged and see how people might use it.

Do you think you can make it compatible with stable Rust before we go on?

micouy commented 3 years ago

You mean the box syntax? Sure thing, I can change it to Box::new. What about the no_std thing? I could change Continous(Box<dyn Fn + 'a>) to Continous(&'a dyn Fn) so as not to introduce more allocations, the enum already has the lifetime parameter. Since you're already breaking the API, you could also change it to use traits and move drawing logic to the shapes. Then you could merge my changes with the no_std update but that would probably take ages without more contributors.

loony-bean commented 3 years ago

I'm fine with dropping no_std support idea. I'm not yet sure there is a lot of utility in a library like that on embedded device.

micouy commented 3 years ago

Done. I've added one example with box syntax in README.md and in src/lib.rs. Just remove them if you do not wish them to be there. Remember to say something about the binary in README.md. I also suggest adding a small demo.