From 9822fccc3ba0efebaea2eb365f7749725f6ae253 Mon Sep 17 00:00:00 2001 From: Xerxes-2 Date: Fri, 2 Aug 2024 15:30:20 +1000 Subject: [PATCH] fix: preview ascii escape image in yazi#1391 --- yazi-plugin/src/external/highlighter.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/yazi-plugin/src/external/highlighter.rs b/yazi-plugin/src/external/highlighter.rs index 0e681b96..8044fab3 100644 --- a/yazi-plugin/src/external/highlighter.rs +++ b/yazi-plugin/src/external/highlighter.rs @@ -97,8 +97,14 @@ impl Highlighter { } if plain { - let indent = " ".repeat(PREVIEW.tab_size as usize); - Ok(Text::from(after.join("").replace('\t', &indent))) + if after.iter().any(|l| l.contains('\x1b')) { + let bytes = after.join("").bytes().collect::>(); + use ansi_to_tui::IntoText; + bytes.into_text().map_err(|e| PeekError::Unexpected(e.to_string())) + } else { + let indent = " ".repeat(PREVIEW.tab_size as usize); + Ok(Text::from(after.join("").replace('\t', &indent))) + } } else { Self::highlight_with(before, after, syntax.unwrap()).await }