From 87bcdd4e51dd625933d07317f95ec8eb34b322de Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 20 Oct 2022 09:33:51 +0900 Subject: [PATCH] cli: remove redundant maybe_tty flag It should be valid to test isatty(stdout) even if the output stream is paged. --- src/ui.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index 3a941ec1c..33e87735d 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -65,11 +65,11 @@ fn color_setting(settings: &UserSettings) -> ColorChoice { .unwrap_or_default() } -fn use_color(choice: ColorChoice, maybe_tty: bool) -> bool { +fn use_color(choice: ColorChoice) -> bool { match choice { ColorChoice::Always => true, ColorChoice::Never => false, - ColorChoice::Auto => maybe_tty && atty::is(Stream::Stdout), + ColorChoice::Auto => atty::is(Stream::Stdout), } } @@ -80,7 +80,7 @@ impl Ui { } pub fn with_cwd(cwd: PathBuf, settings: UserSettings) -> Ui { - let color = use_color(color_setting(&settings), true); + let color = use_color(color_setting(&settings)); let formatter_factory = FormatterFactory::prepare(&settings, color); Ui { cwd, @@ -95,8 +95,7 @@ impl Ui { /// Reconfigures the underlying outputs with the new color choice. pub fn reset_color(&mut self, choice: ColorChoice) { - let maybe_tty = matches!(&self.output_pair, UiOutputPair::Terminal { .. }); - let color = use_color(choice, maybe_tty); + let color = use_color(choice); if self.formatter_factory.is_color() != color { self.formatter_factory = FormatterFactory::prepare(&self.settings, color); }