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

progressbar label should not be shown when the output is not a tty #401

Closed
wants to merge 1 commit into from
Closed

progressbar label should not be shown when the output is not a tty #401

wants to merge 1 commit into from

Conversation

pombredanne
Copy link
Contributor

If you pass a label to a progressbar, the label is incorrectly included when you redirect the command output to a file.

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.

The render_finish function does this correctly:
https://github.com/mitsuhiko/click/blob/36f83d91e27b5b88ee806cb40f284658e2f9cdb5/click/_termui_impl.py#L106

In contrast render_progress always prints a label even if self.is_hidden, and should just return instead without any echo:
https://github.com/mitsuhiko/click/blob/36f83d91e27b5b88ee806cb40f284658e2f9cdb5/click/_termui_impl.py#L183

This simple command shows the issue:

import click

@click.command()
def mycli():
    with click.progressbar(range(2), label='xyz') as pb:
        for _ in pb:
           pass

if __name__ == '__main__':
    mycli()

This is correct:

$ python click_checker.py
xyz  [------------------------------------]    0%

This is not:

$ python click_checker.py > tst
$ cat tst
xyz

I would expect the redirected stdout to be empty in this case.

This commit fixes this.

@untitaker
Copy link
Contributor

Sorry for responding so late.

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.

The bar is not displayed, the label is. This is intended behavior I think.

@untitaker untitaker closed this Aug 11, 2015
@pombredanne
Copy link
Contributor Author

@untitaker I kindly disagree. The label is displayed as part of the bar and is as much part of the bar as the pos, the item show function or anything else.

This does pollute a non-tty redirection for no good reason I can fathom. Furthermore, it prints it to a non-tty more than one time.

@pombredanne
Copy link
Contributor Author

and @untitaker it would be nice not to close the PR abruptly without a discussion first

@untitaker
Copy link
Contributor

@pombredanne 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.

@untitaker
Copy link
Contributor

If you want to discuss the current behavior, please do open an issue for it.

@pombredanne
Copy link
Contributor Author

@untitaker fair enough I created #406 as an issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants