-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I think the control flow in this function is complicated and confusing, largely due to the use of two booleans `print_formatted` and `fallback_to_println` that are set in multiple places and then used to guide proceedings. As well as hurting readability, this leads to at least one bug: if the `write_termcolor_buf` call fails and the pager also fails, the function will try to print color output to stdout, but that output will be empty because `write_termcolor_buf` failed. I.e. the `if fallback_to_println` body fails to check `print_formatted`. This commit rewrites the function to be neater and more Rust-y, e.g. by putting the result of `write_termcolor_buf` into an `Option` so it can only be used on success, and by using `?` more. It also changes terminology a little, using "pretty" to mean "formatted and colorized". The result is a little shorter, more readable, and less buggy.
- Loading branch information
1 parent
7fd7846
commit 2c9b31c
Showing
1 changed file
with
43 additions
and
49 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