diff options
author | Caden Haustein <code@brightlysalty.33mail.com> | 2020-12-22 02:38:50 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-22 02:38:50 +0000 |
commit | 8982000f01d5f476a995385253139b3555e2a5d0 (patch) | |
tree | fd3569564482ece31c1cb80897f0e7dcd0846933 /alacritty_terminal | |
parent | 5725f5812ca5e8d7d992da4ac66aa454a8a9a9ad (diff) | |
download | alacritty-8982000f01d5f476a995385253139b3555e2a5d0.tar.gz alacritty-8982000f01d5f476a995385253139b3555e2a5d0.zip |
Remove terminfo dependency
Fixes #4597.
Co-authored-by: Christian Duerr <contact@christianduerr.com>
Diffstat (limited to 'alacritty_terminal')
-rw-r--r-- | alacritty_terminal/Cargo.toml | 2 | ||||
-rw-r--r-- | alacritty_terminal/src/tty/mod.rs | 54 |
2 files changed, 49 insertions, 7 deletions
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<C>(config: &Config<C>) { // 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<C>(config: &Config<C>) { 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 +} |