BaseEffect
Module: terminaltexteffects.engine.base_effect
Base classes for all effects.
Base classes from which all effects should inherit. These classes define the basic structure for an effect and establish the effect iterator interface as well as the effect configuration and terminal configuration.
Classes:
Name | Description |
---|---|
BaseEffectIterator |
An abstract base class that defines the basic structure for an iterator
that applies a certain effect to the input data. Provides initilization for the effect configuration and
terminal as well as the |
BaseEffect |
An abstract base class that defines the basic structure for an effect. Provides
the |
BaseEffect
Bases: ABC
, Generic[T]
Base iterable class for all effects.
Base class for all effects. Provides the __iter__
method and a context manager for terminal output.
Attributes:
Name | Type | Description |
---|---|---|
input_data |
str
|
Text to which the effect will be applied. |
effect_config |
T
|
Configuration for the effect. |
terminal_config |
TerminalConfig
|
Configuration for the terminal. |
Source code in terminaltexteffects/engine/base_effect.py
__init__(input_data)
Initialize the effect with the input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_data
|
str
|
Text to which the effect will be applied. |
required |
Source code in terminaltexteffects/engine/base_effect.py
__iter__()
Return the iterator object.
Returns:
Name | Type | Description |
---|---|---|
BaseEffectIterator |
BaseEffectIterator
|
Iterator object. |
terminal_output(end_symbol='\n')
Context manager for terminal output. Prepares the terminal for output and restores it after.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
end_symbol
|
str
|
Symbol to print after the effect has completed. Defaults to newline. |
'\n'
|
Yields:
Name | Type | Description |
---|---|---|
Terminal |
Terminal
|
Terminal object for handling output. |
Raises:
Type | Description |
---|---|
Exception
|
Any exception that occurs within the context manager will be raised before restoring the terminal state. |
Source code in terminaltexteffects/engine/base_effect.py
BaseEffectIterator
Bases: ABC
, Generic[T]
Base iterator class for all effects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
effect
|
BaseEffect
|
Effect to apply to the input data. |
required |
Attributes:
Name | Type | Description |
---|---|---|
config |
T
|
Configuration for the effect. |
terminal |
Terminal
|
Terminal to use for output. |
active_characters |
set[EffectCharacter]
|
Set of active characters in the effect. |
preexisting_colors_present |
bool
|
Whether any characters in the input data have preexisting colors. |
Properties: frame (str): Current frame of the effect.
Methods:
Name | Description |
---|---|
update |
Run the tick method for all active characters and remove inactive characters from the active list. |
__iter__ |
Return the iterator object. |
__next__ |
Return the next frame of the effect. |
Source code in terminaltexteffects/engine/base_effect.py
frame
property
Return the current frame by getting the formatted output string from the terminal.
If the frame rate is set >0 in the terminal configuration, enforce the frame rate.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Current frame of the effect. |
__init__(effect)
Initialize the iterator with the Effect.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
effect
|
BaseEffect
|
Effect to apply to the input data. |
required |
Source code in terminaltexteffects/engine/base_effect.py
__iter__()
Return the iterator object.
Returns:
Name | Type | Description |
---|---|---|
BaseEffectIterator |
BaseEffectIterator
|
Iterator object. |
__next__()
abstractmethod
Return the next frame of the effect.
Perform any necessary updates to the effect to progress the effect logic and return the next frame.
Raises:
Type | Description |
---|---|
NotImplementedError
|
This method must be implemented by the subclass. |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Next frame of the effect. |
Source code in terminaltexteffects/engine/base_effect.py
update()
Run the tick method for all active characters.
Remove inactive characters from the active_characters set.