Animation#

class Animation(message_template: str = '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.

Necessary attributes for controlling the Animation are set up during initialization of Animation objects (e.g., the message template, spinner characters, and color scheme).

Parameters:
  • message_template (str) – 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. If animation is disabled, this method does nothing.

async stop()[source]#

Stops the spinner animation by setting the stop event and waiting for the animation task to complete.

async update_msg(new_message_template: str)[source]#

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

Parameters:

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

error_handling()[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 stops the animation and re-raises the exception.