Console helper module

class rebasehelper.helpers.console_helper.ConsoleHelper[source]

Class for interacting with the command line.

class Capturer(stdout=False, stderr=False)[source]

ContextManager for capturing stdout/stderr

static color_is_light(rgb, bit_width)[source]

Determines whether a color is light or dark.

Parameters:
  • rgb (tuple) – RGB tuple.

  • bit_width – Number of bits defining the RGB.

Returns:

Whether a color is light or dark.

Return type:

bool

classmethod cprint(message, prefix='', suffix='')[source]

Prints colored output if possible.

Parameters:
  • message (str) – String to be printed out.

  • prefix (str) – ANSI escape sequence prefix.

  • suffix (str) – ANSI escape sequence suffix.

static detect_background()[source]

Detects terminal background color and decides whether it is light or dark.

Returns:

Whether to use dark or light color scheme.

Return type:

str

static exchange_control_sequence(query, timeout=0.05)[source]

Captures a response of a control sequence from STDIN.

Parameters:
  • query (str) – Control sequence.

  • timeout (int, float) – Time given to the terminal to react.

Returns:

Response of the terminal.

Return type:

str

static parse_rgb_device_specification(specification)[source]

Parses RGB device specification.

Parameters:

specification (str) – RGB device specification.

Returns:

If the specification follows correct format, the first element is RGB tuple and the second is bit width of the RGB. Otherwise, both elements are None.

Return type:

tuple

classmethod should_use_colors(conf)[source]

Determines whether ANSI colors should be used for CLI output.

Parameters:

conf (rebasehelper.config.Config) – Configuration object with arguments from the command line.

Returns:

Whether colors should be used.

Return type:

bool

use_colors: bool = False