Merge pull request #1142 from CounterPillow/progressbar-hidden-label
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by GitHub · parents 69a25da, e745081 · Browse files · 4 files·+16 added−5 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- progressbar: fix regression with hidden bars
Diff stats
4 files+16 added−5 removed
- tests:+2 added−3 removed
- other:+14 added−2 removed
Provenance
- Commit
3018f57- Tree
654f36e- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
69a25da- Parent 2
e745081
4 files changed+16 added−5 removed
modified:src/click/_termui_impl.py+6 added
225 unmodified lines226 def render_progress(self):227 import shutil228 229 if self.is_hidden:230+ # Only output the label as it changes if the output is not a231+ # TTY. Use file=stderr if you expect to be piping stdout.232+ if self._last_line != self.label:233+ self._last_line = self.label234+ echo(self.label, file=self.file, color=self.color)235+236 return237 238 buf = []239 # Update width in case the terminal has been resized453 unmodified linesmodified:src/click/termui.py+6 added-2 removed
379 unmodified lines380 info section.381 :param info_sep: the separator between multiple info items (eta etc.)382 :param width: the width of the progress bar in characters, 0 means full383 terminal width384- :param file: the file to write to. If this is not a terminal then385- only the label is printed.384+ :param file: The file to write to. If this is not a terminal then385+ only the label is printed.386 :param color: controls if the terminal supports ANSI colors or not. The387 default is autodetection. This is only needed if ANSI388 codes are included anywhere in the progress bar output389 which is not the case by default.390 :param update_min_steps: Render only when this many updates have391 completed. This allows tuning for very fast iterators.392 393+ .. versionchanged:: 8.0394+ Labels are echoed if the output is not a TTY. Reverts a change395+ in 7.0 that removed all output.396+397 .. versionadded:: 8.0398 Added the ``update_min_steps`` parameter.399 400 .. versionchanged:: 4.0345 unmodified linesmodified:tests/test_termui.py+2 added-3 removed
74 unmodified lines75 76 77 def test_progressbar_hidden(runner, monkeypatch):78 fake_clock = FakeClock()79- label = "whatever"79 80 @click.command()81 def cli():83- with _create_progress(label=label) as progress:82+ with _create_progress(label="working") as progress:83 for _ in progress:84 fake_clock.advance_time()85 86 monkeypatch.setattr(time, "time", fake_clock.time)87 monkeypatch.setattr(click._termui_impl, "isatty", lambda _: False)89- assert runner.invoke(cli, []).output == ""88+ assert runner.invoke(cli, []).output == "working\n"89 90 91 @pytest.mark.parametrize("avg, expected", [([], 0.0), ([1, 4], 2.5)])92 def test_progressbar_time_per_iteration(runner, avg, expected):379 unmodified linesmodified:CHANGES.rst+2 added
172 unmodified lines173 - ``confirmation_prompt`` can be set to a custom string. :issue:`723`174 - Allow styled output in Jupyter on Windows. :issue:`1271`175 - ``style()`` supports the ``strikethrough`` style. :issue:`805`176 - Multiline marker is removed from short help text. :issue:`1597`177+- Restore progress bar behavior of echoing only the label if the file178+ is not a TTY. :issue:`1138`179 180 181 Version 7.1.2182 -------------635 unmodified lines