Skip to content

ANSItools

Module: terminaltexteffects.utils.ansitools

This module provides a collection of functions that generate ANSI escape codes for various terminal formatting effects. These escape codes can be used to modify the appearance of text in a terminal.

Applies blink formatting.

Returns:

Name Type Description
str str

ANSI escape code

Source code in terminaltexteffects/utils/ansitools.py
def APPLY_BLINK() -> str:
    """Applies blink formatting.

    Returns:
        str: ANSI escape code
    """
    return "\033[5m"

APPLY_BOLD()

Applies bold formatting.

Returns:

Name Type Description
str str

ANSI escape code

Source code in terminaltexteffects/utils/ansitools.py
def APPLY_BOLD() -> str:
    """Applies bold formatting.

    Returns:
        str: ANSI escape code
    """
    return "\033[1m"

APPLY_DIM()

Applies dim formatting.

Returns:

Name Type Description
str str

ANSI escape code

Source code in terminaltexteffects/utils/ansitools.py
def APPLY_DIM() -> str:
    """Applies dim formatting.

    Returns:
        str: ANSI escape code
    """
    return "\033[2m"

APPLY_HIDDEN()

Applies hidden formatting.

Returns:

Name Type Description
str str

ANSI escape code

Source code in terminaltexteffects/utils/ansitools.py
def APPLY_HIDDEN() -> str:
    """Applies hidden formatting.

    Returns:
        str: ANSI escape code
    """
    return "\033[8m"

APPLY_ITALIC()

Applies italic formatting.

Returns:

Name Type Description
str str

ANSI escape code

Source code in terminaltexteffects/utils/ansitools.py
def APPLY_ITALIC() -> str:
    """Applies italic formatting.

    Returns:
        str: ANSI escape code
    """
    return "\033[3m"

APPLY_REVERSE()

Applies reverse formatting.

Returns:

Name Type Description
str str

ANSI escape code

Source code in terminaltexteffects/utils/ansitools.py
def APPLY_REVERSE() -> str:
    """Applies reverse formatting.

    Returns:
        str: ANSI escape code
    """
    return "\033[7m"

APPLY_STRIKETHROUGH()

Applies strikethrough formatting.

Returns:

Name Type Description
str str

ANSI escape code

Source code in terminaltexteffects/utils/ansitools.py
def APPLY_STRIKETHROUGH() -> str:
    """Applies strikethrough formatting.

    Returns:
        str: ANSI escape code
    """
    return "\033[9m"

APPLY_UNDERLINE()

Applies underline formatting.

Returns:

Name Type Description
str str

ANSI escape code

Source code in terminaltexteffects/utils/ansitools.py
def APPLY_UNDERLINE() -> str:
    """Applies underline formatting.

    Returns:
        str: ANSI escape code
    """
    return "\033[4m"

DEC_RESTORE_CURSOR_POSITION()

Restores the cursor position using DEC sequence.

Returns:

Name Type Description
str str

ANSI escape code

Source code in terminaltexteffects/utils/ansitools.py
def DEC_RESTORE_CURSOR_POSITION() -> str:
    """Restores the cursor position using DEC sequence.

    Returns:
        str: ANSI escape code
    """
    return "\0338"

DEC_SAVE_CURSOR_POSITION()

Saves the cursor position using DEC sequence.

Returns:

Name Type Description
str str

ANSI escape code

Source code in terminaltexteffects/utils/ansitools.py
def DEC_SAVE_CURSOR_POSITION() -> str:
    """Saves the cursor position using DEC sequence.

    Returns:
        str: ANSI escape code
    """
    return "\0337"

HIDE_CURSOR()

Hides the cursor.

Returns:

Name Type Description
str str

ANSI escape code

Source code in terminaltexteffects/utils/ansitools.py
def HIDE_CURSOR() -> str:
    """Hides the cursor.

    Returns:
        str: ANSI escape code
    """
    return "\033[?25l"

MOVE_CURSOR_TO_COLUMN(x)

Moves the cursor to the x column.

Parameters:

Name Type Description Default
x int

column number

required

Returns:

Name Type Description
str str

ANSI escape code

Source code in terminaltexteffects/utils/ansitools.py
def MOVE_CURSOR_TO_COLUMN(x: int) -> str:
    """Moves the cursor to the x column.

    Args:
        x (int): column number

    Returns:
        str: ANSI escape code
    """
    return f"\033[{x}G"

MOVE_CURSOR_UP(y)

Moves the cursor up y lines.

Parameters:

Name Type Description Default
y int

number of lines to move up

required

Returns:

Name Type Description
str str

ANSI escape code

Source code in terminaltexteffects/utils/ansitools.py
def MOVE_CURSOR_UP(y: int) -> str:
    """Moves the cursor up y lines.

    Args:
        y (int): number of lines to move up

    Returns:
        str: ANSI escape code
    """
    return f"\033[{y}A"

RESET_ALL()

Resets all formatting.

Returns:

Name Type Description
str str

ANSI escape code

Source code in terminaltexteffects/utils/ansitools.py
def RESET_ALL() -> str:
    """Resets all formatting.

    Returns:
        str: ANSI escape code
    """
    return "\033[0m"

SHOW_CURSOR()

Shows the cursor.

Returns:

Name Type Description
str str

ANSI escape code

Source code in terminaltexteffects/utils/ansitools.py
def SHOW_CURSOR() -> str:
    """Shows the cursor.

    Returns:
        str: ANSI escape code
    """
    return "\033[?25h"