Terminal Display (Version 2)

A better and easier to use input system for the terminal, supports multiple modes.

from PythonFunctions.TerminalDisplay import Display
display = Display()

Note

Module ReadChar is required to get the interactive mode of the terminal. Use pip install PythonFunctions[terminal] -U to install readchar

SetOptions

SetOptions(options)

Sets the options for the terminal to display.

Parameters

options (dict) – The options to pass to the UI

Options Example

{
    1: (Callback, "Home"),
    2: (Callback, "Shop"),
    3: (Callback, "Wait"),
}

Above is an example of how the dictionary should be laid out, index then tuple with a callback function along the value to show. The number on the left only defines the position and can be negative. (Although they get treeted slightly differently).

Note

You can pass in more than 2 arguments, anything else will be passed to the function that you desire as the callback. e.g. passing in (Callback, “Home”, 123) will send “Home” and 123 to the function Callback once selected without showing 123 to the user.

AddOption

AddOption(value, *, index)

Add an option to the display. This can also update an existing option

Parameters
  • index (int) – (Optional) Position to add it to. Defaults to length of all the options.

  • value (tuple) – Value to add the option (Must be like above)

RemoveOption

RemoveOption(index)

Remove the specified option from the list to display.

Parameters

index (int) – The position to remove the option from

Returns

The value at that position

Return type

tuple

RemoveOptions

RemoveOptions(*index)

Remove all options specified

Parameters

index (int) – The index to remove the option from

Returns

The value at those positions

Return type

list

RemoveAllOptions

RemoveAllOptions()

Clears the list

ShowHeader

ShowHeader(*, text, typewriter, pace)

Shows a header

Parameters
  • text (str) – (Optional), Text to display in the header. Defaults to “Display.py”

  • typewriter (bool) – (Optional), To make the text come out in a letter by letter. Defaults to False.

  • pace (int) – (Optional), speed to make the typewriter work. Defaults to 100.

Note

1 second per letter = 1000 pace You can work out the rest from that.

ShowOptions

ShowOptions(useList)

The main function shows all the options that have been specified.

Parameters

useList (bool) – (Optional) To use a list format instead of a interactive movable format

Returns

The result of the callback function of the chosen input

Return type

any

SetQuitMessage

SetQuitMessage(msg)

The message to show on quit. (Normaly done by using ‘q’ in terminal mode)

Parameters

msg (str) – The message to show