cpl_core.console package

Submodules

cpl_core.console.background_color_enum module

class cpl_core.console.background_color_enum.BackgroundColorEnum(value)

Bases: 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_core.console.console module

class cpl_core.console.console.Console

Bases: object

Useful functions for handling with input and output

class property background_color: str

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

classmethod banner(string: str)

Prints the string as a banner

Parameter:
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: str | None = None)

Prints an error with traceback

Parameter:
string: str

Error message

tb: str

Error traceback

class property foreground_color: str

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

classmethod read(output: str | None = None) str

Reads in line

Parameter:
output: str

String to print before input

Returns:

input()

classmethod read_line(output: str | None = None) str

Reads in next line

Parameter:
output: str

String to print before input

Returns:

input()

classmethod reset_cursor_position()

Resets cursor position

classmethod select(char: str, message: str, options: list[str], header_foreground_color: str | ForegroundColorEnum = ForegroundColorEnum.default, header_background_color: str | BackgroundColorEnum = BackgroundColorEnum.default, option_foreground_color: str | ForegroundColorEnum = ForegroundColorEnum.default, option_background_color: str | BackgroundColorEnum = BackgroundColorEnum.default, cursor_foreground_color: str | ForegroundColorEnum = ForegroundColorEnum.default, cursor_background_color: str | BackgroundColorEnum = BackgroundColorEnum.default) str

Prints select menu

Parameter:
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_core.console.foreground_color_enum.ForegroundColorEnum]

Foreground color of the header

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

Background color of the header

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

Foreground color of the options

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

Background color of the options

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

Foreground color of the cursor

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

Background color of the cursor

Returns:

Selected option as str

classmethod set_background_color(color: BackgroundColorEnum | str)

Sets the background color

Parameter:
color: Union[cpl_core.console.background_color_enum.BackgroundColorEnum, str]

Background color of the console

classmethod set_cursor_position(x: int, y: int)

Sets cursor position

Parameter:
x: int

X coordinate

y: int

Y coordinate

classmethod set_foreground_color(color: ForegroundColorEnum | str)

Sets the foreground color

Parameter:
color: Union[cpl_core.console.background_color_enum.BackgroundColorEnum, str]

Foreground color of the console

classmethod set_hold_back(value: bool)
classmethod spinner(message: str, call: Callable, *args, text_foreground_color: str | ForegroundColorEnum | None = None, spinner_foreground_color: str | ForegroundColorEnum | None = None, text_background_color: str | BackgroundColorEnum | None = None, spinner_background_color: str | BackgroundColorEnum | None = None, **kwargs) any

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

Parameter:
message: str

Message of the spinner

call: Callable

Function to call

args: list

Arguments of the function

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

Foreground color of the text

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

Foreground color of the spinner

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

Background color of the text

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

Background color of the spinner

kwargs: dict

Keyword arguments of the call

Returns:

Return value of call

classmethod table(header: list[str], values: list[list[str]])

Prints a table with header and values

Parameter:
header: List[str]

Header of the table

values: List[List[str]]

Values of the table

classmethod write(*args, end='')

Prints in active line

Parameter:
args: list

Elements to print

end: str

Last character to print

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

Prints at given position

Parameter:
x: int

X coordinate

y: int

Y coordinate

args: list

Elements to print

classmethod write_line(*args)

Prints to new line

Parameter:
args: list

Elements to print

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

Prints new line at given position

Parameter:
x: int

X coordinate

y: int

Y coordinate

args: list

Elements to print

cpl_core.console.console_call module

class cpl_core.console.console_call.ConsoleCall(function: Callable, *args)

Bases: object

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

Parameter:
function: Callable

Function to call

args: list

List of arguments

property args
property function

cpl_core.console.foreground_color_enum module

class cpl_core.console.foreground_color_enum.ForegroundColorEnum(value)

Bases: Enum

An enumeration.

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

cpl_core.console.spinner_thread module

class cpl_core.console.spinner_thread.SpinnerThread(msg_len: int, foreground_color: ForegroundColorEnum, background_color: BackgroundColorEnum)

Bases: Thread

Thread to show spinner in terminal

Parameter:
msg_len: int

Length of the message

foreground_color: cpl_core.console.foreground_color.ForegroundColorEnum

Foreground color of the spinner

background_color: cpl_core.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

Module contents

cpl-core CPL core

CPL core package

copyright:
  1. 2020 - 2023 sh-edraft.de

license:

MIT, see LICENSE for more details.

class cpl_core.console.VersionInfo(major, minor, micro)

Bases: tuple

major

Alias for field number 0

micro

Alias for field number 2

minor

Alias for field number 1