Inline and remove HumanReadableErrorType::new_emitter.

And likewise with `ColorConfig::suggests_using_colors`. They both have a
single call site. And note that `BufWriter::supports_color()` always
returns false, which enables a small bit of constant folding along the
way.
This commit is contained in:
Nicholas Nethercote 2024-02-29 14:47:09 +11:00
parent d3727413ed
commit 437325bdd4
3 changed files with 16 additions and 23 deletions

View file

@ -35,7 +35,7 @@ use std::io::prelude::*;
use std::io::{self, IsTerminal};
use std::iter;
use std::path::Path;
use termcolor::{Ansi, Buffer, BufferWriter, ColorChoice, ColorSpec, StandardStream};
use termcolor::{Buffer, BufferWriter, ColorChoice, ColorSpec, StandardStream};
use termcolor::{Color, WriteColor};
/// Default column width, used in tests and when terminal dimensions cannot be determined.
@ -58,18 +58,6 @@ impl HumanReadableErrorType {
HumanReadableErrorType::AnnotateSnippet(cc) => (false, cc),
}
}
pub fn new_emitter(
self,
mut dst: Destination,
fallback_bundle: LazyFallbackBundle,
) -> HumanEmitter {
let (short, color_config) = self.unzip();
let color = color_config.suggests_using_colors();
if !dst.supports_color() && color {
dst = Box::new(Ansi::new(dst));
}
HumanEmitter::new(dst, fallback_bundle).short_message(short)
}
}
#[derive(Clone, Copy, Debug)]
@ -628,12 +616,6 @@ impl ColorConfig {
ColorConfig::Auto => ColorChoice::Never,
}
}
fn suggests_using_colors(self) -> bool {
match self {
ColorConfig::Always | ColorConfig::Auto => true,
ColorConfig::Never => false,
}
}
}
/// Handles the writing of `HumanReadableErrorType::Default` and `HumanReadableErrorType::Short`