Feature Request: Allow usage of csvlens as a library
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!
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.
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!
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.
Just wanted to share that I integrated csvlens with qsv 0.134.0 and it works like a charm! https://github.com/jqnatividad/qsv/releases/tag/0.134.0
As an extension to this - it would be amazing if it could work with an array of records (like the way https://docs.rs/csv/latest/csv/ works with serde structs).
@benwbooth, @YS-L perhaps, we should close this now that csvlens can be used as a library.
And @schwa can open another issue with his request for array of records support.
Indeed, let's close this issue now. Will open another issue for array of records support.