Skip to content

Commit

Permalink
Make less version >= 633 behave like previous versions wrt. Nerd Fonts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
th1000s authored and dandavison committed Jul 17, 2024
1 parent c4803e6 commit 048ae76
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/utils/bat/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub enum PagingMode {
#[default]
Never,
}
const LESSUTFCHARDEF: &str = "LESSUTFCHARDEF";
use crate::errors::*;

pub enum OutputType {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 048ae76

Please sign in to comment.