Skip to content

logging.formatter.utils

Functions:

Name Description
non_ansi

Remove ansi escape characters from text.

Functions

non_ansi

non_ansi(text: str) -> str

Remove ansi escape characters from text.

References:

Parameters:

Name Type Description Default

text

str

Text to convert.

required

Returns:

Name Type Description
str str

text without ansi escape characters

Source code in dlr/ki/logging/formatter/utils.py
def non_ansi(text: str) -> str:
    """
    Remove ansi escape characters from text.

    References:

    - <https://stackoverflow.com/a/14693789>

    Args:
        text (str): Text to convert.

    Returns:
        str: text without ansi escape characters
    """
    ansi_escape = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
    return ansi_escape.sub("", text)