Simple Terminal Menu
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
- breaking When upgrading from version 0.x to 1.x, the `TerminalMenu` constructor arguments (except the first parameter for menu entries) became keyword-only. This change was implemented to improve maintainability and allow for easier addition of new parameters.
- breaking Between versions 1.1 and 1.2, the `multi_select_key` parameter was renamed to `multi_select_keys` and now expects an iterable of keys. Additionally, `shortcut_parentheses_highlight_style` was renamed to `shortcut_brackets_highlight_style` for consistency.
- gotcha simple-term-menu is primarily designed for Unix-like systems (Linux, macOS) and relies on the `terminfo` database. It may not function correctly or provide a consistent experience on Windows due to fundamental differences in terminal capabilities.
- gotcha Embedding extensive logic directly within conditional statements for each menu selection can lead to verbose and difficult-to-manage code, especially with many menu options or submenus.
Install
-
pip install simple-term-menu
Imports
- TerminalMenu
from simple_term_menu import TerminalMenu
Quickstart
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()