Skip to content

ColorTerm

Module: terminaltexteffects.utils.colorterm

This module converts xterm color codes and hex colors into ANSI escape sequences.

bg(color_code)

Sets the background color of the terminal text.

Parameters:

Name Type Description Default
color_code str | int

The value to set the background color, as a hex string or X-Term 256 color code.

required

Returns:

Name Type Description
str str

The ANSI escape sequence to set the background color.

Source code in terminaltexteffects/utils/colorterm.py
def bg(color_code: str | int) -> str:
    """
    Sets the background color of the terminal text.

    Args:
        color_code (str | int): The value to set the background color, as a hex string or X-Term 256 color code.

    Returns:
        str: The ANSI escape sequence to set the background color.

    """
    sequence = _color(color_code, 48)
    return sequence

fg(color_code)

Sets the foreground color of the terminal text.

Parameters:

Name Type Description Default
color_code str | int

The value to set the foreground color, as a hex string or X-Term 256 color code.

required

Returns:

Name Type Description
str str

The ANSI escape sequence to set the foreground color.

Source code in terminaltexteffects/utils/colorterm.py
def fg(color_code: str | int) -> str:
    """
    Sets the foreground color of the terminal text.

    Args:
        color_code (str | int): The value to set the foreground color, as a hex string or X-Term 256 color code.

    Returns:
        str: The ANSI escape sequence to set the foreground color.

    """
    sequence = _color(color_code, 38)
    return sequence