API Usage¶
Menu class¶
-
class
termmenu.
Menu
(**kwargs)¶ Create an instance of this class to start off. A number of options can be passed to the
Menu
classParameters: - title (Optional[
str
]) – This is the text displayed at the top of the menu list. Defaults to “Choose one:” - start (Optional[
int
]) – This changes which number the normal entries indexes from, defaults to 0. :)
-
add_entry
(text: str, **kwargs)¶ This function adds new entries to the list.
Parameters: - text (
str
) – The text next to the number or custom entry key. - submenu (Optional[
Menu
]) –A Menu that will get invoked with the arguments specified in the
submenuargs
argument if the given entry is selected.If
submenu
is specified then therun
argument will not be executed. - submenuargs (Optional[
dict
]) – Arguments that will be passed to thesubmenu
when run. Example:{"allowother": True}
- run (Optional[
function
]) –Function that will be run when user selects that entry. Defaults to
None
and it will just return selected entry.Has lower priority than the
submenu
argument - entry (Optional[
str
]) – Custom entry, instead of number. All custom entries will be displayed after the numbered entries. Custom entry has to include at least one character that isn’t a number or it will raiseCustomEntryIsNumberError
. If no entry is specified it will default to using the number after the last number.
Returns: Returns
self
so that you can stack them likeMenu().add_entry("1").add_entry("2")
Return type: self (
Menu
)- text (
-
run
(**kwargs)¶ This function runs the menu that you have created.
Parameters: - prompt (Optional[
str
]) – The prompt text to be used in the input() Defaults to “> “ - allowother (Optional[
bool
]) – If true, the function will raiseEntryNotFoundError
if the selected entry is not in the menu. Defaults toTrue
- listformat (Optional[
str
]) –How the menu list is shown.
{entry}: the number or custom entry. {name}: name of the entry.
Defaults to: “{entry}. {name}” (example: “2. Settings”)
Returns: Returns the user’s input if it doesn’t raise EntryNotFoundError.
Return type: str
- prompt (Optional[
- title (Optional[