interactive cli menu module for python
Creating interactive cli utilities has never been easier! With menu you can, within four lines of code, create your own arrow-keys controlled any-purpose menu.
from menoo import Menu
def print_choice(i):
print i
menu = Menu(title='do you want to build a snowman?')
menu.add_option('yes', print_choice)
menu.add_option('no', print_choice)
menu.start()
Menu(title='', cursor='>>', fullscreen=False)
instantiates a new Menu object, but does not start it yet,
with the following optional parameters:
title
- displayed above the list of optionscursor
- displayed near the selected optionfullscreen
- will clear screen prior to rendering the menu
Menu.add_option(text, handler)
adds a new entry to the list of options
text
- the text to displayhandler
- a function which receives a single integer as its first positional argument, representing the index of the selected option. the function can vary between options.
Menu.start()
starts the menu and enters the menu loop. blocks the program until an option has been chosen
Menu.stop()
will stop the menu loop on its next iteration
$ pip install menoo