Repository: pallets/click

Issue:
Progressbar regression: label no longer printed if output is not to a tty
The progressbar documentation says:

```
    :param file: the file to write to.  If this is not a terminal then
                 only the label is printed.
```

However, this is no longer the case with newer click versions. Take the following test script:
```python
#!/usr/bin/env python3
import click
from time import sleep

with click.progressbar(range(100), label="Foo") as pb:
    for _ in pb:
        sleep(0.01)

```

In click 5.0:

```
$ ./ayy.py 
Foo  [####################################]  100%          
$ echo "$(./ayy.py)"
Foo
Foo
```

In click 7.0:

```
$ ./ayy.py 
Foo  [####################################]  100%          
$ echo "$(./ayy.py)"

```


Discussion:

Resolving patch:
diff --git a/src/click/_termui_impl.py b/src/click/_termui_impl.py
--- a/src/click/_termui_impl.py
+++ b/src/click/_termui_impl.py
@@ -227,6 +227,12 @@ def render_progress(self):
         import shutil
 
         if self.is_hidden:
+            # Only output the label as it changes if the output is not a
+            # TTY. Use file=stderr if you expect to be piping stdout.
+            if self._last_line != self.label:
+                self._last_line = self.label
+                echo(self.label, file=self.file, color=self.color)
+
             return
 
         buf = []
diff --git a/src/click/termui.py b/src/click/termui.py
--- a/src/click/termui.py
+++ b/src/click/termui.py
@@ -381,8 +381,8 @@ def progressbar(
     :param info_sep: the separator between multiple info items (eta etc.)
     :param width: the width of the progress bar in characters, 0 means full
                   terminal width
-    :param file: the file to write to.  If this is not a terminal then
-                 only the label is printed.
+    :param file: The file to write to. If this is not a terminal then
+        only the label is printed.
     :param color: controls if the terminal supports ANSI colors or not.  The
                   default is autodetection.  This is only needed if ANSI
                   codes are included anywhere in the progress bar output
@@ -390,6 +390,10 @@ def progressbar(
     :param update_min_steps: Render only when this many updates have
         completed. This allows tuning for very fast iterators.
 
+    .. versionchanged:: 8.0
+        Labels are echoed if the output is not a TTY. Reverts a change
+        in 7.0 that removed all output.
+
     .. versionadded:: 8.0
        Added the ``update_min_steps`` parameter.
 


Test patch:
diff --git a/tests/test_termui.py b/tests/test_termui.py
--- a/tests/test_termui.py
+++ b/tests/test_termui.py
@@ -76,17 +76,16 @@ def cli():
 
 def test_progressbar_hidden(runner, monkeypatch):
     fake_clock = FakeClock()
-    label = "whatever"
 
     @click.command()
     def cli():
-        with _create_progress(label=label) as progress:
+        with _create_progress(label="working") as progress:
             for _ in progress:
                 fake_clock.advance_time()
 
     monkeypatch.setattr(time, "time", fake_clock.time)
     monkeypatch.setattr(click._termui_impl, "isatty", lambda _: False)
-    assert runner.invoke(cli, []).output == ""
+    assert runner.invoke(cli, []).output == "working\n"
 
 
 @pytest.mark.parametrize("avg, expected", [([], 0.0), ([1, 4], 2.5)])