pull/132/head
eth-p 6 years ago committed by David Peter
parent 247dfbee83
commit 486e6a19cd

@ -1,4 +1,6 @@
use Colors;
use app::Config;
use console::AnsiCodeIterator;
use decorations::{Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration};
use diff::LineChanges;
use errors::*;
@ -8,7 +10,6 @@ use std::vec::Vec;
use style::OutputWrap;
use syntect::highlighting;
use terminal::as_terminal_escaped;
use Colors;
pub struct Printer<'a> {
handle: &'a mut Write,
@ -118,8 +119,7 @@ impl<'a> Printer<'a> {
// Line decorations.
if self.panel_width > 0 {
let decorations = self
.decorations
let decorations = self.decorations
.iter()
.map(|ref d| d.generate(self.line_number, false, self))
.collect::<Vec<_>>();
@ -150,7 +150,18 @@ impl<'a> Printer<'a> {
.join("")
)?;
} 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 mut chars = text.chars();
let mut remaining = text.chars().count();
@ -168,7 +179,7 @@ impl<'a> Printer<'a> {
"{}",
as_terminal_escaped(
style,
&*text,
&*format!("{}{}", ansi_prefix, text),
self.config.true_color,
self.config.colored_output,
)
@ -183,7 +194,8 @@ impl<'a> Printer<'a> {
"{} ",
self.decorations
.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>>()
.join(" ")
))
@ -202,7 +214,7 @@ impl<'a> Printer<'a> {
"{}\n{}",
as_terminal_escaped(
style,
&*text,
&*format!("{}{}", ansi_prefix, text),
self.config.true_color,
self.config.colored_output,
),
@ -210,6 +222,9 @@ impl<'a> Printer<'a> {
)?;
}
}
}
}
}
write!(self.handle, "\n")?;
}

Loading…
Cancel
Save