Giter VIP home page Giter VIP logo

terminal-menu's Introduction

Terminal Menu using Python

Downloads

Here is a minimal usage example:

from terminal_menu import menu
user_choice: str = menu(
    static_menu_text="Please choose an annoying little dog:",
    choices=("Chihuahua", "Pomeranian", "Jack Russell"),
)
print(f"user chose '{user_choice}'")

I wanted a simple OS-agnostic interface for creating menus in my python command-line applications (using only the python standard library).

I could not find one that I liked, so I built this one.

It is not truly operating system agnostic since it uses the curses python library, which will not work on a Windows terminal. It works on WSL though.

I purposely contained all of the functionality in a single script (terminal_menu.py) so that this function can be easily included in a project with a minimal footprint. If you don't mind your project looking like a NodeJS project, you can also install it as a package from PyPI:

pip install terminal-menu

Here is a more complex usage example (examples/nested_menus.py):

from terminal_menu import menu

sound_status: str = "On"
video_quality: str = "Low"
persist_menu: bool = True
while persist_menu:
    user_choice: str = menu(
        static_menu_text="-- MAIN MENU --", choices=("New Game", "Options", "Exit")
    )
    if user_choice == "Exit":
        break
    elif user_choice == "New Game":
        user_choice = menu(
            static_menu_text="-- NEW GAME --",
            choices=("Single Player", "Multiplayer", "Back to Main Menu"),
        )
        if user_choice in ("Single Player", "Multiplayer"):
            print(f"User started new {user_choice} game")
            persist_menu = False
    elif user_choice == "Options":
        persist_options_menu: bool = True
        while persist_options_menu:
            user_choice = menu(
                static_menu_text=f"""-- OPTIONS --
Sound is currently {sound_status}
Video quality is currently {video_quality}
""",
                choices=("Sound", "Video", "Back to Main Menu"),
            )
            if user_choice == "Back to Main Menu":
                persist_options_menu = False
            elif user_choice == "Sound":
                user_choice = menu(
                    static_menu_text="-- SOUND OPTIONS --",
                    choices=("Off", "On", "Back to Options"),
                )
                if user_choice in ("Off", "On"):
                    sound_status = user_choice
            elif user_choice == "Video":
                user_choice = menu(
                    static_menu_text="-- VIDEO OPTIONS --",
                    choices=("Low", "Medium", "High", "Back to Options"),
                )
                if user_choice in ("Low", "Medium", "High"):
                    video_quality = user_choice

terminal-menu's People

Contributors

j-sephb-lt-n avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.