diff --git a/core/src/error/report.rs b/core/src/error/report.rs index 28a9e7b093..501f032bc8 100644 --- a/core/src/error/report.rs +++ b/core/src/error/report.rs @@ -26,19 +26,11 @@ pub enum ErrorFormat { #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct ColorOpt(pub(crate) clap::ColorChoice); -impl From for ColorOpt { - fn from(color_choice: clap::ColorChoice) -> Self { - Self(color_choice) - } -} - -impl From for ColorChoice { - fn from(c: ColorOpt) -> Self { - use std::io::{stdout, IsTerminal}; - - match c.0 { +impl ColorOpt { + fn for_terminal(self, is_terminal: bool) -> ColorChoice { + match self.0 { clap::ColorChoice::Auto => { - if stdout().is_terminal() { + if is_terminal { ColorChoice::Auto } else { ColorChoice::Never @@ -50,6 +42,12 @@ impl From for ColorChoice { } } +impl From for ColorOpt { + fn from(color_choice: clap::ColorChoice) -> Self { + Self(color_choice) + } +} + impl Default for ColorOpt { fn default() -> Self { Self(clap::ColorChoice::Auto) @@ -68,9 +66,11 @@ pub fn report>( format: ErrorFormat, color_opt: ColorOpt, ) { + use std::io::{stderr, IsTerminal}; + let stdlib_ids = cache.get_all_stdlib_modules_file_id(); report_with( - &mut StandardStream::stderr(color_opt.into()).lock(), + &mut StandardStream::stderr(color_opt.for_terminal(stderr().is_terminal())).lock(), cache.files_mut(), stdlib_ids.as_ref(), error,