Skip to content

Commit

Permalink
Enable true colors if the terminfo RGB capability is set
Browse files Browse the repository at this point in the history
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 #1931
  • Loading branch information
Tachi107 committed Dec 29, 2024
1 parent ef3e1be commit eb552ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 6 additions & 2 deletions src/options/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,10 +662,14 @@ 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)]
Expand Down

0 comments on commit eb552ae

Please sign in to comment.