cpl.console

cpl.console.background_color_enum

class cpl.console.background_color_enum.BackgroundColorEnum(value)

Bases: enum.Enum

An enumeration.

blue = 'on_blue'
cyan = 'on_cyan'
default = 'on_default'
green = 'on_green'
grey = 'on_grey'
magenta = 'on_magenta'
red = 'on_red'
white = 'on_white'
yellow = 'on_yellow'

cpl.console.console

class cpl.console.console.Console

Bases: object

Useful functions for handling with input and output

background_color = 'on_default'
classmethod banner(string: str)

Prints the string as a banner

string: str

Message to print as banner

classmethod clear()

Clears the console

classmethod close()

Closes the application

classmethod color_reset()

Resets the color settings

classmethod disable()

Disables console interaction

classmethod enable()

Enables console interaction

classmethod error(string: str, tb: Optional[str] = None)

Prints an error with traceback

string: str

Error message

tb: str

Error traceback

foreground_color = 'default'
classmethod read(output: Optional[str] = None)str

Reads in line

output: str

String to print before input

input()

classmethod read_line(output: Optional[str] = None)str

Reads in next line

output: str

String to print before input

input()

classmethod reset_cursor_position()

Resets cursor position

classmethod select(char: str, message: str, options: list, header_foreground_color: Union[str, cpl.console.foreground_color_enum.ForegroundColorEnum] = <ForegroundColorEnum.default: 'default'>, header_background_color: Union[str, cpl.console.background_color_enum.BackgroundColorEnum] = <BackgroundColorEnum.default: 'on_default'>, option_foreground_color: Union[str, cpl.console.foreground_color_enum.ForegroundColorEnum] = <ForegroundColorEnum.default: 'default'>, option_background_color: Union[str, cpl.console.background_color_enum.BackgroundColorEnum] = <BackgroundColorEnum.default: 'on_default'>, cursor_foreground_color: Union[str, cpl.console.foreground_color_enum.ForegroundColorEnum] = <ForegroundColorEnum.default: 'default'>, cursor_background_color: Union[str, cpl.console.background_color_enum.BackgroundColorEnum] = <BackgroundColorEnum.default: 'on_default'>)str

Prints select menu

char: str

Character to show which element is selected

message: str

Message or header of the selection

options: List[str]

Selectable options

header_foreground_color: Union[str, cpl.console.foreground_color_enum.ForegroundColorEnum]

Foreground color of the header

header_background_color: Union[str, cpl.console.background_color_enum.BackgroundColorEnum]

Background color of the header

option_foreground_color: Union[str, cpl.console.foreground_color_enum.ForegroundColorEnum]

Foreground color of the options

option_background_color: Union[str, cpl.console.background_color_enum.BackgroundColorEnum]

Background color of the options

cursor_foreground_color: Union[str, cpl.console.foreground_color_enum.ForegroundColorEnum]

Foreground color of the cursor

cursor_background_color: Union[str, cpl.console.background_color_enum.BackgroundColorEnum]

Background color of the cursor

Selected option as str

classmethod set_background_color(color: Union[cpl.console.background_color_enum.BackgroundColorEnum, str])

Sets the background color

color: Union[cpl.console.background_color_enum.BackgroundColorEnum, str]

Background color of the console

classmethod set_cursor_position(x: int, y: int)

Sets cursor position

x: int

X coordinate

y: int

Y coordinate

classmethod set_foreground_color(color: Union[cpl.console.foreground_color_enum.ForegroundColorEnum, str])

Sets the foreground color

color: Union[cpl.console.background_color_enum.BackgroundColorEnum, str]

Foreground color of the console

classmethod set_hold_back(value: bool)
classmethod spinner(message: str, call: collections.abc.Callable, *args, text_foreground_color: Optional[Union[str, cpl.console.foreground_color_enum.ForegroundColorEnum]] = None, spinner_foreground_color: Optional[Union[str, cpl.console.foreground_color_enum.ForegroundColorEnum]] = None, text_background_color: Optional[Union[str, cpl.console.background_color_enum.BackgroundColorEnum]] = None, spinner_background_color: Optional[Union[str, cpl.console.background_color_enum.BackgroundColorEnum]] = None, **kwargs)any

Shows spinner and calls given function, when function has ended the spinner stops

message: str

Message of the spinner

call: Callable

Function to call

args: list

Arguments of the function

text_foreground_color: Union[str, cpl.console.foreground_color_enum.ForegroundColorEnum]

Foreground color of the text

spinner_foreground_color: Union[str, cpl.console.foreground_color_enum.ForegroundColorEnum]

Foreground color of the spinner

text_background_color: Union[str, cpl.console.background_color_enum.BackgroundColorEnum]

Background color of the text

spinner_background_color: Union[str, cpl.console.background_color_enum.BackgroundColorEnum]

Background color of the spinner

kwargs: dict

Keyword arguments of the call

Return value of call

classmethod table(header: list, values: list)

Prints a table with header and values

header: List[str]

Header of the table

values: List[List[str]]

Values of the table

classmethod write(*args, end='')

Prints in active line

args: list

Elements to print

end: str

Last character to print

classmethod write_at(x: int, y: int, *args)

Prints at given position

x: int

X coordinate

y: int

Y coordinate

args: list

Elements to print

classmethod write_line(*args)

Prints to new line

args: list

Elements to print

classmethod write_line_at(x: int, y: int, *args)

Prints new line at given position

x: int

X coordinate

y: int

Y coordinate

args: list

Elements to print

cpl.console.console_call

class cpl.console.console_call.ConsoleCall(function: collections.abc.Callable, *args)

Bases: object

Represents a console call, for hold back when spinner is active

function: Callable

Function to call

args: list

List of arguments

property args
property function

cpl.console.foreground_color_enum

class cpl.console.foreground_color_enum.ForegroundColorEnum(value)

Bases: enum.Enum

An enumeration.

blue = 'blue'
cyan = 'cyan'
default = 'default'
green = 'green'
grey = 'grey'
magenta = 'magenta'
red = 'red'
white = 'white'
yellow = 'yellow'

cpl.console.spinner_thread

class cpl.console.spinner_thread.SpinnerThread(msg_len: int, foreground_color: cpl.console.foreground_color_enum.ForegroundColorEnum, background_color: cpl.console.background_color_enum.BackgroundColorEnum)

Bases: threading.Thread

Thread to show spinner in terminal

msg_len: int

Length of the message

foreground_color: cpl.console.foreground_color.ForegroundColorEnum

Foreground color of the spinner

background_color: cpl.console.background_color.BackgroundColorEnum

Background color of the spinner

exit()

Stops the spinner

run()None

Entry point of thread, shows the spinner

stop_spinning()

Stops the spinner