Updated README.md for the new menus module.

main
Calum Andrew Morrell 2025-05-19 15:40:45 +01:00
parent 9ff0d25227
commit 20c63f78d4
1 changed files with 27 additions and 3 deletions

View File

@ -4,12 +4,16 @@ This is intended to become a simple set of tools I use on a regular basis when d
You almost certainly don't want to use this. There are probably hundreds of alternatives on PyPi already - each one notably better than my own.
Regardless, if you're determined to cause yourself pain, what does this library do? So far there's only one little function which exists out of sheer laziness on my part. It clears the terminal window and is platform independent.
Regardless, if you're determined to cause yourself pain, what does this library do? Not much so far, even less if you don't install it. Handily it's on pypi so just 'pip install dg_clt', 'uv add dg_clt', or whatever your package manager of choice requires.
## dg_clt.screen
This little function exists out of sheer laziness on my part. All it does is clear the terminal window while remaining platform independent.
```python
from dg_clt import screen
import dg_clt as tdg
screen.clear()
tdg.screen.clear()
```
The entire code to provide that function is as follows:
@ -21,3 +25,23 @@ clear = lambda: os.system('cls' if os.name == 'nt' else 'clear')
```
I can just never recall the line off-hand when I need it.
## dg_clt.menus
This is a simple class that will clear the screen, display a menu from data you pass in, and return the user's choice once they select a correct menu item.
The Menu class accepts a title as a string, the list of menu items as a dictionary (using a blank key to display a blank line), and a prompt to ask the user to select a menu item (optional, with a default of '> '). The user's choice will be returned as a string.
```python
import dg_clt as tdg
main_menu = tdg.menus.Menu(title='Main Menu',
menu_items={'1': 'First item',
'2': 'Second item',
'3': 'Final item',
'':'',
'q': 'Quit the application'},
selection="What's it to be? ")
user_choice = main_menu.get_input()
```