Skip to main content

Clean Menu

Table of content

Installation

You can install the package by running the following command : python3 -m pip install --upgrade clean-menu

Note

Please note that the package is currently in beta version and may encounter bugs or unexpected behaviours for which I am not responsible.

Known issues :

Linux :

  • The keys are captured but not intercepted
  • navigate in the menu browse your terminal history
  • when you press enter to validate, it can trigger one of your previous commands

I tried the same fix than windows but I haven't tested it yet.

Windows :

  • To disable key propagation, I set up a filter using the win32_event_filter kwarg
  • It will block arrows up and down, enter, and space (only if you use the space key to validate) These issues are all related, and a safe way to use it would be to override the default validation_key and set it to space.

MacOS : I actually don't have a mac to test it, but I think it won't work as expected, because filters are not the same as windows. Furthermore, keyboard monitoring requires elevated (root) privileges.

Use

Create an instance

Simply import the Menu object from the package into your script and start use it.

from clean_menu import Menu

menu = Menu(title,  # menu title
            options,  # list of options
            subtitle="",  # menu subtitle
            subtitle_color=None,  # subtitle color
            exit_text="Exit",  # exit text
            exit_function=sys.exit,  # exit function called when
            art_title=True,  # enable/disable ascii art title
            title_font="",  # ascii art title font
            default_pointer_index=0,  # default option index in option list
            margin="    ",  # characters before options, better result when longer than pointer
            title_color="red",  # title color
            text_color="white",  # color for not pointed options
            pointer_style=None,  # pointer style, if None, no pointer
            pointer_color="green",  # pointer color
            pointed_text_color="white",  # pointed option text color
            pointed_background_color="None",  # pointed option background color
            validation_key="enter",  # key to validate an option
            )

so the following code :

from clean_menu import Menu

menu = Menu("Test",
            ["Option 1", "Option 2", "Option 3"],
            title_font="rounded",
            title_color="blue",
            margin="        ",
            pointer_style=["==>", "<=="],
            pointer_color="red",
            pointed_background_color="white",
            pointed_text_color="green",
            exit_text="Quit me forever...",
            text_color="magenta",
            validation_key="enter",
            )

will render this :

Click to see the image (redirection)

Bind actions to options:

You can attach a function or method to each action in the menu, except for the exit, which is handled by the parameter exit_function. To do so, you just have to call the bind() method, with the index of the option and the function as parameters.

menu.bind(0, lambda: print("Option 1"))
menu.bind(1, lambda: print("Option 2"))
menu.bind(2, lambda: print("Option 3"))

in case the given index is not handled, you will get an error like this :

menu.bind(3, lambda: print("Option 4"))
=======================================
Bind Error: Index out of range
List of available options to assign functions :
0 : Option 1                                    # you will see all the options
1 : Option 2                                    # available for binding and their
2 : Option 3                                    # index to specify as parameter
Traceback (most recent call last):
  File "c:\Users\mathe\Documents\code\cleanMenu\clean-menu\main.py", line 158, in <module>
    example()
  File "c:\Users\mathe\Documents\code\cleanMenu\clean-menu\main.py", line 152, in example
    menu.bind(3, lambda: print("Option 4"))
  File "c:\Users\mathe\Documents\code\cleanMenu\clean-menu\main.py", line 114, in bind
    raise IndexError
IndexError

Use the menu

You have to options to use the menu :

  • You can bind functions to options and let the menu execute them with the run method
  • you can just execute the menu screen to get the index of the selected option

examples :

menu.run() # and that's pretty much all you need to do...
index = menu.get_index() # will return the index of the selected option	
print(menu.options[index]) # should display the option you selected

Metadata

Release files for clean-menu 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clean-menu 0.2.1
File Size Uploaded Provenance Actions
clean_menu-0.2.1.tar.gz 6.5 kB Without provenance Details for clean_menu-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for clean-menu 0.2.1
File Interpreter ABI Platform Actions
clean_menu-0.2.1-py3-none-any.whl Python 3 none any Details for clean_menu-0.2.1-py3-none-any.whl

Total release size: 12.7 kB

Release files / clean_menu-0.2.1.tar.gz

Download URL clean_menu-0.2.1.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a8500f8c56d357bc87a04f823b4445305636ffe0bd7752f6904176a11e2b20bc
BLAKE2b-256 checksum
How to use checksums
5a059a77f2e5a6e79d98de56731ed972544c545b180ee03210979412cf8972f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.10.8 Windows/10

Release files / clean_menu-0.2.1-py3-none-any.whl

Download URL clean_menu-0.2.1-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14b86f79e4de9974901a29ee16e37e75eecb07b600807ad8c07aaca3f25b509e
BLAKE2b-256 checksum
How to use checksums
1d5f678f04befd111878dac5e690a6926bedae671416df466d2483d766e22fbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.10.8 Windows/10

Security for clean-menu 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page