jsonmenu


Namejsonmenu JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/xavi-burgos99/jsonmenu
SummaryThe easiest way to create interactive console menus in Python using JSON
upload_time2024-03-15 12:25:47
maintainer
docs_urlNone
authorXavi Burgos
requires_python>=3.6
licenseMIT
keywords json menu console interactive python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
	<!--
  <a href="https://example.com/">
    <img src="https://via.placeholder.com/72" alt="JSON Menu" width=72 height=72>
  </a>
	-->

  <h3 align="center">JSON Menu</h3>

  <p align="center">
    The easiest way to create interactive console menus in Python
    <br>
    <a href="https://github.com/xavi-burgos99/jsonmenu/issues/new?template=bug.md">Report bug</a>
    ·
    <a href="https://github.com/xavi-burgos99/jsonmenu/issues/new?template=feature.md&labels=feature">Request feature</a>
  </p>
</p>


## Table of contents

- [Table of contents](#table-of-contents)
- [Introduction](#introduction)
- [Installation](#installation)
- [Import](#import)
- [How to use](#how-to-use)
	- [Compact version](#compact-version)
- [Options](#options)
	- [Custom language](#custom-language)
	- [Custom theme](#custom-theme)
- [What's included](#whats-included)
- [Bugs and feature requests](#bugs-and-feature-requests)
- [Contributing](#contributing)
- [Creator](#creator)


## Introduction

JSON Menu is a Python library created by [Xavi Burgos](https://xburgos.es/) that lets you create interactive console menus from basic JSON structures. With just a few lines of code, you can build user-friendly interfaces for your Python scripts.

The menu generated by JSON Menu will be displayed as the following example:

```text
┌─────────────────────────────┐
│        My first menu        │
├─────────────────────────────┤
│ 1. My first action          │
│ 2. Submenu                  │
│ 0. Exit                     │
└─────────────────────────────┘

Select an option: 
```


## Installation

To install JSON Menu, you can use the following [pip](https://pip.pypa.io/en/stable/) command:

```bash
pip install jsonmenu
```

Alternatively, you can clone the repository from GitHub or download the source code from the [releases page](https://github.com/xavi-burgos99/jsonmenu/releases/) and include the `jsonmenu.py` file in your project.


## Import

Once installed, you can import the library in your Python script with the following line:

```python
from jsonmenu import JsonMenu
```


## How to use

To create a menu, you need to define a JSON structure with the following format:

```python
menu_data = [
	{
		"label": "My first action",
		"action": my_function
	},
	{
		"label": "Submenu",
		"submenu": [
			{
				"label": "Option 1",
				"action": custom_function_1
			},
			{
				"label": "Option 2",
				"action": custom_function_2
			}
		]
	}
]
```

Also, you can add an options dictionary to customize the menu, explained at [options](#options) section.

```python
custom_options = {
	"theme": "rounded",
	# More options here...
}
```

Then, you can create the menu with the following code:

```python
jm = JsonMenu("My first menu", menu_data, custom_options)
jm.show()
```


### Compact version

A compact version of the previous code to create and show the menu is the following:

```python
jm = JsonMenu("My first menu", [
	{
		"label": "My first action",
		"action": my_function
	},
	{
		"label": "Submenu",
		"submenu": [
			{
				"label": "Option 1",
				"action": custom_function_1
			},
			{
				"label": "Option 2",
				"action": custom_function_2
			}
		]
	}
], { "theme": "rounded" })
jm.show()
```


## Options

The options dictionary allows you to customize the appearance and behavior of the menu. The following options are available:

| Option | Description | Default value | Possible values |
| --- | --- | --- | --- |
| `back_menu` | Previous menu to return when the user selects the `0` option. If not defined, the menu will close. | `None` | `JsonMenu` object |
| `clear` | Clear the console before showing the menu. This option is useful to avoid cluttering the console with previous outputs. | `False` | `True`, `False` |
| `debug` | Show debug information in the console. This option is useful for development and testing. Warnings will not be displayed if `clear` option is enabled (console is cleared before showing the menu). | `False` | `True`, `False` |
| `width` | Width of the menu in characters. | `31` | `int` |
| `language` | Language of the menu. Also a dictionary could be passed, and the menu will be use the provided custom translations. | `en` | `ar`, `ca`, `de`, `en`, `es`, `fr`, `hi`, `it`, `ja`, `ko`, `nl`, `pt`, `ru`, `sv`, `tr`, `zh`, [\<custom dictionary\>](#custom-language) |
| `theme` | Theme of the menu. Also a dictionary could be passed, and the menu will be use the provided custom theme. | `unicode` | `ascii`, `unicode`, `bold`, `double`, `rounded`, `dotted`, `striped`, [\<custom dictionary\>](#custom-theme) |


### Custom language

A custom language dictionary can be passed to the `language` option. The dictionary must contain the following keys:

| Key | Description | English value |
| --- | --- | --- |
| `back` | Text for the back option. | Back |
| `exit` | Text for the exit option. | Exit |
| `invalid_option` | Text for the invalid option message. | Invalid option |
| `select_option` | Text for the select option message. | Select an option |
| `press_enter` | Text for the press enter to continue message. | Press "Enter" to continue |


### Custom theme

A custom theme dictionary can be passed to the `theme` option. The dictionary must contain the following keys:

| Key | Description | Unicode value |
| --- | --- | --- |
| `tl` | Top left corner of the menu. | `┌` |
| `tr` | Top right corner of the menu. | `┐` |
| `cl` | Center left corner of the menu. | `├` |
| `cr` | Center right corner of the menu. | `┤` |
| `bl` | Bottom left corner of the menu. | `└` |
| `br` | Bottom right corner of the menu. | `┘` |
| `h` | Horizontal line of the menu. | `─` |
| `v` | Vertical line of the menu. | `│` |


## What's included

Within the download you'll find the following directories and files, logically grouping common assets. You'll see something like this:

```text
jsonmenu/
├── jsonmenu
│   ├── __init__.py
│   └── jsonmenu.py
├── setup.py
├── CONTRIBUTING.md
├── LICENSE
└── README.md
```


## Bugs and feature requests

Have a bug or a feature request? Please first read the [issue guidelines](https://github.com/xavi-burgos99/jsonmenu/blob/main/CONTRIBUTING.md) and search for existing and closed issues. If your problem or idea is not addressed yet, [please open a new issue](https://github.com/xavi-burgos99/jsonmenu/issues/new).


## Contributing

Please read through our [contributing guidelines](https://github.com/xavi-burgos99/jsonmenu/blob/main/CONTRIBUTING.md). Included are directions for opening issues, coding standards, and notes on development.


## Creator

**Xavier Burgos**
 - Website: <https://xburgos.es/>
 - GitHub: <https://github.com/xavi-burgos99/>
 - LinkedIn: <https://linkedin.com/in/xavi-burgos/>




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/xavi-burgos99/jsonmenu",
    "name": "jsonmenu",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "json menu console interactive python",
    "author": "Xavi Burgos",
    "author_email": "xavi@dzin.es",
    "download_url": "https://files.pythonhosted.org/packages/04/62/c28fceaffdb268083e20a3ab83a3f5a9694ff66f9f8f01ad67a2d40e3462/jsonmenu-1.0.1.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n\t<!--\n  <a href=\"https://example.com/\">\n    <img src=\"https://via.placeholder.com/72\" alt=\"JSON Menu\" width=72 height=72>\n  </a>\n\t-->\n\n  <h3 align=\"center\">JSON Menu</h3>\n\n  <p align=\"center\">\n    The easiest way to create interactive console menus in Python\n    <br>\n    <a href=\"https://github.com/xavi-burgos99/jsonmenu/issues/new?template=bug.md\">Report bug</a>\n    \u00b7\n    <a href=\"https://github.com/xavi-burgos99/jsonmenu/issues/new?template=feature.md&labels=feature\">Request feature</a>\n  </p>\n</p>\n\n\n## Table of contents\n\n- [Table of contents](#table-of-contents)\n- [Introduction](#introduction)\n- [Installation](#installation)\n- [Import](#import)\n- [How to use](#how-to-use)\n\t- [Compact version](#compact-version)\n- [Options](#options)\n\t- [Custom language](#custom-language)\n\t- [Custom theme](#custom-theme)\n- [What's included](#whats-included)\n- [Bugs and feature requests](#bugs-and-feature-requests)\n- [Contributing](#contributing)\n- [Creator](#creator)\n\n\n## Introduction\n\nJSON Menu is a Python library created by [Xavi Burgos](https://xburgos.es/) that lets you create interactive console menus from basic JSON structures. With just a few lines of code, you can build user-friendly interfaces for your Python scripts.\n\nThe menu generated by JSON Menu will be displayed as the following example:\n\n```text\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502        My first menu        \u2502\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502 1. My first action          \u2502\n\u2502 2. Submenu                  \u2502\n\u2502 0. Exit                     \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n\nSelect an option: \n```\n\n\n## Installation\n\nTo install JSON Menu, you can use the following [pip](https://pip.pypa.io/en/stable/) command:\n\n```bash\npip install jsonmenu\n```\n\nAlternatively, you can clone the repository from GitHub or download the source code from the [releases page](https://github.com/xavi-burgos99/jsonmenu/releases/) and include the `jsonmenu.py` file in your project.\n\n\n## Import\n\nOnce installed, you can import the library in your Python script with the following line:\n\n```python\nfrom jsonmenu import JsonMenu\n```\n\n\n## How to use\n\nTo create a menu, you need to define a JSON structure with the following format:\n\n```python\nmenu_data = [\n\t{\n\t\t\"label\": \"My first action\",\n\t\t\"action\": my_function\n\t},\n\t{\n\t\t\"label\": \"Submenu\",\n\t\t\"submenu\": [\n\t\t\t{\n\t\t\t\t\"label\": \"Option 1\",\n\t\t\t\t\"action\": custom_function_1\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"label\": \"Option 2\",\n\t\t\t\t\"action\": custom_function_2\n\t\t\t}\n\t\t]\n\t}\n]\n```\n\nAlso, you can add an options dictionary to customize the menu, explained at [options](#options) section.\n\n```python\ncustom_options = {\n\t\"theme\": \"rounded\",\n\t# More options here...\n}\n```\n\nThen, you can create the menu with the following code:\n\n```python\njm = JsonMenu(\"My first menu\", menu_data, custom_options)\njm.show()\n```\n\n\n### Compact version\n\nA compact version of the previous code to create and show the menu is the following:\n\n```python\njm = JsonMenu(\"My first menu\", [\n\t{\n\t\t\"label\": \"My first action\",\n\t\t\"action\": my_function\n\t},\n\t{\n\t\t\"label\": \"Submenu\",\n\t\t\"submenu\": [\n\t\t\t{\n\t\t\t\t\"label\": \"Option 1\",\n\t\t\t\t\"action\": custom_function_1\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"label\": \"Option 2\",\n\t\t\t\t\"action\": custom_function_2\n\t\t\t}\n\t\t]\n\t}\n], { \"theme\": \"rounded\" })\njm.show()\n```\n\n\n## Options\n\nThe options dictionary allows you to customize the appearance and behavior of the menu. The following options are available:\n\n| Option | Description | Default value | Possible values |\n| --- | --- | --- | --- |\n| `back_menu` | Previous menu to return when the user selects the `0` option. If not defined, the menu will close. | `None` | `JsonMenu` object |\n| `clear` | Clear the console before showing the menu. This option is useful to avoid cluttering the console with previous outputs. | `False` | `True`, `False` |\n| `debug` | Show debug information in the console. This option is useful for development and testing. Warnings will not be displayed if `clear` option is enabled (console is cleared before showing the menu). | `False` | `True`, `False` |\n| `width` | Width of the menu in characters. | `31` | `int` |\n| `language` | Language of the menu. Also a dictionary could be passed, and the menu will be use the provided custom translations. | `en` | `ar`, `ca`, `de`, `en`, `es`, `fr`, `hi`, `it`, `ja`, `ko`, `nl`, `pt`, `ru`, `sv`, `tr`, `zh`, [\\<custom dictionary\\>](#custom-language) |\n| `theme` | Theme of the menu. Also a dictionary could be passed, and the menu will be use the provided custom theme. | `unicode` | `ascii`, `unicode`, `bold`, `double`, `rounded`, `dotted`, `striped`, [\\<custom dictionary\\>](#custom-theme) |\n\n\n### Custom language\n\nA custom language dictionary can be passed to the `language` option. The dictionary must contain the following keys:\n\n| Key | Description | English value |\n| --- | --- | --- |\n| `back` | Text for the back option. | Back |\n| `exit` | Text for the exit option. | Exit |\n| `invalid_option` | Text for the invalid option message. | Invalid option |\n| `select_option` | Text for the select option message. | Select an option |\n| `press_enter` | Text for the press enter to continue message. | Press \"Enter\" to continue |\n\n\n### Custom theme\n\nA custom theme dictionary can be passed to the `theme` option. The dictionary must contain the following keys:\n\n| Key | Description | Unicode value |\n| --- | --- | --- |\n| `tl` | Top left corner of the menu. | `\u250c` |\n| `tr` | Top right corner of the menu. | `\u2510` |\n| `cl` | Center left corner of the menu. | `\u251c` |\n| `cr` | Center right corner of the menu. | `\u2524` |\n| `bl` | Bottom left corner of the menu. | `\u2514` |\n| `br` | Bottom right corner of the menu. | `\u2518` |\n| `h` | Horizontal line of the menu. | `\u2500` |\n| `v` | Vertical line of the menu. | `\u2502` |\n\n\n## What's included\n\nWithin the download you'll find the following directories and files, logically grouping common assets. You'll see something like this:\n\n```text\njsonmenu/\n\u251c\u2500\u2500 jsonmenu\n\u2502   \u251c\u2500\u2500 __init__.py\n\u2502   \u2514\u2500\u2500 jsonmenu.py\n\u251c\u2500\u2500 setup.py\n\u251c\u2500\u2500 CONTRIBUTING.md\n\u251c\u2500\u2500 LICENSE\n\u2514\u2500\u2500 README.md\n```\n\n\n## Bugs and feature requests\n\nHave a bug or a feature request? Please first read the [issue guidelines](https://github.com/xavi-burgos99/jsonmenu/blob/main/CONTRIBUTING.md) and search for existing and closed issues. If your problem or idea is not addressed yet, [please open a new issue](https://github.com/xavi-burgos99/jsonmenu/issues/new).\n\n\n## Contributing\n\nPlease read through our [contributing guidelines](https://github.com/xavi-burgos99/jsonmenu/blob/main/CONTRIBUTING.md). Included are directions for opening issues, coding standards, and notes on development.\n\n\n## Creator\n\n**Xavier Burgos**\n - Website: <https://xburgos.es/>\n - GitHub: <https://github.com/xavi-burgos99/>\n - LinkedIn: <https://linkedin.com/in/xavi-burgos/>\n\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "The easiest way to create interactive console menus in Python using JSON",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/xavi-burgos99/jsonmenu"
    },
    "split_keywords": [
        "json",
        "menu",
        "console",
        "interactive",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b58057202ec62ec8dbcff7664ff19c4db8f92e51e80dd8438d4203d7e3b4a808",
                "md5": "6203509b1a669b0b6b16e1106543edcb",
                "sha256": "4a6802df1f9f6accb3cc4278cd9353c370da836512f8245cdba464a2832acd9a"
            },
            "downloads": -1,
            "filename": "jsonmenu-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6203509b1a669b0b6b16e1106543edcb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 7923,
            "upload_time": "2024-03-15T12:25:45",
            "upload_time_iso_8601": "2024-03-15T12:25:45.352085Z",
            "url": "https://files.pythonhosted.org/packages/b5/80/57202ec62ec8dbcff7664ff19c4db8f92e51e80dd8438d4203d7e3b4a808/jsonmenu-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0462c28fceaffdb268083e20a3ab83a3f5a9694ff66f9f8f01ad67a2d40e3462",
                "md5": "cf63986f1fe27ccba2e406612cc34d72",
                "sha256": "253e609d4a615585b07bb5b279cde790435a0fe428b118695cb26691e73f349f"
            },
            "downloads": -1,
            "filename": "jsonmenu-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "cf63986f1fe27ccba2e406612cc34d72",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 7944,
            "upload_time": "2024-03-15T12:25:47",
            "upload_time_iso_8601": "2024-03-15T12:25:47.382412Z",
            "url": "https://files.pythonhosted.org/packages/04/62/c28fceaffdb268083e20a3ab83a3f5a9694ff66f9f8f01ad67a2d40e3462/jsonmenu-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-15 12:25:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "xavi-burgos99",
    "github_project": "jsonmenu",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "jsonmenu"
}
        
Elapsed time: 3.67916s