Skip to content

Commit

Permalink
Rename default_columns to get_default_columns, and add docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
ptmcg committed Jan 31, 2022
1 parent b079452 commit 76e234b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
28 changes: 25 additions & 3 deletions rich/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def __init__(
refresh_per_second is None or refresh_per_second > 0
), "refresh_per_second must be > 0"
self._lock = RLock()
self.columns = columns or self.default_columns()
self.columns = columns or self.get_default_columns()
self.speed_estimate_period = speed_estimate_period

self.disable = disable
Expand All @@ -609,7 +609,29 @@ def __init__(
self.log = self.console.log

@classmethod
def default_columns(cls) -> Tuple[ProgressColumn, ...]:
def get_default_columns(cls) -> Tuple[ProgressColumn, ...]:
"""Get the default columns used for a new Progress instance:
- a text column for the description (TextColumn)
- the bar itself (BarColumn)
- a text column showing completion percentage (TextColumn)
- an estimated-time-remaining column (TimeRemainingColumn)
If the Progress instance is created without passing a columns argument,
the default columns defined here will be used.
You can also create a Progress instance using custom columns before
and/or after the defaults, as in this example:
progress = Progress(
SpinnerColumn(),
*Progress.default_columns(),
"Elapsed:",
TimeElapsedColumn(),
)
This code shows the creation of a Progress display, containing
a spinner to the left, the default columns, and a labeled elapsed
time column.
"""
return (
TextColumn("[progress.description]{task.description}"),
BarColumn(),
Expand Down Expand Up @@ -1019,7 +1041,7 @@ def remove_task(self, task_id: TaskID) -> None:

with Progress(
SpinnerColumn(),
*Progress.default_columns(),
*Progress.get_default_columns(),
TimeElapsedColumn(),
console=console,
transient=True,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def test_using_default_columns() -> None:

progress = Progress(
SpinnerColumn(),
*Progress.default_columns(),
*Progress.get_default_columns(),
"Elapsed:",
TimeElapsedColumn(),
)
Expand Down

0 comments on commit 76e234b

Please sign in to comment.