Animation#

class Animation(message_template: AnyStr = 'Processing', enable_animation: bool = True)[source]#

Handles displaying an animated spinner with a message during long-running operations.

The Animation class provides a simple way to display a rotating spinner along with a customizable message in the terminal, which can be useful for indicating progress in asynchronous tasks.

Initialize the Animation object.

Sets up the necessary attributes for controlling the animation, including the message template, the spinner characters, and the color scheme.

Parameters:
  • message_template (AnyStr) – The base message to display alongside the spinner.

  • enable_animation (bool) – Flag to enable or disable the spinner animation.

async start()[source]#

Start the animation as an asyncio task.

This method initiates the spinner animation in an asynchronous task. If animation is disabled, this method does nothing.

async stop()[source]#

Stop the animation and wait for the task to finish.

This method stops the spinner animation by setting the stop event and waiting for the animation task to complete.

async update_msg(new_message_template: AnyStr)[source]#

Update the message template.

This method updates the message displayed alongside the spinner, clearing the previous message before displaying the new one.

Parameters:

new_message_template (AnyStr) – The new message to display alongside the spinner.

error_handling(log: LogMe)[source]#

Context manager for error handling with animation.

This context manager starts the spinner animation when entering the context, and stops it when exiting. If an exception occurs within the context, it is logged and then re-raised.

Parameters:

log (LogMe) – The logger object used to log any errors that occur within the context.