This is the base class for a command line user interface.
You can control the style of the interface with the attributes AND OR parameters provided in this class. All are optional. Some more than others.
This method adds menu options to the menu.
Mainloop of the clui.
Only hit this after you have added all of the options for your menu. It will enter a loop, and it will break in only three scenarios:
You can pass user defined condition tests to clui, if you need more fine tuned control over your clui.
Note
The default condition is True, but you can change that to any thing you want, but make sure you can match that value.
Must take two positional arguments.
The first positional argument is the last string that the user entered.
The second positional argument is an integer representation of the number of loops the clui has gone through.
Must return a condition, or a list/tuple with a condition in it.
If a list or tuple is used, the condition must be the first item in the list.
Everything value in the container after that will be printed to the screen!
from clui import base_clui
def my_condition_test(user_input,looped):
"A condition test function for a clui."
if looped > 3: #Looped is an integer, that increases by one after each loop
return (False,'test failed',"I don't want you to run after 3 loops!")
return (True,'Test passed') #IMPORTANT - without returning the set condition, your loop would fail.
def a_function(): #This is a generic callable. Just for fun.
print "I am useless!"
ui = base_clui()
ui.title = 'Testing'
ui.initial_message = "Doin' some test!"
ui.condition_tests = [my_condition_test]
ui.add(display_name='option',callables=[a_function,'Wheee!'])
ui.add(display_name='moar stuff',patterns=['^moar *(stuff)?$'],callables=[a_function])
ui.execute()
Would give you this:
Clui lets you define exit callables, which are called before your clui terminates.
They are defined in the BASE_CLUI(link) attributes, but can also be passed as named arguments
A list of regex strings. It matches the user’s input to these and exits the clui if it finds a match.
The defaults are [‘^end$’,’^exit$’,’^leave$’,’^bye’$]
This toggles the start of the menu’s index between 0 and 1.
This affects the menu options’ pattern as well.
display_all_regex (boolean):
display_exit_words (boolean):
exit_callables (list):
input_message (string):
condition (BOOLEAN):
condition_tests (list of callables):
enable_clear (boolean):
It has the following parameters: