Skip to main content

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

Python Version License Version Download

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 top
  • options (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 msvcrt for keyboard input
  • Linux/macOS: Uses termios and tty for 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flexmenu-1.0.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flexmenu-1.0.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file flexmenu-1.0.0.tar.gz.

File metadata

  • Download URL: flexmenu-1.0.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.0 Windows/11

File hashes

Hashes for flexmenu-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2be37bcbee9855ab601f4f384bc5a99b25418fef6a1f9c0e287d79c11bcd799d
MD5 a09582a6c624e3525bb85ced76376f89
BLAKE2b-256 95c04780954dce893dc74db69c55f0d06426527b26d4b0ec7867525f6c7ee343

See more details on using hashes here.

File details

Details for the file flexmenu-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: flexmenu-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.0 Windows/11

File hashes

Hashes for flexmenu-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 19db500febfdf2923d1911fcc5d5bdc2a30d153a418086f6d415f20a7609f15f
MD5 157cdf77e33f63d51c98edd7ecf7b398
BLAKE2b-256 54a3a4934b475d57a0ea5b41b4be70db36f8e7f96e2a15a12486f21a120ee6fe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page