Skip to content

Commit 462c656

Browse files
committed
Make x-mas tree output configurable
When setting "tame" color output, do not highlight the spanned code and do not highlight notes.
1 parent db5023e commit 462c656

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

src/librustc_errors/emitter.rs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,27 @@ impl FromStr for ErrorFormat {
136136
pub enum ColorConfig {
137137
Auto,
138138
Always,
139+
Tame,
139140
Never,
140141
}
141142

142143
impl ColorConfig {
143144
fn use_color(&self) -> bool {
144145
match *self {
145-
ColorConfig::Always => true,
146+
ColorConfig::Always |
147+
ColorConfig::Tame => true,
146148
ColorConfig::Never => false,
147149
ColorConfig::Auto => stderr_isatty(),
148150
}
149151
}
152+
fn extra_colorful(&self) -> bool {
153+
match *self {
154+
ColorConfig::Always |
155+
ColorConfig::Auto => stderr_isatty(),
156+
ColorConfig::Tame |
157+
ColorConfig::Never => false,
158+
}
159+
}
150160
}
151161

152162
impl FromEnv for ColorConfig {
@@ -164,6 +174,7 @@ impl FromStr for ColorConfig {
164174
match s {
165175
"" | "auto" => Ok(ColorConfig::Auto),
166176
"1" | "always" => Ok(ColorConfig::Always),
177+
"tame" => Ok(ColorConfig::Tame),
167178
"never" => Ok(ColorConfig::Never),
168179
_ => Err(s.into()),
169180
}
@@ -174,6 +185,7 @@ pub struct EmitterWriter {
174185
dst: Destination,
175186
cm: Option<Rc<CodeMapper>>,
176187
short_message: bool,
188+
extra_colorful: bool,
177189
}
178190

179191
struct FileWithAnnotatedLines {
@@ -193,12 +205,14 @@ impl EmitterWriter {
193205
dst,
194206
cm: code_map,
195207
short_message: short_message,
208+
extra_colorful: color_config.extra_colorful(),
196209
}
197210
} else {
198211
EmitterWriter {
199212
dst: Raw(Box::new(io::stderr())),
200213
cm: code_map,
201214
short_message: short_message,
215+
extra_colorful: false,
202216
}
203217
}
204218
}
@@ -211,6 +225,7 @@ impl EmitterWriter {
211225
dst: Raw(dst),
212226
cm: code_map,
213227
short_message: short_message,
228+
extra_colorful: false,
214229
}
215230
}
216231

@@ -620,11 +635,13 @@ impl EmitterWriter {
620635
style);
621636
}
622637
_ => {
623-
buffer.set_style_range(line_offset,
624-
code_offset + annotation.start_col,
625-
code_offset + annotation.end_col,
626-
style,
627-
annotation.is_primary);
638+
if self.extra_colorful {
639+
buffer.set_style_range(line_offset,
640+
code_offset + annotation.start_col,
641+
code_offset + annotation.end_col,
642+
style,
643+
annotation.is_primary);
644+
}
628645
}
629646
}
630647
}
@@ -979,10 +996,18 @@ impl EmitterWriter {
979996
line_number += 1;
980997
buffer.append(line_number, &padding, Style::NoStyle);
981998
}
982-
buffer.append(line_number, line, style_or_override(*style, override_style));
999+
buffer.append(line_number, line, if self.extra_colorful {
1000+
style_or_override(*style, override_style)
1001+
} else {
1002+
Style::NoStyle
1003+
});
9831004
}
9841005
} else {
985-
buffer.append(line_number, text, style_or_override(*style, override_style));
1006+
buffer.append(line_number, text, if self.extra_colorful {
1007+
style_or_override(*style, override_style)
1008+
} else {
1009+
Style::NoStyle
1010+
});
9861011
}
9871012
}
9881013
}

0 commit comments

Comments
 (0)