From 237d089446865712dd199736484af06be64ef1a2 Mon Sep 17 00:00:00 2001 From: Andrea Pappacoda Date: Sun, 29 Dec 2024 01:09:23 +0100 Subject: [PATCH] Enable true colors if the terminfo RGB capability is set This allows delta to work properly on Direct Color terminals like xterm-direct and foot-direct. This adds a dependency on the "terminfo" crate in order to read the `RGB` capability. The crate is used by wezterm, among others. Fixes https://github.com/dandavison/delta/issues/1931 --- Cargo.toml | 1 + src/options/set.rs | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6401aaf21..7b00e806b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,6 +54,7 @@ syntect = "5.0.0" # sysinfo: no default features to disable the use of threads sysinfo = { version = "0.29.0", default-features = false, features = [] } terminal-colorsaurus = "0.4.1" +terminfo = "0.9.0" unicode-segmentation = "1.10.1" unicode-width = "=0.1.12" xdg = "2.4.1" diff --git a/src/options/set.rs b/src/options/set.rs index 6d26d15df..0a0025d38 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -662,10 +662,15 @@ fn set_true_color(opt: &mut cli::Opt) { } fn is_truecolor_terminal(env: &DeltaEnv) -> bool { - env.colorterm + let rgb_cap = terminfo::Database::from_env() + .map(|db| db.raw("RGB").is_some()) + .unwrap_or(false); + let colorterm = env + .colorterm .as_ref() .map(|colorterm| colorterm == "truecolor" || colorterm == "24bit") - .unwrap_or(false) + .unwrap_or(false); + rgb_cap || colorterm } #[cfg(test)]