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

Move most of the logic from main into functions? #19

Open
kaushalmodi opened this issue Jun 13, 2019 · 4 comments
Open

Move most of the logic from main into functions? #19

kaushalmodi opened this issue Jun 13, 2019 · 4 comments

Comments

@kaushalmodi
Copy link

Hello,

I am using the Nim language (https://nim-lang.org) which interfaces with C language seamlessly.

I'd like to use your project as a library where the input is a pointer to array of strings (and all the smenu options) and output is an another pointer to an array of strings.

Would it be possible for you to pack the core of smenu into such function whose API you provide via smenu.h?

In main, you then probably just parse the command line switches and pass the appropriate args to the smenu function.

Thoughts?


PS: I started with wrapping the smenu.h here, but then realized that I cannot do much with it as most of the smenu code is inline in the main.

To use smenu via Nim, I'd then need to literally translate all the C code to Nim manually.

@p-gen
Copy link
Owner

p-gen commented Jun 13, 2019

Hello,

Thank you for your interest in smenu. smenu is indeed not very modular and I am working to improve this point.

Regarding your need, smenu was designed as an interactive filter that can be used in a pipeline and not as a library of functions. Why not use it like that by applying the unix philosophy?

@kaushalmodi
Copy link
Author

kaushalmodi commented Jun 13, 2019

I am working on a project that generates a list of options, and then user is interactively asked to pick one or more of those options and then my project further processes those options.

I can do something like myproj -sw1 | smenu -sw1 -sw2 -sw3 | myproj -sw2. But I would like to make the UI easier and have the user do just myproj -sw1.

The idea is that I strictly control how smenu is called inside myproj.

The best way would be to get an smenu function from your project that I can call using the switches I decide.

Plan B would be to do a shell call from within myproj and call the smenu binary.


Proposed API for smenu function if you are interested in implementing it:

Inputs

  • pointer to array of input strings
  • boolean/int/etc. options to smenu (the CLI switches and their values will translate to these args)

Outputs

  • pointer to array of output strings

@p-gen
Copy link
Owner

p-gen commented Jun 13, 2019

I'll think about the interest of an evolution for such a use case. For now, simply choose Plan B.

@kaushalmodi
Copy link
Author

kaushalmodi commented Jun 13, 2019

Ok, thanks for considering this proposal.

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

2 participants