]>
git.proxmox.com Git - rustc.git/blob - vendor/term-0.6.1/src/terminfo/searcher.rs
1 // Copyright 2019 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! ncurses-compatible database discovery
13 //! Does not support hashed database, only filesystem!
17 use std
::path
::PathBuf
;
21 /// Return path to database entry for `term`
22 pub fn get_dbpath_for_term(term
: &str) -> Option
<PathBuf
> {
23 let mut dirs_to_search
= Vec
::new();
24 let first_char
= match term
.chars().next() {
29 // Find search directory
30 // The terminfo manual says:
32 // > If the environment variable TERMINFO is set, it is interpreted
33 // > as the pathname of a directory containing the compiled description
34 // > you are working on. Only that directory is searched.
36 // However, the ncurses manual says:
38 // > If the environment variable TERMINFO is defined, any program using
39 // > curses checks for a local terminal definition before checking in
40 // > the standard place.
42 // Given that ncurses is the defacto standard, we follow the ncurses manual.
43 if let Some(dir
) = env
::var_os("TERMINFO") {
44 dirs_to_search
.push(PathBuf
::from(dir
));
47 if let Ok(dirs
) = env
::var("TERMINFO_DIRS") {
48 for i
in dirs
.split('
:'
) {
50 dirs_to_search
.push(PathBuf
::from("/usr/share/terminfo"));
52 dirs_to_search
.push(PathBuf
::from(i
));
56 // Found nothing in TERMINFO_DIRS, use the default paths:
57 // According to /etc/terminfo/README, after looking at
58 // ~/.terminfo, ncurses will search /etc/terminfo, then
59 // /lib/terminfo, and eventually /usr/share/terminfo.
60 // On Haiku the database can be found at /boot/system/data/terminfo
61 if let Some(mut homedir
) = dirs
::home_dir() {
62 homedir
.push(".terminfo");
63 dirs_to_search
.push(homedir
)
66 dirs_to_search
.push(PathBuf
::from("/etc/terminfo"));
67 dirs_to_search
.push(PathBuf
::from("/lib/terminfo"));
68 dirs_to_search
.push(PathBuf
::from("/usr/share/terminfo"));
69 dirs_to_search
.push(PathBuf
::from("/boot/system/data/terminfo"));
72 // Look for the terminal in all of the search directories
73 for mut p
in dirs_to_search
{
74 if fs
::metadata(&p
).is_ok() {
75 p
.push(&first_char
.to_string());
77 if fs
::metadata(&p
).is_ok() {
83 // on some installations the dir is named after the hex of the char
85 p
.push(&format
!("{:x}", first_char
as usize));
87 if fs
::metadata(&p
).is_ok() {