summaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/tty
diff options
context:
space:
mode:
Diffstat (limited to 'alacritty_terminal/src/tty')
-rw-r--r--alacritty_terminal/src/tty/mod.rs54
1 files changed, 48 insertions, 6 deletions
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
+}