/// Check if a terminfo entry exists on the system.
Check if a terminfo entry exists on the system.
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
}
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 ! ( " " 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 ( " " ) { check_path ! ( PathBuf from ( dir ) ) ; } else if let Some ( home ) = dirs :: home_dir ( ) { check_path ! ( home join ( " " ) ) ; } if let Ok ( dirs ) = env :: var ( " " ) { for dir in dirs . split ( ':' ) { check_path ! ( PathBuf from ( dir ) ) ; } } if let Ok ( prefix ) = env :: var ( " " ) { let path = PathBuf :: from ( prefix ) ; check_path ! ( path join ( " " ) ) ; check_path ! ( path join ( " " ) ) ; check_path ! ( path join ( " " ) ) ; } check_path ! ( PathBuf from ( " " ) ) ; check_path ! ( PathBuf from ( " " ) ) ; check_path ! ( PathBuf from ( " " ) ) ; check_path ! ( PathBuf from ( " " ) ) ; // No valid terminfo path has been found. false }
Check if a terminfo entry exists on the system.
Check if a terminfo entry exists on the system .
terminfo
&str