mirror of
https://github.com/sharkdp/bat
synced 2024-11-16 21:25:56 +00:00
Fixed #124
This commit is contained in:
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…
Reference in New Issue
Block a user