Improve echo_via_pager behaviour in face of errors#2775
Merged
Conversation
b715ba2 to
ce88a00
Compare
Contributor
Author
|
I've had a look at #350 and the new behaviour sounds like what @amjith describes in the comment #350 (comment) The fix by @untitaker is still in place (https://github.com/pallets/click/commits/e71f0a040a81e03276b25ab1d1b0671822ab331b) – now in the finally block, which should be even better. For me this works really well in all the situations I was able to come up with so far. |
stefreak
commented
Sep 7, 2024
stefreak
commented
Sep 7, 2024
0xDEC0DE
reviewed
Sep 9, 2024
Contributor
0xDEC0DE
left a comment
There was a problem hiding this comment.
I don't have rights to approve, but this looks like it will do the trick.
…cho in the generator This commit fixes pallets#2674 (echo_via_pager with generators leaves terminal in broken state). When running the program to reproduce the issue (thanks to @0xDEC0DE for providing it in the issue mentioned above!) ``` import click def output_generator(): counter = 0 while True: yield "this is a line of output\n" if counter == 1024: click.echo("kaboom", err=True) click.get_current_context().exit(0) counter += 1 @click.command def kaboom(): click.echo_via_pager(output_generator) if __name__ == "__main__": kaboom() ``` The "kaboom" message will now be visible immediately (the error will cause click to terminate the pager). ZSH and bash will not be in a broken state (tested using bash and zsh on macos). Further changes: - Error handling: terminate the pager and close the file descriptors in a finally block - KeyboardInterrupt: the pager code will not ignore KeyboardInterrupt anymore. This allows the user to search for future output of the generator when using less and then aborting the program using ctrl-c. - tests: improved the echo_via_pager tests by using a named tuple and separate assertions for pager output, stderr and stdout. Added additional test cases.
8be3685 to
0bdd673
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #2674 (echo_via_pager with generators leaves terminal in broken state).
should fail without the change.
.. versionchanged::entries in any relevant code docs.