Skip to content

CharacterVisual

Module: terminaltexteffects.engine.animation

A class for storing symbol, color, and terminal graphical modes for the character.

Parameters:

Name Type Description Default
symbol str

the unformatted symbol

required
bold bool

bold mode

False
dim bool

dim mode

False
italic bool

italic mode

False
underline bool

underline mode

False
blink bool

blink mode

False
reverse bool

reverse mode

False
hidden bool

hidden mode

False
strike bool

strike mode

False
color Color | None

color to display the symbol

None

Attributes:

Name Type Description
formatted_symbol str

the current symbol with all ANSI sequences applied

Source code in terminaltexteffects/engine/animation.py
@dataclass
class CharacterVisual:
    """A class for storing symbol, color, and terminal graphical modes for the character.

    Args:
        symbol (str): the unformatted symbol
        bold (bool): bold mode
        dim (bool): dim mode
        italic (bool): italic mode
        underline (bool): underline mode
        blink (bool): blink mode
        reverse (bool): reverse mode
        hidden (bool): hidden mode
        strike (bool): strike mode
        color (graphics.Color | None): color to display the symbol

    Attributes:
        formatted_symbol (str): the current symbol with all ANSI sequences applied
    """

    symbol: str
    bold: bool = False
    dim: bool = False
    italic: bool = False
    underline: bool = False
    blink: bool = False
    reverse: bool = False
    hidden: bool = False
    strike: bool = False
    color: graphics.Color | None = None
    _color_code: str | int | None = None

    def __post_init__(self):
        self.formatted_symbol = self.format_symbol()

    def disable_modes(self) -> None:
        """Disables all graphical modes."""
        self.bold = False
        self.dim = False
        self.italic = False
        self.underline = False
        self.blink = False
        self.reverse = False
        self.hidden = False
        self.strike = False

    def format_symbol(self) -> str:
        """Formats the symbol for printing by applying ANSI sequences for any active modes and color."""
        formatting_string = ""
        if self.bold:
            formatting_string += ansitools.APPLY_BOLD()
        if self.italic:
            formatting_string += ansitools.APPLY_ITALIC()
        if self.underline:
            formatting_string += ansitools.APPLY_UNDERLINE()
        if self.blink:
            formatting_string += ansitools.APPLY_BLINK()
        if self.reverse:
            formatting_string += ansitools.APPLY_REVERSE()
        if self.hidden:
            formatting_string += ansitools.APPLY_HIDDEN()
        if self.strike:
            formatting_string += ansitools.APPLY_STRIKETHROUGH()
        if self._color_code is not None:
            formatting_string += colorterm.fg(self._color_code)

        return f"{formatting_string}{self.symbol}{ansitools.RESET_ALL() if formatting_string else ''}"

disable_modes()

Disables all graphical modes.

Source code in terminaltexteffects/engine/animation.py
def disable_modes(self) -> None:
    """Disables all graphical modes."""
    self.bold = False
    self.dim = False
    self.italic = False
    self.underline = False
    self.blink = False
    self.reverse = False
    self.hidden = False
    self.strike = False

format_symbol()

Formats the symbol for printing by applying ANSI sequences for any active modes and color.

Source code in terminaltexteffects/engine/animation.py
def format_symbol(self) -> str:
    """Formats the symbol for printing by applying ANSI sequences for any active modes and color."""
    formatting_string = ""
    if self.bold:
        formatting_string += ansitools.APPLY_BOLD()
    if self.italic:
        formatting_string += ansitools.APPLY_ITALIC()
    if self.underline:
        formatting_string += ansitools.APPLY_UNDERLINE()
    if self.blink:
        formatting_string += ansitools.APPLY_BLINK()
    if self.reverse:
        formatting_string += ansitools.APPLY_REVERSE()
    if self.hidden:
        formatting_string += ansitools.APPLY_HIDDEN()
    if self.strike:
        formatting_string += ansitools.APPLY_STRIKETHROUGH()
    if self._color_code is not None:
        formatting_string += colorterm.fg(self._color_code)

    return f"{formatting_string}{self.symbol}{ansitools.RESET_ALL() if formatting_string else ''}"