ProgressBar Reference¶
See the ProgressBar guide for usage examples.
A progress bar painted with a gradient while in progress, pulsing, and complete.
- In progress: the filled portion is painted with
colors. The gradient spans the whole bar width, so colors stay fixed in place and are revealed as the bar fills. The unfilled track keeps Rich'sstyle. - Complete (
completed >= total): the full bar is painted withfinished_colors, orcolorswhen that is omitted. - Pulsing (
pulse=Trueortotal=None): Rich's sliding pulse wave is kept, but the bright part of the wave takes its color frompulse_colors(orcolors), so the wave changes color as it moves and fades into the track's color.
When no colors are given, a palette is picked once (from the spectrum, or the full rainbow) and reused for every render, so a live display does not flicker.
Examples:
>>> from rich.console import Console
>>> console = Console()
>>> console.print(ProgressBar(total=100, completed=60, colors=["#38bdf8", "#a855f7"]))
>>> console.print(ProgressBar(total=10, completed=10, finished_colors=["#22c55e", "#a3e635"]))
>>> console.print(ProgressBar(total=None, pulse_colors=["#f43f5e", "#f59e0b"]))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
total
|
Optional[float]
|
Number of steps, or |
100.0
|
completed
|
float
|
Number of completed steps. Defaults to 0. |
0
|
width
|
Optional[int]
|
Fixed width in cells, or |
None
|
pulse
|
bool
|
Show the pulse animation instead of progress, e.g. before a task starts. Defaults to False. |
False
|
style
|
StyleType
|
Style of the unfilled track. A style string or
|
'bar.back'
|
complete_style
|
StyleType
|
Style of the filled portion, under the gradient. A
style string or |
'bar.complete'
|
finished_style
|
StyleType
|
Style used once the bar is complete. A style string
or |
'bar.finished'
|
pulse_style
|
StyleType
|
Style used for the pulse wave on terminals without
color blending, where Rich's plain pulse is drawn. A style string or
|
'bar.pulse'
|
animation_time
|
Optional[float]
|
Time in seconds that drives the pulse
position, e.g. |
None
|
colors
|
Optional[Sequence[ColorType]]
|
Foreground color stops. Each stop may be
a color name (Rich/ANSI names such as |
None
|
pulse_colors
|
Optional[Sequence[ColorType]]
|
Color stops for the pulse wave, in
the same formats as |
None
|
finished_colors
|
Optional[Sequence[ColorType]]
|
Color stops for a complete bar,
in the same formats as |
None
|
rainbow
|
bool
|
Use the full 17-color spectrum palette, ignoring |
False
|
hues
|
int
|
Number of colors to take from the spectrum palette when |
5
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/rich_gradient/progress_bar.py
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 | |
percentage_completed
property
¶
The completion percentage (0-100), or None if indeterminate.
__getattr__(name)
¶
Expose Rich's bar state (completed, total, styles, ...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The attribute being looked up. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The attribute's value on the wrapped |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If |
Source code in src/rich_gradient/progress_bar.py
__init__(total=100.0, completed=0, width=None, pulse=False, style='bar.back', complete_style='bar.complete', finished_style='bar.finished', pulse_style='bar.pulse', animation_time=None, *, colors=None, pulse_colors=None, finished_colors=None, rainbow=False, hues=5)
¶
Initialize the gradient progress bar; see the class docstring for arguments.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/rich_gradient/progress_bar.py
__rich_console__(console, options)
¶
Render the bar with gradient colors for its current state.
Filled cells are identified by position (mirroring Rich's own width math), not by color, so they are found even when the fill and track share a color. The gradient replaces only the foreground; Rich's fill style keeps its background and attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
console
|
Console
|
The console being rendered to. |
required |
options
|
ConsoleOptions
|
The console options for the current render. |
required |
Yields:
| Type | Description |
|---|---|
RenderResult
|
The bar's segments, with gradient colors on the filled cells (or the |
RenderResult
|
pulse wave). |
Source code in src/rich_gradient/progress_bar.py
__rich_measure__(console, options)
¶
Delegate measurement to Rich's bar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
console
|
Console
|
The console used for measurement. |
required |
options
|
ConsoleOptions
|
The console options for the current render. |
required |
Returns:
| Type | Description |
|---|---|
Measurement
|
The wrapped Rich bar's measurement. |
Source code in src/rich_gradient/progress_bar.py
__setattr__(name, value)
¶
Route Rich's bar state attributes to the wrapped bar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The attribute being set. |
required |
value
|
Any
|
The new value. |
required |
Source code in src/rich_gradient/progress_bar.py
update(completed, total=None)
¶
Update progress.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
completed
|
float
|
Number of completed steps, e.g. |
required |
total
|
float | None
|
New total number of steps. Defaults to None, which leaves the total unchanged. |
None
|
Source code in src/rich_gradient/progress_bar.py
Bases: BarColumn
A rich.progress bar column that draws gradient ProgressBar bars.
Use it in place of rich.progress.BarColumn. Running tasks show the
in-progress gradient, finished tasks the finished gradient, and tasks that
have not started (or have no total) the gradient pulse. The palette is picked
once when the column is created, so colors stay steady while the display
refreshes.
Examples:
>>> from rich.progress import Progress, TextColumn
>>> with Progress(
... TextColumn("{task.description}"),
... GradientBarColumn(colors=["#38bdf8", "#a855f7"], finished_colors=["#22c55e", "#a3e635"]),
... ) as progress:
... task = progress.add_task("Downloading", total=100)
... progress.update(task, advance=50)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bar_width
|
Optional[int]
|
Width of each bar in cells, or |
40
|
style
|
StyleType
|
Style of the unfilled track (and the color the pulse fades
into). A style string or |
'bar.back'
|
complete_style
|
StyleType
|
Style of the filled portion, under the gradient. A
style string or |
'bar.complete'
|
finished_style
|
StyleType
|
Style used once a task is complete. A style string
or |
'bar.finished'
|
pulse_style
|
StyleType
|
Style of the pulse on terminals without color
blending. A style string or |
'bar.pulse'
|
table_column
|
Optional[Column]
|
Column settings for the progress table, e.g.
|
None
|
colors
|
Optional[Sequence[ColorType]]
|
Foreground color stops for running
tasks, in any format |
None
|
pulse_colors
|
Optional[Sequence[ColorType]]
|
Color stops for the pulse wave,
e.g. |
None
|
finished_colors
|
Optional[Sequence[ColorType]]
|
Color stops for finished tasks,
e.g. |
None
|
rainbow
|
bool
|
Use the full 17-color spectrum palette, ignoring |
False
|
hues
|
int
|
Number of colors to take from the spectrum palette when |
5
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/rich_gradient/progress_bar.py
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 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | |
__init__(bar_width=40, style='bar.back', complete_style='bar.complete', finished_style='bar.finished', pulse_style='bar.pulse', table_column=None, *, colors=None, pulse_colors=None, finished_colors=None, rainbow=False, hues=5)
¶
Initialize the gradient bar column; see the class docstring for arguments.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/rich_gradient/progress_bar.py
render(task)
¶
Build the gradient bar for a task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Task
|
The |
required |
Returns:
| Type | Description |
|---|---|
ProgressBar
|
A gradient |