Skip to main content

A simple, elegant Python interactive menu system using the Rich library.

Project description

pz-clean-menu

A simple, elegant Python interactive menu system using the Rich library, part of the pz- namespace.

Features

✅ Create colorful and structured console menus
✅ Support for nested submenus (children)
✅ Group options for better organization
✅ Dynamic addition of options and submenus at runtime
✅ Breadcrumb navigation for nested menus
✅ Support for disabled menu options
✅ Single-key input (no need to press Enter after selecting an option)
✅ Console helper utilities for various platforms
✅ Geometric console utilities (boxes, tables, grids, etc.)
✅ Powered by Rich for beautiful console output

Installation

Install via pip (after publishing to PyPI):

pip install pz-clean-menu

Or for local development:

git clone https://github.com/poziel/clean-menu.git
cd clean-menu
pip install -e .

Basic Usage

from pz_clean_menu import CleanMenu

def hello_callback(menu):
    print("\\nHello, world!")

menu = CleanMenu(header="My Menu")
menu.Group("default", title="Options")
menu.Add("1", "Say Hello", hello_callback)
menu.Display()

Advanced Usage

Submenus, dynamic options, and more!

from pz_clean_menu import CleanMenu

def final_depth_action(menu):
    print("\\n[Action] You've reached the final depth! Well done!\\n")

def create_deep_child(menu, depth):
    if depth == 0:
        return final_depth_action

    def next_level_callback(inner_menu):
        next_child = inner_menu.Children(header=f"Level {depth} Menu")
        next_child.Group("deep_group", title=f"Level {depth} Options")
        next_child.Add("1", f"Go Deeper to Level {depth-1}", create_deep_child(next_child, depth - 1), group_id="deep_group")
        next_child.Display()

    return next_level_callback

if __name__ == "__main__":
    main_menu = CleanMenu(header="Infinite Depth Menu", footer="Start your journey!")
    main_menu.Group("root", title="Root Options")
    main_menu.Add("1", "Descend to Level 3", create_deep_child(main_menu, 3), group_id="root")
    main_menu.Display()

Examples

Check out the examples/ folder for:

  • basic_usage.py: Simple menu with two actions
  • advanced_usage.py: Submenus and dynamic options
  • nested_menus.py: Deep nested menus showcasing the power of pz-clean-menu
  • feature_showcase.py: Demonstrates all the new features (breadcrumbs, disabled options, console helpers, geometric console)

Run them with:

python examples/basic_usage.py
python examples/advanced_usage.py
python examples/nested_menus.py
python examples/feature_showcase.py

Console Helpers

The package includes various console helper functions:

from pz_clean_menu import clear_console, get_terminal_size, run_command, pause, print_centered, print_header

# Clear the console (works on Windows, macOS, and Linux)
clear_console()

# Get terminal dimensions
width, height = get_terminal_size()

# Run a system command
output = run_command("echo Hello World")

# Pause execution until user presses Enter
pause("Press Enter to continue...")

# Print centered text
print_centered("This text is centered")

# Print a header
print_header("My Application", style="bold blue")

Geometric Console

Create beautiful geometric elements in the console:

from pz_clean_menu import GeometricConsole

gc = GeometricConsole()

# Create a box with text
gc.box("This is text in a box", title="My Box")

# Create a centered box
gc.centered_box("Centered text in a box", width=50)

# Create a table
data = [
    ["Name", "Age", "City"],
    ["Alice", 30, "New York"],
    ["Bob", 25, "Los Angeles"]
]
gc.table(data[1:], headers=data[0], title="People")

# Create a progress bar
gc.progress_bar(75, 100)

# Create a grid of items
items = ["Item 1", "Item 2", "Item 3", "Item 4"]
gc.grid(items, columns=2)

# Create a divider
gc.divider()

Tests

Tests are written using pytest:

pytest tests

License

MIT License


Enjoy exploring with pz-clean-menu! 🚀

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

pz_clean_menu-1.1.1.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

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

pz_clean_menu-1.1.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file pz_clean_menu-1.1.1.tar.gz.

File metadata

  • Download URL: pz_clean_menu-1.1.1.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for pz_clean_menu-1.1.1.tar.gz
Algorithm Hash digest
SHA256 2f7d9d655bf817872aa853b56abc5678f3f9c3007cf72dfed3c8c3a7248ea84f
MD5 5cbebab38cbfdcbb5ed0ad05dd3f0447
BLAKE2b-256 5b74651961f5ce95b294aadc64471306870143f73457545d7e538c3fa1429501

See more details on using hashes here.

File details

Details for the file pz_clean_menu-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: pz_clean_menu-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for pz_clean_menu-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aedbd65dd4e396c53227e2d8dbcd07da799104d97f3631a8ac1519a7017a78b1
MD5 4e5922d18cd0d85da0c2dce968649374
BLAKE2b-256 df10bf41f97d691908fb8b427b3937af573117fbff67c94aafd824b4da8d2ae4

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