1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-12 08:12:27 +01:00

Fixed tab expansion not working in --wrap=never mode.

This commit is contained in:
eth-p
2018-09-11 13:45:49 -07:00
parent b4096e5627
commit d90797f8e9
2 changed files with 17 additions and 22 deletions

View File

@@ -150,7 +150,7 @@ impl<'a> InteractivePrinter<'a> {
Ok(())
}
fn preprocess(&self, text: &str, cursor: usize) -> String {
fn preprocess(&self, text: &str, cursor: &mut usize) -> String {
if self.config.tab_width > 0 {
expand(text, self.config.tab_width, cursor)
} else {
@@ -243,19 +243,15 @@ impl<'a> Printer for InteractivePrinter<'a> {
let true_color = self.config.true_color;
let colored_output = self.config.colored_output;
write!(
handle,
"{}",
regions
.iter()
.map(|&(style, text)| as_terminal_escaped(
style,
&*self.preprocess(text, 0),
true_color,
colored_output,
)).collect::<Vec<_>>()
.join("")
)?;
for &(style, region) in regions.iter() {
let text = &*self.preprocess(region, &mut cursor_total);
write!(handle, "{}", as_terminal_escaped(
style,
&*text,
true_color,
colored_output,
))?;
}
} else {
for &(style, region) in regions.iter() {
let mut ansi_iterator = AnsiCodeIterator::new(region);
@@ -280,8 +276,9 @@ impl<'a> Printer for InteractivePrinter<'a> {
(text, false) => {
let text = self.preprocess(
text.trim_right_matches(|c| c == '\r' || c == '\n'),
cursor_total,
&mut cursor_total,
);
let mut chars = text.chars();
let mut remaining = text.chars().count();
@@ -292,7 +289,6 @@ impl<'a> Printer for InteractivePrinter<'a> {
if remaining <= available {
let text = chars.by_ref().take(remaining).collect::<String>();
cursor += remaining;
cursor_total += remaining;
write!(
handle,
@@ -330,7 +326,6 @@ impl<'a> Printer for InteractivePrinter<'a> {
// It wraps.
let text = chars.by_ref().take(available).collect::<String>();
cursor = 0;
cursor_total += available;
remaining -= available;
write!(