This is a lightweight Python library for terminal menu interaction that enables keyboard navigation through options, supports cross-platform operation (Windows/Unix/macOS), and provides a clean colored interface with instant user feedback.
Project description
FlexMenu
A lightweight, cross-platform terminal menu library for Python that enables keyboard-controlled menu selection with a clean visual interface.
Features
- Keyboard Navigation: Use ↑/↓ arrows to navigate, Enter/Space to select, ESC to cancel
- Cross-Platform: Works on Windows (msvcrt) and Unix/Linux/macOS (termios)
- Visual Feedback: Color-coded selection highlighting and clear operation prompts
- No Dependencies: Pure Python implementation using ANSI escape codes
- Lightweight: Simple and easy to integrate into any CLI application
Installation
Simply copy the FlexMenu class into your project. No additional dependencies required.
Quick Start
from FlexMenu import FlexMenu
# Create a menu
menu = FlexMenu("Main Menu", ["Start Game", "Settings", "Exit"])
# Run the menu
choice_index = menu.run()
# Get the selected option
if choice_index != -1: # -1 means user pressed ESC
print(f"You selected: {menu.get_choice}")
else:
print("Menu cancelled")
API Reference
FlexMenu(title, options)
Create a new menu instance.
title(str): The menu title displayed at the topoptions(list): List of option strings to display
Methods
run(): Display the menu and handle user input. Returns the index of selected option (0-based) or -1 if cancelled.get_choice(property): Returns the text of the currently selected option
Keyboard Controls
- ↑ / ↓: Navigate through options
- Enter / Space: Confirm selection
- ESC: Cancel and exit menu
Platform Support
- Windows: Uses
msvcrtfor keyboard input - Linux/macOS: Uses
termiosandttyfor keyboard input - Falls back to simple input mode if terminal control libraries are unavailable
Example
menu = FlexMenu(
"Configuration",
["Network Settings", "Display Options", "Audio", "Save & Exit"]
)
choice = menu.run()
if choice == 0:
configure_network()
elif choice == 1:
configure_display()
# ... etc
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters