mirror of
https://github.com/sharkdp/bat
synced 2024-11-15 16:38:06 +00:00
Improved logic when encountering ANSI in character wrap mode
Fixes #551
This commit is contained in:
parent
7ef0fe091d
commit
0ad09df7ab
1 changed files with 12 additions and 2 deletions
|
@ -367,15 +367,25 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
|||
match chunk {
|
||||
// ANSI escape passthrough.
|
||||
(text, true) => {
|
||||
if text.chars().last().map_or(false, |c| c == 'm') {
|
||||
let is_ansi_csi = text.chars().skip(1).nth(0).map_or(false, |c|c == '[');
|
||||
|
||||
if is_ansi_csi && text.chars().last().map_or(false, |c| c == 'm') {
|
||||
// It's an ANSI SGR sequence.
|
||||
// We should be mostly safe to just append these together.
|
||||
ansi_prefix.push_str(text);
|
||||
if text == "\x1B[0m" {
|
||||
self.ansi_prefix_sgr = "\x1B[0m".to_owned();
|
||||
} else {
|
||||
self.ansi_prefix_sgr.push_str(text);
|
||||
}
|
||||
} else {
|
||||
} else if is_ansi_csi {
|
||||
// It's a regular CSI sequence.
|
||||
// We should be mostly safe to just append these together.
|
||||
ansi_prefix.push_str(text);
|
||||
} else {
|
||||
// It's probably a VT100 code.
|
||||
// Passing it through is the safest bet.
|
||||
write!(handle, "{}", text)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue