From 20c63f78d409f57f9ecf6513e9db0cf0e173b498 Mon Sep 17 00:00:00 2001 From: Calum Andrew Morrell Date: Mon, 19 May 2025 15:40:45 +0100 Subject: [PATCH] Updated README.md for the new menus module. --- README.md | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a523ba8..3d99252 100644 --- a/README.md +++ b/README.md @@ -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() +```