From 0c24307555485b4cd36663263283d45280075e24 Mon Sep 17 00:00:00 2001 From: Xerxes-2 Date: Sat, 3 Aug 2024 16:53:59 +1000 Subject: [PATCH] use "^[" to represent esc --- yazi-plugin/src/external/highlighter.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/yazi-plugin/src/external/highlighter.rs b/yazi-plugin/src/external/highlighter.rs index b63151a8..4b99777d 100644 --- a/yazi-plugin/src/external/highlighter.rs +++ b/yazi-plugin/src/external/highlighter.rs @@ -84,7 +84,19 @@ impl Highlighter { buf.push(b'\n'); } - buf.iter_mut().filter(|&&mut b| b == b'\x1b').for_each(|b| *b = b'^'); + let esc_count = buf.iter().filter(|&&b| b == 27).count(); + if esc_count > 0 { + plain = true; + drop(mem::take(&mut before)); + buf = buf.iter().fold(Vec::with_capacity(buf.len() + esc_count), |mut acc, &b| { + if b == 27 { + acc.extend_from_slice(b"^["); + } else { + acc.push(b); + } + acc + }) + } if i > skip { after.push(String::from_utf8_lossy(&buf).into_owned());