# cpl_core.console — Common Python Library documentation

# cpl_core.console

## cpl_core.console.background_color_enum

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

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

    > 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

  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: 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[str], header_foreground_color: Union[str, ForegroundColorEnum ] = ForegroundColorEnum.default, header_background_color: Union[str, BackgroundColorEnum ] = BackgroundColorEnum.default, option_foreground_color: Union[str, ForegroundColorEnum ] = ForegroundColorEnum.default, option_background_color: Union[str, BackgroundColorEnum ] = BackgroundColorEnum.default, cursor_foreground_color: Union[str, ForegroundColorEnum ] = ForegroundColorEnum.default, cursor_background_color: Union[str, BackgroundColorEnum ] = BackgroundColorEnum.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_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

    > Selected option as `str`

  classmethod set_background_color(color: Union[ BackgroundColorEnum , str])

    Sets the background color

    > 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

    > x: `int`

    >   X coordinate

    > y: `int`

    >   Y coordinate

  classmethod set_foreground_color(color: Union[ ForegroundColorEnum , str])

    Sets the foreground color

    > 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: Optional[Union[str, ForegroundColorEnum ]] = None, spinner_foreground_color: Optional[Union[str, ForegroundColorEnum ]] = None, text_background_color: Optional[Union[str, BackgroundColorEnum ]] = None, spinner_background_color: Optional[Union[str, 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_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

    > Return value of call

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

    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_core.console.console_call

class cpl_core.console.console_call.ConsoleCall(function: 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_core.console.foreground_color_enum

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

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

  Bases: `Thread`

  Thread to show spinner in terminal

  > 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