Skip to main content

A Python library for creating interactive CLI menus

Project description

pymenu-cli

PyPI PyPI - Downloads License: MIT

pymenu-cli is a Python library that simplifies the creation of interactive command-line interface (CLI) menus. It provides a convenient way to define hierarchical menu structures and associate actions with menu items.

Features

  • Define menus and submenus using a simple JSON file format
  • Automatically generate navigation options (e.g., "Back" and "Exit")
  • Execute specific functions based on user selections
  • Customizable menu titles and item labels
  • Flexible and extensible architecture
  • Execute menus directly from the command line

Installation

pip install pymenu-cli

Usage

  1. Define your menu structure in a JSON file (menu.json)
  2. Implement the corresponding action functions in a separate Python file (actions.py)

Using the Python API

from pymenu_cli.menu import load_menu

menu_file_path = 'menu.json'
actions_file_path = 'actions.py'
main_menu = load_menu(menu_file_path, actions_file_path)

main_menu.display()

Using the Command Line

pymenu-cli --menu menu.json --actions actions.py

pymenu-cli takes care of the menu navigation, user input handling, and execution of the associated actions based on the user's selections.

Menu JSON Format

The menu.json file defines the structure of your menu. Here's an example:

{
  "title": "Main Menu",
  "items": [
    {
      "title": "Option 1",
      "action": "action_function_1"
    },
    {
      "title": "Option 2",
      "submenu": {
        "title": "Submenu",
        "items": [
          {
            "title": "Submenu Option 1",
            "action": "action_function_2"
          },
          {
            "title": "Submenu Option 2",
            "action": "action_function_3"
          }
        ]
      }
    }
  ]
}

Actions Python File

The actions.py file contains the functions that are executed when a menu item is selected. Here's an example:

def action_function_1():
    print("Executing action 1")

def action_function_2():
    print("Executing action 2")

def action_function_3():
    print("Executing action 3")

Examples

Explore the examples directory for sample menu configurations and action implementations. To run an example, follow these steps:

  1. Clone the project repository.
  2. Open your command line and navigate to the examples directory.
  3. Execute the example by running the following command:
python3 menu_example.py

License

This project is licensed under the MIT License.

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

pymenu_cli-1.0.5.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

pymenu_cli-1.0.5-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file pymenu_cli-1.0.5.tar.gz.

File metadata

  • Download URL: pymenu_cli-1.0.5.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.2

File hashes

Hashes for pymenu_cli-1.0.5.tar.gz
Algorithm Hash digest
SHA256 001cc46d0478a4aca3635602ecd3cd505ce5192a9fe4474b389a1faf3cc5b1e2
MD5 79b0cb665344d250b6ae070a2a88e81e
BLAKE2b-256 4ee6e7c8b84cfa6845ab6e093689c04d8151e0b00a449c7543c945e61685df55

See more details on using hashes here.

File details

Details for the file pymenu_cli-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: pymenu_cli-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.2

File hashes

Hashes for pymenu_cli-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 898f33ca6010db5bb814da28b1c8c1f72632e96cb6d44a05b3bff18f15bde196
MD5 02789e69bc9f2c0a62d7f221d1a4be33
BLAKE2b-256 33d03723c14406467ac19fc766bba7cec72b7cff739042cd810e870dcc04ab2a

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