cli: remove redundant maybe_tty flag

It should be valid to test isatty(stdout) even if the output stream is paged.
This commit is contained in:
Yuya Nishihara 2022-10-20 09:33:51 +09:00
parent 0633856ab2
commit 87bcdd4e51

View file

@ -65,11 +65,11 @@ fn color_setting(settings: &UserSettings) -> ColorChoice {
.unwrap_or_default() .unwrap_or_default()
} }
fn use_color(choice: ColorChoice, maybe_tty: bool) -> bool { fn use_color(choice: ColorChoice) -> bool {
match choice { match choice {
ColorChoice::Always => true, ColorChoice::Always => true,
ColorChoice::Never => false, 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 { 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); let formatter_factory = FormatterFactory::prepare(&settings, color);
Ui { Ui {
cwd, cwd,
@ -95,8 +95,7 @@ impl Ui {
/// Reconfigures the underlying outputs with the new color choice. /// Reconfigures the underlying outputs with the new color choice.
pub fn reset_color(&mut self, choice: ColorChoice) { pub fn reset_color(&mut self, choice: ColorChoice) {
let maybe_tty = matches!(&self.output_pair, UiOutputPair::Terminal { .. }); let color = use_color(choice);
let color = use_color(choice, maybe_tty);
if self.formatter_factory.is_color() != color { if self.formatter_factory.is_color() != color {
self.formatter_factory = FormatterFactory::prepare(&self.settings, color); self.formatter_factory = FormatterFactory::prepare(&self.settings, color);
} }