-
Notifications
You must be signed in to change notification settings - Fork 7
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
Pager for output lists #1152
Conversation
neuromation/cli/utils.py
Outdated
for line in handled: | ||
click.echo(str(line)) | ||
else: | ||
handled.extend(lines) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use itertools.chain()
?
neuromation/cli/utils.py
Outdated
click.echo(str(line)) | ||
return | ||
count = int(terminal_size[1] * 2 / 3) | ||
handled = [i for i in itertools.islice(lines, count)] |
There was a problem hiding this comment.
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))
.
neuromation/cli/utils.py
Outdated
) -> None: | ||
if not tty: | ||
for line in lines: | ||
click.echo(str(line)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is str needed?
neuromation/cli/utils.py
Outdated
click.echo(str(line)) | ||
else: | ||
handled.extend(lines) | ||
click.echo_via_pager(str(line) + "\n" for line in handled) |
There was a problem hiding this comment.
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)))
All comments are fixed. |
The output can be potentially long, the pager is auto-applied in this case.