Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds expand Parameter to track wrap_file open in rich.progress for Full-Width Progress Bars #3589

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- Adds `expand` argument to `track` `wrap_file` `open` in `rich.progress` for full-width progress bar. https://github.com/Textualize/rich/pull/3589

## [13.9.4] - 2024-11-01

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,4 @@ The following people have contributed to the development of Rich:
- [L. Yeung](https://github.com/lewis-yeung)
- [chthollyphile](https://github.com/chthollyphile)
- [Jonathan Helmus](https://github.com/jjhelmus)
- [Peishan Yang](https://github.com/PeiPei233)
14 changes: 14 additions & 0 deletions rich/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def track(
update_period: float = 0.1,
disable: bool = False,
show_speed: bool = True,
expand: bool = False,
) -> Iterable[ProgressType]:
"""Track progress by iterating over a sequence.

Expand All @@ -141,6 +142,7 @@ def track(
update_period (float, optional): Minimum time (in seconds) between calls to update(). Defaults to 0.1.
disable (bool, optional): Disable display of progress.
show_speed (bool, optional): Show speed if total isn't known. Defaults to True.
expand (bool, optional): Expand the progress display to fill the width of the console. Defaults to False.
Returns:
Iterable[ProgressType]: An iterable of the values in the sequence.

Expand All @@ -152,6 +154,7 @@ def track(
columns.extend(
(
BarColumn(
bar_width=None if expand else 40,
style=style,
complete_style=complete_style,
finished_style=finished_style,
Expand All @@ -169,6 +172,7 @@ def track(
get_time=get_time,
refresh_per_second=refresh_per_second or 10,
disable=disable,
expand=expand,
)

with progress:
Expand Down Expand Up @@ -320,6 +324,7 @@ def wrap_file(
finished_style: StyleType = "bar.finished",
pulse_style: StyleType = "bar.pulse",
disable: bool = False,
expand: bool = False,
) -> ContextManager[BinaryIO]:
"""Read bytes from a file while tracking progress.

Expand All @@ -336,6 +341,7 @@ def wrap_file(
finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished".
pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse".
disable (bool, optional): Disable display of progress.
expand (bool, optional): Expand the progress display to fill the width of the console. Defaults to False.
Returns:
ContextManager[BinaryIO]: A context manager yielding a progress reader.

Expand All @@ -347,6 +353,7 @@ def wrap_file(
columns.extend(
(
BarColumn(
bar_width=None if expand else 40,
style=style,
complete_style=complete_style,
finished_style=finished_style,
Expand All @@ -364,6 +371,7 @@ def wrap_file(
get_time=get_time,
refresh_per_second=refresh_per_second or 10,
disable=disable,
expand=expand,
)

reader = progress.wrap_file(file, total=total, description=description)
Expand Down Expand Up @@ -391,6 +399,7 @@ def open(
finished_style: StyleType = "bar.finished",
pulse_style: StyleType = "bar.pulse",
disable: bool = False,
expand: bool = False,
) -> ContextManager[TextIO]:
pass

Expand All @@ -416,6 +425,7 @@ def open(
finished_style: StyleType = "bar.finished",
pulse_style: StyleType = "bar.pulse",
disable: bool = False,
expand: bool = False,
) -> ContextManager[BinaryIO]:
pass

Expand All @@ -440,6 +450,7 @@ def open(
finished_style: StyleType = "bar.finished",
pulse_style: StyleType = "bar.pulse",
disable: bool = False,
expand: bool = False,
) -> Union[ContextManager[BinaryIO], ContextManager[TextIO]]:
"""Read bytes from a file while tracking progress.

Expand All @@ -462,6 +473,7 @@ def open(
pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse".
disable (bool, optional): Disable display of progress.
encoding (str, optional): The encoding to use when reading in text mode.
expand (bool, optional): Expand the progress display to fill the width of the console. Defaults to False.

Returns:
ContextManager[BinaryIO]: A context manager yielding a progress reader.
Expand All @@ -474,6 +486,7 @@ def open(
columns.extend(
(
BarColumn(
bar_width=None if expand else 40,
style=style,
complete_style=complete_style,
finished_style=finished_style,
Expand All @@ -491,6 +504,7 @@ def open(
get_time=get_time,
refresh_per_second=refresh_per_second or 10,
disable=disable,
expand=expand,
)

reader = progress.open(
Expand Down