From 048ae76aaa5f0a37d107ed512da57aba51c3687d Mon Sep 17 00:00:00 2001 From: Thomas Otto Date: Tue, 16 Jul 2024 09:35:35 +0200 Subject: [PATCH] Make less version >= 633 behave like previous versions wrt. Nerd Fonts Sets `LESSUTFCHARDEF` (unless already present), a new env var introduced by this less version to always print characters from the Private Use Area of Unicode as-is, even if the terminal does not understand them. --- src/utils/bat/output.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/utils/bat/output.rs b/src/utils/bat/output.rs index 54373ef1b..91fb5ba71 100644 --- a/src/utils/bat/output.rs +++ b/src/utils/bat/output.rs @@ -21,6 +21,7 @@ pub enum PagingMode { #[default] Never, } +const LESSUTFCHARDEF: &str = "LESSUTFCHARDEF"; use crate::errors::*; pub enum OutputType { @@ -156,8 +157,22 @@ fn _make_process_from_less_path( } else { p.args(args); } + + // less >= 633 (from May 2023) prints any characters from the Private Use Area of Unicode + // as control characters (e.g. instead of hoping that the terminal can render it). + // This means any Nerd Fonts will not be displayed properly. Previous versions of less just + // passed these characters through, and terminals usually fall back to a less obtrusive + // box. Use this new env var less introduced to restore the previous behavior. This sets all + // chars to single width (':p', see less manual). If a user provided env var is present, + // use do not override it. + // Also see delta issue 1616 and nerd-fonts/issues/1337 + if std::env::var(LESSUTFCHARDEF).is_err() { + p.env(LESSUTFCHARDEF, "E000-F8FF:p,F0000-FFFFD:p,100000-10FFFD:p"); + } + p.env("LESSCHARSET", "UTF-8"); p.env("LESSANSIENDCHARS", "mK"); + if config.navigate { if let Ok(hist_file) = navigate::copy_less_hist_file_and_append_navigate_regex(config) { p.env("LESSHISTFILE", hist_file);