csvlens icon indicating copy to clipboard operation
csvlens copied to clipboard

Feature Request: Allow usage of csvlens as a library

Open benwbooth opened this issue 1 year ago • 4 comments

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!

benwbooth avatar Jun 24 '24 13:06 benwbooth

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.

YS-L avatar Jul 03 '24 17:07 YS-L

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!

benwbooth avatar Jul 08 '24 15:07 benwbooth

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.

YS-L avatar Jul 20 '24 10:07 YS-L

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

jqnatividad avatar Sep 10 '24 15:09 jqnatividad

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).

schwa avatar Sep 29 '24 16:09 schwa

@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.

jqnatividad avatar Jan 15 '25 11:01 jqnatividad

Indeed, let's close this issue now. Will open another issue for array of records support.

YS-L avatar Jan 15 '25 16:01 YS-L