-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve echo_via_pager behaviour in face of errors and use of click.e…
…cho in the generator This commit fixes #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.
- Loading branch information
Showing
3 changed files
with
198 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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