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, fg=None, bg=None, style=None)[source]

Prints colored output if possible.

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

  • fg (str) – Foreground color.

  • bg (str) – Background color.

  • style (str) – Style to be applied to the printed message. Possible styles: bold, faint, italic, underline, blink, blink2, negative, concealed, crossed. Some styles may not be supported by every terminal, e.g. ‘blink’. Multiple styles should be connected with a ‘+’, e.g. ‘bold+italic’.

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