diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2019-03-25 11:16:58 +0100 |
|---|---|---|
| committer | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2019-04-02 16:14:59 +0200 |
| commit | 39b21376dbe9489b7f4d39f3bf742a44d5f3770d (patch) | |
| tree | 01777e3e1ec6df2815920f4fb6e87c4c91ee9f97 /src/librustc_errors/emitter.rs | |
| parent | 0a842e8c7a18ac609c3c7c60563e8e6bc7d917c6 (diff) | |
| download | rust-39b21376dbe9489b7f4d39f3bf742a44d5f3770d.tar.gz rust-39b21376dbe9489b7f4d39f3bf742a44d5f3770d.zip | |
Rename `colorful-json` to `json-rendered` and make it a selection instead of a bool
Diffstat (limited to 'src/librustc_errors/emitter.rs')
| -rw-r--r-- | src/librustc_errors/emitter.rs | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 0790f9bc761..5ba17d12d93 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -19,6 +19,32 @@ use std::cmp::{min, Reverse}; use termcolor::{StandardStream, ColorChoice, ColorSpec, BufferWriter, Ansi}; use termcolor::{WriteColor, Color, Buffer}; +/// Describes the way the content of the `rendered` field of the json output is generated +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum HumanReadableErrorType { + Default(ColorConfig), + Short(ColorConfig), +} + +impl HumanReadableErrorType { + /// Returns a (`short`, `color`) tuple + pub fn unzip(self) -> (bool, ColorConfig) { + match self { + HumanReadableErrorType::Default(cc) => (false, cc), + HumanReadableErrorType::Short(cc) => (true, cc), + } + } + pub fn new_emitter( + self, + dst: Box<dyn Write + Send>, + source_map: Option<Lrc<SourceMapperDyn>>, + teach: bool, + ) -> EmitterWriter { + let (short, color_config) = self.unzip(); + EmitterWriter::new(dst, source_map, short, teach, color_config.suggests_using_colors()) + } +} + const ANONYMIZED_LINE_NUM: &str = "LL"; /// Emitter trait for emitting errors. @@ -104,8 +130,8 @@ pub enum ColorConfig { } impl ColorConfig { - fn to_color_choice(&self) -> ColorChoice { - match *self { + fn to_color_choice(self) -> ColorChoice { + match self { ColorConfig::Always => { if atty::is(atty::Stream::Stderr) { ColorChoice::Always @@ -120,6 +146,14 @@ impl ColorConfig { ColorConfig::Auto => ColorChoice::Never, } } + pub fn suggests_using_colors(self) -> bool { + match self { + | ColorConfig::Always + | ColorConfig::Auto + => true, + ColorConfig::Never => false, + } + } } pub struct EmitterWriter { @@ -1540,6 +1574,7 @@ fn emit_to_destination(rendered_buffer: &[Vec<StyledString>], pub enum Destination { Terminal(StandardStream), Buffered(BufferWriter), + // The bool denotes whether we should be emitting ansi color codes or not Raw(Box<(dyn Write + Send)>, bool), } |
