{"id":18638137,"url":"https://github.com/d33p0st/mr-menu","last_synced_at":"2026-01-06T11:30:31.238Z","repository":{"id":257342838,"uuid":"857436793","full_name":"d33p0st/mr-menu","owner":"d33p0st","description":"Create complex tree of menus and sub-menus","archived":false,"fork":false,"pushed_at":"2024-09-17T01:16:28.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-17T02:02:58.860Z","etag":null,"topics":["menu-generator","menus","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/d33p0st.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-14T16:50:50.000Z","updated_at":"2024-09-17T01:21:16.000Z","dependencies_parsed_at":"2024-09-17T02:13:11.688Z","dependency_job_id":null,"html_url":"https://github.com/d33p0st/mr-menu","commit_stats":null,"previous_names":["d33p0st/menux","d33p0st/mr-menu"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d33p0st%2Fmr-menu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d33p0st%2Fmr-menu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d33p0st%2Fmr-menu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d33p0st%2Fmr-menu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/d33p0st","download_url":"https://codeload.github.com/d33p0st/mr-menu/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223466228,"owners_count":17149769,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["menu-generator","menus","python"],"created_at":"2024-11-07T05:39:22.361Z","updated_at":"2026-01-06T11:30:31.191Z","avatar_url":"https://github.com/d33p0st.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Unit Tests](https://github.com/d33p0st/mr-menu/actions/workflows/test.yml/badge.svg)](https://github.com/d33p0st/mr-menu/actions/workflows/test.yml)\n[![codecov](https://codecov.io/github/d33p0st/menux/graph/badge.svg?token=NF0LC6QWPX)](https://codecov.io/github/d33p0st/mr-menu)\n[![CD(PYPI)](https://github.com/d33p0st/mr-menu/actions/workflows/pypi.yml/badge.svg)](https://github.com/d33p0st/mr-menu/actions/workflows/pypi.yml)\n[![CodeQL](https://github.com/d33p0st/mr-menu/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/d33p0st/mr-menu/actions/workflows/github-code-scanning/codeql)\n\n# Overview\n\n`mr-menu` helps create Menus and sub-Menus all at once and helps managing them easily. `mr-menu` can easily execute menu and sub-menus and their conditional functions all-together.\n\nUsing `mr-menu`, you can create a `Tree` of Menus and add functionalities for each menu item. `mr-menu` can execute those functionalities and return results gracefully.\n\n## Table of Contents\n\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Issues](#issues)\n- [Pull Requests](#pull-requests)\n\n## Features\n\n- **_Nested Tree of Menu and Sub-Menus_**: Single Menu can have multiple sub-menus and further sub-sub-menus and so on.\n\n- **_In-built Execution of defined functions_**: You can define functions for each menu item and `mr-menu` will execute them based on which option the user chooses.\n\n## Installation\n\nExecute in Terminal:\n\n```bash\npip install mr-menu\n```\n\n## Usage\n\n\u003e Example Test Case: Suppose you want to create a simple menu which will contain two items - Add two nums and Sub two nums.\n\n- **`Simple Menu`**\n\n  - import the `Menu` class.\n\n    ```python\n    from mr-menu.simple import Menu\n    ```\n\n  - create functions/class methods for Add and Sub\n\n    ```python\n    def add_two():\n        num1 = int(input(\"Enter num 1: \"))\n        num2 = int(input(\"Enter num 2: \"))\n        return num1 + num2\n    \n    def sub_two():\n        num1 = int(input(\"Enter num 1: \"))\n        num2 = int(input(\"Enter num 2: \"))\n        return num1 - num2\n    ```\n\n  - Create `Menu` class object\n\n    ```python\n    menu = Menu(\n        identifier=\"main\", # unique menu identifier.\n        menu={1: \"Add two nums\", 2: \"Sub two nums\"}, # menu in dict form\n        functions={1: add_two, 2: sub_two}, # function dict with callable functions mapped to menu\n    )\n    ```\n\n  - Handle the menu and it's functions.\n\n    ```python\n    result = menu.handler(\n        prompt=\"Enter choice: \", # to be shown to the user.\n        return_execution_result=True,\n        *args, # see docstring\n        **kwargs, # see docstring\n    )\n\n    # the above code will ask the user for input with the \n    # prompt and if it is \"1\", it will ask for two nums and \n    # return (True, output).\n    # Similarly, if \"2\" is selected, it will return (True, output) again.\n    # if execution fails, it will return (False, None)\n    ```\n\n\u003e Now, Let us take an example where the first menu has two options -\u003e Add, Sub and one extra option -\u003e `More options` which expands into another menu, say, `Multiply` and `divide`.\n\n- **`Tree of Menus and submenus`**\n\n  - import `MenuBuilder` classs\n\n    ```python\n    from mr-menu.generator import MenuBuilder\n    ```\n\n  - create functions for `Add`, `Sub`, `Multiply` and `divide`\n\n    ```python\n    def add():\n        num1 = int(input(\"enter num 1: \"))\n        num2 = int(input(\"enter num 2: \"))\n        return num1 + num2\n    \n    def sub():\n        num1 = int(input(\"enter num 1: \"))\n        num2 = int(input(\"enter num 2: \"))\n        return num1 - num2\n    \n    def mult():\n        num1 = int(input(\"enter num 1: \"))\n        num2 = int(input(\"enter num 2: \"))\n        return num1*num2\n    \n    def div():\n        num1 = int(input(\"enter num 1: \"))\n        num2 = int(input(\"enter num 2: \"))\n        return num1/num2 if num2 != 0 else 0\n    ```\n\n  - create `MenuBuilder` class object\n\n    ```python\n    builder = MenuBuilder()\n    ```\n\n  - Add the first menu (main menu)\n\n    ```python\n    builder.add(\n        identifier=\"main\", # Unique identifier for this particular menu\n        menu={1: \"Add two nums\", 2: \"Sub two nums\", 3: \"More Options\"}, # menu in dict form\n        functions={1: add, 2: sub, 3: None}, # functions for all the options except the one that expands a new menu (3rd)\n        go_back_index=None, # It is recommended to keep this\n        # None, as a new (4th) option will be automatically\n        # created and handled that facilitates going back to the main menu.\n    )\n    ```\n\n  - Add the sub-menu\n\n    ```python\n    builder.add_submenu(\n        parent_identifier=\"main\", # parent menu is \"main\",\n        parent_menu_index=3, # the index key where the menu is supposed to expand. i.e., 3 (More options)\n        submenu_identifier=\"main-submenu-1\", # the unique identifier for this sub-menu,\n        submenu={1: \"Multiply two nums\", 2: \"Divide two nums\"}, # submenu in dict form.\n        go_back_index=None, # again, keep this None, here a 3rd\n        # option will be automatically created that helps to\n        # go back to the main menu.\n        replace_if_exist=True, # this means if the submenu already exists, replace the old one with this current one.\n    )\n    ```\n\n  - Handle the menu and submenu\n\n    If the user chooses option 1 (Add two nums), the `handler` will ask for two inputs and return the sum of the numbers. But when the user chooses 3rd option in the main menu, The new sub-menu will be displayed. The user can then choose `Multiply` and `Divide`.\n\n    ```python\n    result = builder.handler(\n        prompt=\"Enter your choice:\", # the prompt that asks to choose an option.\n        post_execution_label=\"The Task executed Successfully\", # after a task finishes, this will be printed.\n        return_execution_result=True, # returns the result in tuple form with two values - tuple[bool, Any],,\n        # where bool represents execute status and Any is the result.\n    )\n    ```\n\n## Issues\n\nPlease submit any issues found [here](https://github.com/d33p0st/mr-menu/issues).\n\n## Pull Requests\n\nPull Requests are welcome and encouraged. Find it [here](https://github.com/d33p0st/mr-menu/pulls)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd33p0st%2Fmr-menu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fd33p0st%2Fmr-menu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd33p0st%2Fmr-menu/lists"}