diff options
| author | Thomas Otto <th1000s@posteo.net> | 2024-07-16 09:35:35 +0200 |
|---|---|---|
| committer | Dan Davison <dandavison7@gmail.com> | 2024-07-17 10:13:59 +0100 |
| commit | 048ae76aaa5f0a37d107ed512da57aba51c3687d (patch) | |
| tree | 397044f7edd4d7696ba2b6cf383596c2469aa4c8 /src | |
| parent | c4803e6825826b6e38904b6b0579040f2d46bfb3 (diff) | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/utils/bat/output.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/utils/bat/output.rs b/src/utils/bat/output.rs index 54373ef..91fb5ba 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. <U+E012> 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); |
