Good day, dear habraklyudi! It just so happened that on duty I had to write a console application (menu) to solve the pressing problems associated with database migrations (and not only migrations, but also with a different, different type, service). At once I will make a reservation that I will not speak about migrants under the cut! The development is conducted in the Python language, so the untranslatable wordplay with the use of national dialects follows.
The current work of a colleague was a
plasticine ball of tightly knit and intertwined parts. Therefore, I couldn’t change, supplement or at least understand anything in that code, so I decided to rewrite this balalaika, having previously divided the architectural components. I went to the Network to search for a python-framework for building console menus. Searches were not crowned with success - there were simply no web frameworks for building at least a little bit of usable menus. But I found two "almost candidates":
cliff doesn’t quite match my needs. This is not a console menu, in fact, but simply an interactive session (command line) in which it is possible to enter commands manually and enjoy auto-completion. Not that.
console does not correspond to the desires at all. this
the same cheese, but with a different sauce
Moreover, more than raw. Sorry for taftalogiya.
I, in fact, decided to start by writing a couple of classes to draw the console menu (the rendering base was helpfully provided to me by the
cmd2 module, which, as a result, is required to work with my little
xmenu ). Actually there are no tricks to implement. Three classes, korutina for storing history - that's the whole story. This is a mini-framework. Please do not start spitting immediately, because I urge you to know that this is a
pre-alpha version. And you can pick up and watch xmenu on a
githaba . And those who do not want to understand the missing documentation (so far, missing), publish an example of client code here:
It turns out like this:

This is an absolutely chaotic menu - do not judge by filling.
So xmenu provides:
- Menu infinite nesting (menus are embedded in the menu)
- Coloring menu items
- The ability to walk back in history (in the future, maybe I will go and go)
- On the menu items you can hang any callable objects.
- Xmenu automatically collects docks from all objects and aggregates them in one menu - help.
I am not so active in the open software movement, but I promise to move in this direction, I will develop and complement this tool. Thanks to all who read to this proposal, and
special thanks to those who tested, expressed their wishes and highlighted my flaws. And he sees Habr, perhaps I have not tried in vain, because this is my first article and I'm just learning to be a habrachelok.
UPD: the version has been updated - write down see on
githab