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

Pager for output lists #1152

Merged
merged 5 commits into from
Nov 6, 2019
Merged

Pager for output lists #1152

merged 5 commits into from
Nov 6, 2019

Conversation

asvetlov
Copy link
Contributor

@asvetlov asvetlov commented Nov 5, 2019

The output can be potentially long, the pager is auto-applied in this case.

for line in handled:
click.echo(str(line))
else:
handled.extend(lines)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use itertools.chain()?

click.echo(str(line))
return
count = int(terminal_size[1] * 2 / 3)
handled = [i for i in itertools.islice(lines, count)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just list(itertools.islice(lines, count)).

) -> None:
if not tty:
for line in lines:
click.echo(str(line))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is str needed?

click.echo(str(line))
else:
handled.extend(lines)
click.echo_via_pager(str(line) + "\n" for line in handled)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the problem is that echo_via_pager() adds a newline at the end. So we will always get an empty line.

It can be solved by writing:

click.echo_via_pager(chain(["\n".join(handled)], (f"\n{line}" for line in lines)))

@asvetlov
Copy link
Contributor Author

asvetlov commented Nov 6, 2019

All comments are fixed.
@serhiy-storchaka thanks for the review!

@asvetlov asvetlov merged commit 77ff45c into master Nov 6, 2019
@asvetlov asvetlov deleted the pager branch November 6, 2019 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants