Skip to content

Animation

rich-gradient provides animated variants of its core renderables for live terminal demos. They build on rich.live.Live to refresh the console at a steady frame rate while shifting the gradient phase.

AnimatedGradient

Animated gradient

from rich.console import Console
from rich.markdown import Markdown
from rich_gradient.animated_gradient import AnimatedGradient

console = Console()
markdown = Markdown(
    "[b]Animated gradients[/b]\n\n"
    "- Run as a context manager\n"
    "- Or control start/stop manually\n"
)

with AnimatedGradient(
    markdown,
    rainbow=True,
    console=console,
) as gradient:
    console.input("[dim]Press Enter to stop...[/dim]")

Key parameters:

  • refresh_per_second: desired frame rate for the Live render loop.
  • repeat_scale: stretch the palette across a wider span before repeating.
  • highlight_words / highlight_regex: identical to the static Gradient.
  • start(), stop(), run(): manual control when you want to integrate with custom event loops.
  • Defaults honour the global configuration; see Configuration for details.

AnimatedPanel

Animated panel

AnimatedPanel wraps the static Panel helper, so it inherits title and subtitle highlighting alongside the animation controls above.

from rich.panel import Panel as RichPanel
from rich_gradient.animated_panel import AnimatedPanel

panel = RichPanel(
    "Rainbow [i]AnimatedPanel[/i] in motion",
    title="Animated Panel",
    padding=(1, 2),
)

animated = AnimatedPanel(
    panel,
    rainbow=True,
    refresh_per_second=40,
)
try:
    animated.run()
finally:
    animated.stop()

Both animated classes forward console, expand, justify, and color configuration to their static counterparts, making it easy to switch between live demos and static output.