This commit is contained in:
eth-p 2018-05-16 14:19:36 -07:00 committed by David Peter
parent 247dfbee83
commit 486e6a19cd

View File

@ -1,4 +1,6 @@
use Colors;
use app::Config; use app::Config;
use console::AnsiCodeIterator;
use decorations::{Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration}; use decorations::{Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration};
use diff::LineChanges; use diff::LineChanges;
use errors::*; use errors::*;
@ -8,7 +10,6 @@ use std::vec::Vec;
use style::OutputWrap; use style::OutputWrap;
use syntect::highlighting; use syntect::highlighting;
use terminal::as_terminal_escaped; use terminal::as_terminal_escaped;
use Colors;
pub struct Printer<'a> { pub struct Printer<'a> {
handle: &'a mut Write, handle: &'a mut Write,
@ -118,8 +119,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<_>>();
@ -150,7 +150,18 @@ impl<'a> Printer<'a> {
.join("") .join("")
)?; )?;
} else { } else {
for &(style, text) in regions.iter() { for &(style, region) in regions.iter() {
let mut ansi_iterator = AnsiCodeIterator::new(region);
let mut ansi_prefix = "";
while let Some(chunk) = ansi_iterator.next() {
match chunk {
// ANSI escape passthrough.
(text, true) => {
ansi_prefix = text;
}
// Regular text.
(text, false) => {
let text = text.trim_right_matches(|c| c == '\r' || c == '\n'); let text = text.trim_right_matches(|c| c == '\r' || c == '\n');
let mut chars = text.chars(); let mut chars = text.chars();
let mut remaining = text.chars().count(); let mut remaining = text.chars().count();
@ -168,7 +179,7 @@ impl<'a> Printer<'a> {
"{}", "{}",
as_terminal_escaped( as_terminal_escaped(
style, style,
&*text, &*format!("{}{}", ansi_prefix, text),
self.config.true_color, self.config.true_color,
self.config.colored_output, self.config.colored_output,
) )
@ -183,7 +194,8 @@ impl<'a> Printer<'a> {
"{} ", "{} ",
self.decorations self.decorations
.iter() .iter()
.map(|ref d| d.generate(self.line_number, true, self).text) .map(|ref d| d.generate(self.line_number, true, self)
.text)
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join(" ") .join(" ")
)) ))
@ -202,7 +214,7 @@ impl<'a> Printer<'a> {
"{}\n{}", "{}\n{}",
as_terminal_escaped( as_terminal_escaped(
style, style,
&*text, &*format!("{}{}", ansi_prefix, text),
self.config.true_color, self.config.true_color,
self.config.colored_output, self.config.colored_output,
), ),
@ -210,6 +222,9 @@ impl<'a> Printer<'a> {
)?; )?;
} }
} }
}
}
}
write!(self.handle, "\n")?; write!(self.handle, "\n")?;
} }