YS-L / csvlens

Command line csv viewer
MIT License
2.47k stars 41 forks source link

Feature Request: Allow usage of csvlens as a library #90

Open benwbooth opened 2 months ago

benwbooth commented 2 months ago

I would like to be able to use csvlens as a library to integrate into one of my tools. If I add csvlens = "*" to my Cargo.toml, I get the following warning:

warning: archive2tape v1.0.0 (/home/bbooth/src/archive2tape) ignoring invalid dependency `csvlens` which is missing a lib target

Is it possible to add a lib target to csvlens so that it can be used as a library?

Thanks!

YS-L commented 1 month ago

Sure. I'm curious how would you like to use csvlens as a library? The way csvlens is written now is very much an application, but if there's a way it can be useful as a library I'm happy to help.

benwbooth commented 1 month ago

Sure. I want to be able to display paged CSV table in my application. It would be sufficient to be able to fork/exec my process and call the main function of csvlens directly. Thanks!

YS-L commented 1 month ago

I added a lib.rs in the main branch to expose the function that the binary's main would call. It can be used this way:

use csvlens::run_csvlens;

let out = run_csvlens(&["/path/to/your.csv", "--delimiter", "\t"]).unwrap();
if let Some(selected_cell) = out {
    println!("Selected: {}", selected_cell);
}

Feel free to try it and let me know if it works in your case.