Skip to main content

A simple and customizable menu system for CLI applications.

Project description

EasyMenu3

EasyMenu3

EasyMenu3 is a Python-based interactive menu system that allows users to create customizable command-line menus with ease. It provides a structured way to display options, handle user input, and execute actions, making it useful for CLI-based applications.

Available at https://pypi.org/project/easymenu3/0.1.0/

Screenshot

Example

Features

  • Customizable menu title, author, and URL display
  • ASCII art title generation using pyfiglet
  • Automatic debug message handling with icecream
  • Screen handling for clean terminal output
  • Color-coded menu options using a formatter cprint
  • Customizable menu item ordering and shortcut keys
  • Supports both function-based and static value-based actions

Installation

To use EasyMenu3, ensure you have Python installed along with the required dependencies:

pip install pyfiglet icecream easymenu3

Usage

Import easymenu and create an instance:

from EasyMenu3 import easymenu
def example1():
    app.print_success("example1 ran")
def example2():
    app.print_error("example2 ran")
    
def custom():
    app.print_info("Custom Option")
    input("Press enter to kill this!!!")
    app.exit_app()

app = easymenu(name="My Custom App", author="Joe Schmo", url="https://github.com/pitterpatter22/EasyMenu3", url_label="My Site", quit_item=True, debug=False, make_screen=True)
app.add_menu_option(item_name="Option 1", action=example1)
app.add_menu_option(item_name="Option 2", action=example2)
app.add_menu_option(item_name="Custom Option", action=custom, item_key="c", order_weight=1, color='\033[92m')

app.start()
# or 
#app.print_menu()

Class: easymenu

Constructor Parameters:

  • name (str): Optional menu title.
  • title_font (str): Font used for the ASCII title (default: "slant").
  • author (str): Author name.
  • url (str): URL displayed in the menu.
  • url_label (str): Custom label for the URL.
  • debug (bool): Enable debug messages.
  • make_screen (bool): Create a separate terminal screen.
  • quit_item (bool): Include a quit option automatically.

Methods:

  • add_menu_option(item_name, action, item_key=None, order_weight=None, color=None): Adds a new menu item.
  • print_menu(): Displays the menu and handles user input.
  • start(): Start the app and continue on errors. Also exits 'cleaner' / handles ctrl+c if a screen is created.
  • clear_screen(): Clears the terminal screen.
  • exit_app(): Gracefully exits the menu system.

Adding a Menu Option:

Create a new menu item to be displayed:

  • item_name: The name to be displayed as a menu item ex: Do Action
  • action: A function to be run if an item is selected from the menu.
    • If this is not a function, the value will be printed instead.
  • item_key: Optional string to change the key that is displayed in the menu instead of the index.
    • Instead of 1. Item the number will be replaced with the item_key provided c. Item
  • order_weight: Optional Integer to change the order of a menu item in the printed menu.
    • Default values are 5 for menu items with a custom item_key and 15 for an item without an item_key.
    • The goal is to have any special items ahead of normal items in the menu.
    • Menu items with the same weight will be sorted.
  • color: Optional ASCII color for the menu item or item from cprint
    • ex: \\033[91m
    • Defaults to no color

Example Menu Output

    __  ___         ______           __                     ___              
   /  |/  /_  __   / ____/_  _______/ /_____  ____ ___     /   |  ____  ____ 
  / /|_/ / / / /  / /   / / / / ___/ __/ __ \/ __ `__ \   / /| | / __ \/ __ \
 / /  / / /_/ /  / /___/ /_/ (__  ) /_/ /_/ / / / / / /  / ___ |/ /_/ / /_/ /
/_/  /_/\__, /   \____/\__,_/____/\__/\____/_/ /_/ /_/  /_/  |_/ .___/ .___/ 
       /____/                                                 /_/   /_/      

Made by: Joe Schmo
Visit: [My Site](https://github.com/pitterpatter22/EasyMenu3)

Menu:
c. Custom Option
2. Option 1
3. Option 2
q. Quit


What option do you want?:

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

easymenu3-0.2.1.tar.gz (133.6 kB view details)

Uploaded Source

Built Distribution

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

easymenu3-0.2.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file easymenu3-0.2.1.tar.gz.

File metadata

  • Download URL: easymenu3-0.2.1.tar.gz
  • Upload date:
  • Size: 133.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for easymenu3-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e532a60044783f64517618e06570bd5c959b2f2bec8bc2fd9ad701504cb9fc28
MD5 245a3a0e3c34ec83c5f3ab8c67716330
BLAKE2b-256 daf4dc0d827c28b2585e915d661fc72930176f66b425a761e07cad5e05a61d6a

See more details on using hashes here.

File details

Details for the file easymenu3-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: easymenu3-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for easymenu3-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c9064b18bdfde2073c7e14715be3f44852946e39b8fc2543755e44d975ee816
MD5 ef02fce3b203cbb5034d03e926e8afd5
BLAKE2b-256 f46bc6a313e7ba8c6aa32d48f12f9a76a79146bcf8d0f2d341f0c55435ebf2e3

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