mirror of
https://github.com/sharkdp/bat.git
synced 2025-02-22 12:58:26 +00:00
Correctly render tab stops
This commit is contained in:
parent
cde239e809
commit
da5921b4a9
@ -53,26 +53,32 @@ pub fn replace_nonprintable(input: &[u8], tab_width: usize) -> String {
|
|||||||
let tab_width = if tab_width == 0 { 4 } else { tab_width };
|
let tab_width = if tab_width == 0 { 4 } else { tab_width };
|
||||||
|
|
||||||
let mut idx = 0;
|
let mut idx = 0;
|
||||||
|
let mut line_idx = 0;
|
||||||
let len = input.len();
|
let len = input.len();
|
||||||
while idx < len {
|
while idx < len {
|
||||||
if let Some((chr, skip_ahead)) = try_parse_utf8_char(&input[idx..]) {
|
if let Some((chr, skip_ahead)) = try_parse_utf8_char(&input[idx..]) {
|
||||||
idx += skip_ahead;
|
idx += skip_ahead;
|
||||||
|
line_idx += 1;
|
||||||
|
|
||||||
match chr {
|
match chr {
|
||||||
// space
|
// space
|
||||||
' ' => output.push('·'),
|
' ' => output.push('·'),
|
||||||
// tab
|
// tab
|
||||||
'\t' => {
|
'\t' => {
|
||||||
if tab_width == 1 {
|
let tab_stop = tab_width - ((line_idx - 1) % tab_width);
|
||||||
|
if tab_stop == 1 {
|
||||||
output.push('↹');
|
output.push('↹');
|
||||||
} else {
|
} else {
|
||||||
output.push('├');
|
output.push('├');
|
||||||
output.push_str(&"─".repeat(tab_width - 2));
|
output.push_str(&"─".repeat(tab_stop - 2));
|
||||||
output.push('┤');
|
output.push('┤');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// line feed
|
// line feed
|
||||||
'\x0A' => output.push_str("␊\x0A"),
|
'\x0A' => {
|
||||||
|
output.push_str("␊\x0A");
|
||||||
|
line_idx = 0;
|
||||||
|
}
|
||||||
// carriage return
|
// carriage return
|
||||||
'\x0D' => output.push('␍'),
|
'\x0D' => output.push('␍'),
|
||||||
// null
|
// null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user