pull/187/merge
eth-p 6 years ago committed by David Peter
parent 8b92aae23f
commit 34811b8161

@ -64,6 +64,7 @@ pub fn print_files(assets: &HighlightingAssets, config: &Config) -> Result<bool>
let mut no_errors: bool = true; let mut no_errors: bool = true;
for file in &config.files { for file in &config.files {
printer.ansi_prefix_sgr.clear();
printer.line_changes = file.and_then(|filename| get_git_diff(filename)); printer.line_changes = file.and_then(|filename| get_git_diff(filename));
let syntax = assets.get_syntax(config.language, *file); let syntax = assets.get_syntax(config.language, *file);

@ -18,6 +18,7 @@ pub struct Printer<'a> {
pub config: &'a Config<'a>, pub config: &'a Config<'a>,
decorations: Vec<Box<Decoration>>, decorations: Vec<Box<Decoration>>,
panel_width: usize, panel_width: usize,
pub ansi_prefix_sgr: String,
pub line_number: usize, pub line_number: usize,
pub line_changes: Option<LineChanges>, pub line_changes: Option<LineChanges>,
} }
@ -67,6 +68,7 @@ impl<'a> Printer<'a> {
colors, colors,
config, config,
decorations, decorations,
ansi_prefix_sgr: String::new(),
line_number: 0, line_number: 0,
line_changes: None, line_changes: None,
} }
@ -124,8 +126,7 @@ impl<'a> Printer<'a> {
// Line decorations. // Line decorations.
if self.panel_width > 0 { if self.panel_width > 0 {
let decorations = self let decorations = self.decorations
.decorations
.iter() .iter()
.map(|ref d| d.generate(self.line_number, false, self)) .map(|ref d| d.generate(self.line_number, false, self))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -158,12 +159,17 @@ impl<'a> Printer<'a> {
} else { } else {
for &(style, region) in regions.iter() { for &(style, region) in regions.iter() {
let mut ansi_iterator = AnsiCodeIterator::new(region); let mut ansi_iterator = AnsiCodeIterator::new(region);
let mut ansi_prefix = ""; let mut ansi_prefix: String = String::new();
for chunk in ansi_iterator { for chunk in ansi_iterator {
match chunk { match chunk {
// ANSI escape passthrough. // ANSI escape passthrough.
(text, true) => { (text, true) => {
ansi_prefix = text; if text.chars().last().unwrap() == 'm' {
self.ansi_prefix_sgr.push_str(text);
ansi_prefix.push_str(text);
} else {
ansi_prefix.push_str(text);
}
} }
// Regular text. // Regular text.
@ -185,7 +191,10 @@ impl<'a> Printer<'a> {
"{}", "{}",
as_terminal_escaped( as_terminal_escaped(
style, style,
&*format!("{}{}", ansi_prefix, text), &*format!(
"{}{}{}",
self.ansi_prefix_sgr, ansi_prefix, text
),
self.config.true_color, self.config.true_color,
self.config.colored_output, self.config.colored_output,
) )
@ -200,9 +209,11 @@ impl<'a> Printer<'a> {
"{} ", "{} ",
self.decorations self.decorations
.iter() .iter()
.map(|ref d| d .map(|ref d| d.generate(
.generate(self.line_number, true, self) self.line_number,
.text) true,
self
).text)
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join(" ") .join(" ")
)) ))
@ -221,13 +232,19 @@ impl<'a> Printer<'a> {
"{}\n{}", "{}\n{}",
as_terminal_escaped( as_terminal_escaped(
style, style,
&*format!("{}{}", ansi_prefix, text), &*format!(
"{}{}{}",
self.ansi_prefix_sgr, ansi_prefix, text
),
self.config.true_color, self.config.true_color,
self.config.colored_output, self.config.colored_output,
), ),
panel_wrap.clone().unwrap() panel_wrap.clone().unwrap()
)?; )?;
} }
// Clear the ANSI prefix buffer.
ansi_prefix.clear();
} }
} }
} }

Loading…
Cancel
Save