Skip to main content

Bash Menu Builder

Project description

Bash Menu Builder

PyPI - Version Python Version PyPI - License PyPI - Downloads GitHub repo size

This package help you build menu for yours console scripts

Installation | Usage | Draw menu | How it works

Installation

For install package to your project use this command:

pip3 install bash-menu-builder

Usage

Script give opportunity use two type views of menu:

The Input type Menu

from bash_menu_builder import InputMenu, MenuItemDto


def banner_text() -> str:
    return 'I\'m Banner Text'

def function_one() -> None:
    print('Script One')

def function_two() -> None:
    print('Script Two')

def function_three() -> None:
    print('Script Three')

    
if __name__ == "__main__":
    InputMenu(
        menu=[
            MenuItemDto(title='Test', option='one', handler=function_one),
            MenuItemDto(title='Test2', option='two', handler=function_two),
            MenuItemDto(title='Test3', option='three', handler=function_three),
        ],
        banner=banner_text()
    )

View Menu

How it works

The Select type Menu

from bash_menu_builder import SelectMenu, MenuItemDto


def banner_text() -> str:
    return 'I\'m Banner Text'

def function_one() -> None:
    print('Script One')

def function_two() -> None:
    print('Script Two')

def function_three() -> None:
    print('Script Three')

    
if __name__ == "__main__":
    SelectMenu(
        menu=[
            MenuItemDto(title='Menu Item One', option='one', handler=function_one),
            MenuItemDto(title='Menu Item Two', option='two', handler=function_two),
            MenuItemDto(title='Menu Item Three', option='three', handler=function_three),
        ],
        banner=banner_text()
    )

View Menu

How it works

Draw menu

The menu draw via class View which get params of array with DTOs and text of banner (optional) The MenuItemDto have 3 params def __init__(self, title: str, option_name: str, handler: object):

  • title: str - the title of menu item
  • option_name: str - the option name for call menu via console
  • handler: object - the handler of menu item. What exactly script do after select this menu item.

How it works

After select menu number and press Enter will run script in function. When script finish process menu will draw again.

Also you can call script without drawing menu. Just set option when call python script file, ex. python3 main.py --three In this case will run script for menu 'Menu Item Three'. When script finish process menu will not draw again and program will close.

How it works

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

bash_menu_builder-1.1.4.tar.gz (5.8 kB view hashes)

Uploaded Source

Built Distribution

bash_menu_builder-1.1.4-py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 3

Supported by

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