Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for selecting by pressing number or letter #73

Open
Quantlyx opened this issue Apr 23, 2022 · 3 comments
Open

add support for selecting by pressing number or letter #73

Quantlyx opened this issue Apr 23, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@Quantlyx
Copy link

Quantlyx commented Apr 23, 2022

[Label: enhancement]

Maybe you could add support for the following:
When you are in a menu you just have to press the associated number or letter for the option to be selected. So not like with writing the number down and pressing enter.

BTW: big fan of the package, keep it up!

@aegirhall aegirhall added the enhancement New feature or request label Aug 10, 2022
croisez pushed a commit to croisez/console-menu that referenced this issue Feb 27, 2023
@croisez
Copy link

croisez commented Mar 1, 2023

Hi,
I needed this new feature, so I coded it.
Would you like to test my code, and possibly to merge it ?

@croisez
Copy link

croisez commented Mar 1, 2023

Here is a test.py script, to see how I implemented it.
Look at "exit_menu_char" option to ConsoleMenu() object.
Look also at "menu_char" option to all other Items() objects, like SubmenuItem() or FunctionItem(), for instance.

from consolemenu import *
from consolemenu.items import *

def MyTestFunction():
     Screen().println("In function MyTestFunction()")
    
mainMenu = ConsoleMenu("My test Menu", "main menu",   clear_screen=False, exit_menu_char='q')
subMenu  = ConsoleMenu("My test subMenu", "sub menu", clear_screen=False, exit_menu_char='q')

mainMenu_item1 = SubmenuItem("menu item1",  submenu=subMenu, menu_char='c')
mainMenu_item2 = FunctionItem("function test item", MyTestFunction, menu_char='t')

mainMenu.append_item(mainMenu_item1)
mainMenu.append_item(mainMenu_item2)

mainMenu.show()

@croisez
Copy link

croisez commented Mar 1, 2023

Here is the result of running this test.py file:

  ┌─────────────────────────────────────────────────────────────────────────┐
  │                                                                         │
  │  My test Menu                                                           │
  │                                                                         │
  │  main menu                                                              │
  │                                                                         │
  │                                                                         │
  │    c - menu item1                                                       │
  │    t - function test item                                               │
  │    q - Exit                                                             │
  │                                                                         │
  │                                                                         │
  └─────────────────────────────────────────────────────────────────────────┘
  >> c

  ┌─────────────────────────────────────────────────────────────────────────┐
  │                                                                         │
  │  My test subMenu                                                        │
  │                                                                         │
  │  sub menu                                                               │
  │                                                                         │
  │                                                                         │
  │    q - Exit                                                             │
  │                                                                         │
  │                                                                         │
  └─────────────────────────────────────────────────────────────────────────┘
  >> q

  ┌─────────────────────────────────────────────────────────────────────────┐
  │                                                                         │
  │  My test Menu                                                           │
  │                                                                         │
  │  main menu                                                              │
  │                                                                         │
  │                                                                         │
  │    c - menu item1                                                       │
  │    t - function test item                                               │
  │    q - Exit                                                             │
  │                                                                         │
  │                                                                         │
  └─────────────────────────────────────────────────────────────────────────┘
  >> t
In function MyTestFunction()

  ┌─────────────────────────────────────────────────────────────────────────┐
  │                                                                         │
  │  My test Menu                                                           │
  │                                                                         │
  │  main menu                                                              │
  │                                                                         │
  │                                                                         │
  │    c - menu item1                                                       │
  │    t - function test item                                               │
  │    q - Exit                                                             │
  │                                                                         │
  │                                                                         │
  └─────────────────────────────────────────────────────────────────────────┘
  >> q

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants