Simple Terminal Menu

1.6.6 · active · verified Sun Apr 12

simple-term-menu is a Python package that facilitates the creation of interactive command-line menus. It enables users to select options using arrow keys, j/k (Vim motions), or emacs keys. The library intelligently adapts to terminal capabilities by leveraging the terminfo database, disabling unavailable styles. It is actively maintained, with frequent minor releases, and primarily supports Linux and macOS environments.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic terminal menu with a list of options. The `TerminalMenu` class is instantiated with the options, and the `show()` method displays the menu and returns the index of the selected item or `None` if cancelled.

from simple_term_menu import TerminalMenu

def main():
    options = ["entry 1", "entry 2", "entry 3"]
    terminal_menu = TerminalMenu(options)
    menu_entry_index = terminal_menu.show()
    if menu_entry_index is not None:
        print(f"You have selected {options[menu_entry_index]}!")
    else:
        print("Menu cancelled.")

if __name__ == "__main__":
    main()

view raw JSON →