Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
benwbooth opened this issue Jun 24, 2024 · 5 comments
Open

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

benwbooth opened this issue Jun 24, 2024 · 5 comments

Comments

@benwbooth
Copy link

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
Copy link
Owner

YS-L commented Jul 3, 2024

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
Copy link
Author

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
Copy link
Owner

YS-L commented Jul 20, 2024

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.

@jqnatividad
Copy link
Contributor

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

@schwa
Copy link

schwa commented Sep 29, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants