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.0.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.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pz_clean_menu-1.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 003fea9e095f7afc8910eaff845bd3563e82ec17b317ba1d8764b0dccb3c58d3
MD5 b363cacd32c1156c3cfeac170fbd0881
BLAKE2b-256 7a1514c05498035782ed11efc7fc9bc8b3a55313db2e971ede0cb20a301cef1a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pz_clean_menu-1.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bdbab7ba54abc7053931b3eca784ad7476edfba1c07d3fe197e65de388857037
MD5 aa002a9431872ed3041a98a940bbfc13
BLAKE2b-256 95f3faf4a8ab69868a7b80b54735c065fd4899dbac9d3351899b24f8e766f31d

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