You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
progressbar label should not be shown when the output is not a tty #406
See #401 for details.
The behaviour is not as advertised.
import click
@click.command()
def mycli():
with click.progressbar(range(10), label='xyz') as pb:
for _ in pb:
pass
if __name__ == '__main__':
mycli()
will print the label twice:
python tst.py > that
cat that
xyz
xyz
The docstring states: "By default, this progress bar will not be rendered if the file is not a terminal."
However, the label is always displayed even when the output is not a tty.
You make this seem like a bug when it's not. This is intended behavior -- the label contains information about the work that is currently done by the launched program. Since you can't output anything else while the progressbar is running (without creating glitches), this is the only option to show any information at all, besides the progressbar itself. Your fix would make any well-behaved Click app effectively silent in non-TTY mode.
But you can effectively issue a click.echo before displaying entering in a progressbar block and issue a click.echo after that block without problems. This is a more flexible way that printing a surprising fixed label twice.
But you can effectively issue a click.echo before displaying entering in a progressbar block and issue a click.echo after that block without problems.
Not if you want to change the label during the progressbar (on a related note, perhaps we should also print the item info in non-TTY mode). Also it looks ugly in TTY mode.
That the same label is printed more than once is stupid behavior.
ah... I had no idea you could change the label while the progressbar is iterated. This is an object after all. Though when you do that, the label you update is only shown in tty mode.
The original label overwrites this (with a dual output) in non-tty mode.
So, I really think that a progressbar should not display as stated anything when the output is not a tty.
Displaying something like a start string and an end string ugliness is really a matter of taste.
And if you really want something to be shown in a non-tty output it is IMHO best to let you control that rather that let the progressbar drive it.
ah... I had no idea you could change the label while the progressbar is iterated. This is an object after all. Though when you do that, the label you update is only shown in tty mode.
The new label will get used once the iterator advances. I'm not sure if that's intended usage, but I suspect a few people already rely on this.
Activity
untitaker commentedon Aug 11, 2015
Not if you want to change the label during the progressbar (on a related note, perhaps we should also print the item info in non-TTY mode). Also it looks ugly in TTY mode.
That the same label is printed more than once is stupid behavior.
pombredanne commentedon Aug 11, 2015
ah... I had no idea you could change the label while the progressbar is iterated. This is an object after all. Though when you do that, the label you update is only shown in tty mode.
The original label overwrites this (with a dual output) in non-tty mode.
So, I really think that a progressbar should not display as stated anything when the output is not a tty.
Displaying something like a start string and an end string ugliness is really a matter of taste.
And if you really want something to be shown in a non-tty output it is IMHO best to let you control that rather that let the progressbar drive it.
FWIW, having a start and end statement is something I do here https://github.com/nexB/scancode-toolkit/blob/develop/src/scancode/utils.py#L63
untitaker commentedon Aug 11, 2015
The new label will get used once the iterator advances. I'm not sure if that's intended usage, but I suspect a few people already rely on this.
pombredanne commentedon May 24, 2017
I found out that this is fixed in head.... so I am closing
will print the label only once as excepted: