smenu
smenu copied to clipboard
Move most of the logic from main into functions?
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.
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?
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
I'll think about the interest of an evolution for such a use case. For now, simply choose Plan B.
Ok, thanks for considering this proposal.