Animated Gradient Reference
AnimatedGradient¶
Bases: Gradient
A gradient that animates over time using rich.live.Live.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
renderables
|
RenderableType | Iterable[RenderableType] | None
|
A renderable or
an iterable of renderables to animate. Strings are parsed as console markup,
e.g. |
None
|
colors
|
Optional[list[ColorType]]
|
Foreground color stops. Each stop may be a
color name (Rich/ANSI names such as |
None
|
bg_colors
|
Optional[list[ColorType]]
|
Background color stops, in the same
formats as |
None
|
hues
|
int
|
Number of colors to take from the spectrum palette when |
5
|
rainbow
|
bool
|
Use the full 17-color spectrum palette, ignoring |
False
|
repeat_scale
|
float
|
Width of one full color cycle as a multiple of the rendered width; larger values give a more gradual gradient. Defaults to 4.0. |
4.0
|
expand
|
bool
|
Expand the output to the full console width. Defaults to True. |
True
|
justify
|
AlignMethod
|
Horizontal alignment of the content: |
'left'
|
vertical_justify
|
VerticalAlignMethod
|
Vertical alignment of the content:
|
'top'
|
highlight_words
|
Optional[Mapping | Sequence]
|
Words to restyle on top of the
gradient. Accepts a mapping of a word (or a tuple of words) to a style, e.g.
|
None
|
highlight_regex
|
Optional[Mapping | Sequence]
|
Regular expressions whose
matches are restyled on top of the gradient. Accepts a mapping of a pattern
to a style, e.g. |
None
|
console
|
Optional[Console]
|
Console used for rendering and measurement.
Defaults to |
None
|
redirect_stdout
|
bool
|
Redirect |
False
|
redirect_stderr
|
bool
|
Redirect |
False
|
auto_refresh
|
bool
|
Let |
True
|
refresh_per_second
|
float
|
Live refresh and animation frame rate, in frames per second. Must be positive. Defaults to 30.0. |
30.0
|
transient
|
bool
|
Clear the output from the terminal when the animation stops. Defaults to False. |
False
|
animate
|
Optional[bool]
|
Whether to animate. The global config is a kill
switch: when |
True
|
duration
|
Optional[float]
|
Seconds after which a running animation stops on its
own, e.g. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
Or as a context manager:
Source code in src/rich_gradient/animated_gradient.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
live_console
property
writable
¶
The console used by the Live instance.
__enter__()
¶
Start the animation when entering a with block.
Returns:
| Type | Description |
|---|---|
AnimatedGradient
|
This |
__exit__(exc_type, exc, tb)
¶
Stop the animation when leaving a with block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc_type
|
object
|
The exception type raised in the block, if any. |
required |
exc
|
object
|
The exception instance raised in the block, if any. |
required |
tb
|
object
|
The traceback of the exception, if any. |
required |
Returns:
| Type | Description |
|---|---|
Literal[False]
|
|
Source code in src/rich_gradient/animated_gradient.py
__init__(renderables=None, colors=None, bg_colors=None, hues=5, rainbow=False, repeat_scale=4.0, expand=True, justify='left', vertical_justify='top', highlight_words=None, highlight_regex=None, console=None, redirect_stdout=False, redirect_stderr=False, auto_refresh=True, refresh_per_second=30.0, transient=False, animate=True, duration=None)
¶
Initialize the animated gradient; see the class docstring for arguments.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/rich_gradient/animated_gradient.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
get_animated(animate=True)
¶
Resolve whether animation is enabled.
The global config is a kill switch: when config.animation_enabled
is False ("animate": false in the config file, or
RICH_GRADIENT_ANIMATE=0), nothing animates, even if animate is
True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
animate
|
bool | None
|
Whether this instance should animate. |
True
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/rich_gradient/animated_gradient.py
get_renderable()
¶
Build the renderable the Live instance should display each frame.
Returns:
| Type | Description |
|---|---|
ConsoleRenderable
|
This gradient wrapped in an |
ConsoleRenderable
|
|
Raises:
| Type | Description |
|---|---|
AssertionError
|
If no renderables have been set. |
Source code in src/rich_gradient/animated_gradient.py
run()
¶
Blocking helper: start, then wait for Ctrl+C, then stop.
Source code in src/rich_gradient/animated_gradient.py
start()
¶
Start the Live context and the animation loop in a background thread.
Source code in src/rich_gradient/animated_gradient.py
stop()
¶
Signal the animation to stop, wait for the thread, and close Live.