1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-02 19:32:25 +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

@@ -1,7 +1,7 @@
use console::AnsiCodeIterator;
/// Expand tabs like an ANSI-enabled expand(1).
pub fn expand(line: &str, width: usize, mut cursor: usize) -> String {
pub fn expand(line: &str, width: usize, cursor: &mut usize) -> String {
let mut buffer = String::with_capacity(line.len() * 2);
for chunk in AnsiCodeIterator::new(line) {
@@ -11,20 +11,20 @@ pub fn expand(line: &str, width: usize, mut cursor: usize) -> String {
while let Some(index) = text.find('\t') {
// Add previous text.
if index > 0 {
cursor += index;
*cursor += index;
buffer.push_str(&text[0..index]);
}
// Add tab.
let spaces = width - (cursor % width);
cursor += spaces;
let spaces = width - (*cursor % width);
*cursor += spaces;
buffer.push_str(&*" ".repeat(spaces));
// Next.
text = &text[index + 1..text.len()];
}
cursor += text.len();
*cursor += text.len();
buffer.push_str(text);
}
}