IngoMeyer441 / simple-term-menu

A Python package which creates simple interactive menus on the command line.
MIT License
492 stars 43 forks source link

Can you add example code to your repo that better shows usage per example #1

Closed pageauc closed 4 years ago

pageauc commented 4 years ago

Example code to show better usage. I tried to show alternative options

#!/usr/bin/env python3
'''
Demonstration example for GitHub Project at
https://github.com/IngoHeimbach/simple-term-menu

This code only works in python3. Install per

    sudo pip3 install simple-term-menu

'''
import time
import os
from simple_term_menu import TerminalMenu

def main():
    main_menu_title = "  Main Menu\n"
    main_menu_items = ["Edit Menu", "Second Item", "Third Item", "Quit"]
    main_menu_cursor = "> "
    main_menu_cursor_style = ("fg_red", "bold")
    main_menu_style = ("bg_red", "fg_yellow")
    main_menu_exit = False

    main_menu = TerminalMenu(menu_entries=main_menu_items, 
                             title=main_menu_title,
                             menu_cursor=main_menu_cursor,
                             menu_cursor_style=main_menu_cursor_style,
                             menu_highlight_style=main_menu_style,
                             cycle_cursor=True)

    edit_menu_title = "  Edit Menu\n"
    edit_menu_items = ["Edit Config", "Save Settings", "Back to Main Menu"]
    edit_menu_back = False
    edit_menu = TerminalMenu(edit_menu_items,
                             edit_menu_title,
                             main_menu_cursor,
                             main_menu_cursor_style,
                             main_menu_style)

    while not main_menu_exit:
        os.system('clear')
        main_sel = main_menu.show()

        if main_sel == 0:
            while not edit_menu_back:
                os.system('clear')
                edit_sel = edit_menu.show()
                if edit_sel == 0:
                    print("Edit Config Selected")
                    time.sleep(5)
                elif edit_sel == 1:
                    print("Save Selected")
                    time.sleep(5)
                elif edit_sel == 2:
                    edit_menu_back = True
                    print("Back Selected")
            edit_menu_back = False
        elif main_sel == 1:
            print("option 2 selected")
            time.sleep(5)
        elif main_sel == 2:
            print("option 3 selected")
            time.sleep(5)
        elif main_sel == 3:
            main_menu_exit = True
            print("Quit Selected")  

if __name__ == "__main__":
    main()
IngoMeyer441 commented 4 years ago

Thank you very much, your example is added in 59162b31ac52cdc2b96f71984c38708826343920. :+1:

pageauc commented 4 years ago

Thanks. Not sure if you want to include example as a file in repo so users can download, but your choice. I am thinking of creating a class for specialized reusable options similar to windows widgets. All could share the same user specified style.

yes_no_cancel Display a message to confirm something with choices

message_ok Display a message until user selects OK

Browse directory structure to select a file. I have a bash whiptail that does this. See https://github.com/pageauc/FileBrowser

Read a user supplied filename and browse file structure to save file.

Not sure if multi select options is possible but could make a modified version of simple_term_menu. Also options above would work better with horizontal menu picks option. Whiptail works ok with bash scripts but would like something similar that is python based. Also thinking about python2 support even though it is no longer supported. Just a thought.

I use bash whiptail in some of my projects to make user management easier through SSH or terminal session. Useful especially on headless systems.

Thanks for your project. Claude ...

On Tue, Mar 10, 2020 at 11:36 AM Ingo Heimbach notifications@github.com wrote:

Closed #1 https://github.com/IngoHeimbach/simple-term-menu/issues/1.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/IngoHeimbach/simple-term-menu/issues/1?email_source=notifications&email_token=ABNPKZCFE5CV5XMEWPNX77DRGZUCTA5CNFSM4LETMSKKYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOXGZQ7YA#event-3115519968, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNPKZEOTMOT4BYZ7OVZ66DRGZUCTANCNFSM4LETMSKA .

-- See my YouTube Channel at http://www.youtube.com/user/pageaucp