pmbarrett314 / curses-menu

A simple console menu system in python using the curses library
MIT License
471 stars 55 forks source link

Allow to call a menu and return the selected value #30

Closed Kos closed 2 years ago

Kos commented 7 years ago

Hi,

I'm working on a library for Curses menus. Here's a handful of basic premises:

What I've been working on...

1) A menu definition is just a sequence of strings and Selections.

The selections can be aligned on the screen in any way (horizontally, vertically or both), which allows things like:

Available branches:

- Foo [remove] [rename]
- Quux [remove] [rename]

[Add new]

There's 2D navigation possible.

2) Menus can be easily defined using a bunch of helper methods, from strings or objects

menu = from_string('''
How are you doing?
    [Great] [Okay] [Meh]
''')

or:

selections = [
    Selection(value=True, label='yes'),
    Selection(value=False, label='no'),
]
menu = from_args('''
    Are you sure?
       {}
       {}
''', *selections)

3) You can ask a GUI for a selection from a menu and get the answer directly:

with GUI() as gui:
    value = gui.select(from_string('Are you sure? [yes] [no]'))
print 'You have selected', value

This is a variation of the "immediate mode GUI" concept.

4) Selections can be plain values that are returned, or functions that are called when selected (and functions are returned), or they could trigger sub-menus.

What I'm proposing

I have a working prototype implemented, but there's much more to do (documentation, tests, also nested menus, text inputs...)

My original idea was to create a new library on PyPI, but now I wonder if it would maybe make sense to extend your project with my ideas, while keeping the API compatible for your existing users?

Would you be interested in converging our approaches to one library? What would be your advice to me at this point?

PS this is my prototype if you'd like to have a look: https://github.com/Kos/console-menu

Cheers and best,

pmbarrett314 commented 2 years ago

I hope you enjoyed and learned from your project, it looks like you haven't touched it in a while. I'm just going through and clearing up some old issues after finally getting around to some cleanup I wanted to do on this project. This is kind of an off-and-on project for me, so it's difficult for me to commit to any specific collaborations. It looks like your approach is very different from mine, if you did ever come back to it I don't think there would be any harm in having two similar libraries on pypi with different approaches.