A menu-based python command line interface constructor tool
Download cli.py and include it in your project. Make sure there is a init.py script in your project. Import and use the module as follows:
from cli import *
cli = CLI("Welcome!")
cli.run()
When you run this script, you will see the message Welcome! printed on the console followed by a prompt for input. To exit use Ctrl+C.
Creates and returns an instance of the CLI class.
- header: A string to serve as the menu header.
Adds an option to the menu.
- option: An instance of the class
MenuOption. See below in the Supporting Classes and Functions section.
Calls the ith menu option given by the integer selection. The options are indexed at 0.
Starts the command line interface.
Creates and returns a menu option.
- prompt: a string of menu prompt text for the given menu option
- action: a function to call
Clears the console.
Gets string input from the user using the given prompt text.
- message: the prompt text.
Gets a True or False value from the user using a character specified in format.
- message: the prompt text.
- format: a string of the form
@/$where the@and$symbols refer to distinct characters representing distinct True/False values.
Gets number input from the user using the given prompt text.
- message: the prompt text.
Prints a header followed by the menu options.
- header: a string header
See test.py and utils.py for an example of the module's use.