diff --git a/Cargo.lock b/Cargo.lock index f9b53890..a520832a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -75,6 +75,7 @@ dependencies = [ "alacritty_config_derive", "base64", "bitflags", + "dirs", "libc", "log", "mio", @@ -89,7 +90,6 @@ dependencies = [ "serde_json", "serde_yaml", "signal-hook", - "terminfo", "unicode-width", "vte", "winapi 0.3.9", @@ -1482,44 +1482,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" -[[package]] -name = "phf" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dfb61232e34fcb633f43d12c58f83c1df82962dcdfa565a4e866ffc17dafe12" -dependencies = [ - "phf_shared", -] - -[[package]] -name = "phf_codegen" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbffee61585b0411840d3ece935cce9cb6321f01c45477d30066498cd5e1a815" -dependencies = [ - "phf_generator", - "phf_shared", -] - -[[package]] -name = "phf_generator" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526" -dependencies = [ - "phf_shared", - "rand", -] - -[[package]] -name = "phf_shared" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7" -dependencies = [ - "siphasher", -] - [[package]] name = "pkg-config" version = "0.3.19" @@ -1587,7 +1549,6 @@ dependencies = [ "rand_chacha", "rand_core", "rand_hc", - "rand_pcg", ] [[package]] @@ -1618,15 +1579,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "rand_pcg" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" -dependencies = [ - "rand_core", -] - [[package]] name = "raw-window-handle" version = "0.3.3" @@ -1879,12 +1831,6 @@ dependencies = [ "libc", ] -[[package]] -name = "siphasher" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa8f3741c7372e75519bd9346068370c9cdaabcc1f9599cbcf2a2719352286b7" - [[package]] name = "slab" version = "0.4.2" @@ -1991,19 +1937,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "terminfo" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76971977e6121664ec1b960d1313aacfa75642adc93b9d4d53b247bd4cb1747e" -dependencies = [ - "dirs", - "fnv", - "nom", - "phf", - "phf_codegen", -] - [[package]] name = "textwrap" version = "0.11.0" diff --git a/alacritty_terminal/Cargo.toml b/alacritty_terminal/Cargo.toml index 9bdccf7b..b859185c 100644 --- a/alacritty_terminal/Cargo.toml +++ b/alacritty_terminal/Cargo.toml @@ -24,8 +24,8 @@ mio-extras = "2" log = "0.4" unicode-width = "0.1" base64 = "0.12.0" -terminfo = "0.7.1" regex-automata = "0.1.9" +dirs = "2.0.2" [target.'cfg(unix)'.dependencies] nix = "0.18.0" diff --git a/alacritty_terminal/src/tty/mod.rs b/alacritty_terminal/src/tty/mod.rs index 7df4f140..a1c8c0c1 100644 --- a/alacritty_terminal/src/tty/mod.rs +++ b/alacritty_terminal/src/tty/mod.rs @@ -1,9 +1,8 @@ //! TTY related functionality. +use std::path::PathBuf; use std::{env, io}; -use terminfo::Database; - use crate::config::Config; #[cfg(not(windows))] @@ -65,10 +64,8 @@ pub fn setup_env(config: &Config) { // Default to 'alacritty' terminfo if it is available, otherwise // default to 'xterm-256color'. May be overridden by user's config // below. - env::set_var( - "TERM", - if Database::from_name("alacritty").is_ok() { "alacritty" } else { "xterm-256color" }, - ); + let terminfo = if terminfo_exists("alacritty") { "alacritty" } else { "xterm-256color" }; + env::set_var("TERM", terminfo); // Advertise 24-bit color support. env::set_var("COLORTERM", "truecolor"); @@ -81,3 +78,48 @@ pub fn setup_env(config: &Config) { env::set_var(key, value); } } + +/// Check if a terminfo entry exists on the system. +fn terminfo_exists(terminfo: &str) -> bool { + // Get first terminfo character for the parent directory. + let first = terminfo.get(..1).unwrap_or_default(); + let first_hex = format!("{:x}", first.chars().next().unwrap_or_default() as usize); + + // Return true if the terminfo file exists at the specified location. + macro_rules! check_path { + ($path:expr) => { + if $path.join(first).join(terminfo).exists() + || $path.join(&first_hex).join(terminfo).exists() + { + return true; + } + }; + } + + if let Some(dir) = env::var_os("TERMINFO") { + check_path!(PathBuf::from(&dir)); + } else if let Some(home) = dirs::home_dir() { + check_path!(home.join(".terminfo")); + } + + if let Ok(dirs) = env::var("TERMINFO_DIRS") { + for dir in dirs.split(':') { + check_path!(PathBuf::from(dir)); + } + } + + if let Ok(prefix) = env::var("PREFIX") { + let path = PathBuf::from(prefix); + check_path!(path.join("etc/terminfo")); + check_path!(path.join("lib/terminfo")); + check_path!(path.join("share/terminfo")); + } + + check_path!(PathBuf::from("/etc/terminfo")); + check_path!(PathBuf::from("/lib/terminfo")); + check_path!(PathBuf::from("/usr/share/terminfo")); + check_path!(PathBuf::from("/boot/system/data/terminfo")); + + // No valid terminfo path has been found. + false +}