Skip to content

Commit

Permalink
terminfo: Support more terminfo directory structures
Browse files Browse the repository at this point in the history
OS X's terminfo uses the hex representation of the first character of
the terminal name as the directory name.

Ubuntu seems to use /lib/terminfo instead of /usr/share/terminfo, at
least on the one machine I have access to.
  • Loading branch information
lilyball committed Jun 10, 2013
1 parent 1310212 commit 8f1edd5
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/libextra/terminfo/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~path> {
dirs_to_search.push(path(i.to_owned()));
}
},
// Found nothing, use the default path
None => dirs_to_search.push(path("/usr/share/terminfo"))
// Found nothing, use the default paths
// /usr/share/terminfo is the de facto location, but it seems
// Ubuntu puts it in /lib/terminfo
None => {
dirs_to_search.push(path("/usr/share/terminfo"));
dirs_to_search.push(path("/lib/terminfo"));
}
}
}
};
Expand All @@ -56,6 +61,11 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~path> {
if os::path_exists(p) && os::path_exists(newp) {
return Some(newp);
}
// on some installations the dir is named after the hex of the char (e.g. OS X)
let newp = ~p.push_many(&[fmt!("%x", first_char[0] as uint), term.to_owned()]);
if os::path_exists(p) && os::path_exists(newp) {
return Some(newp);
}
}
None
}
Expand All @@ -72,6 +82,7 @@ pub fn open(term: &str) -> Result<@Reader, ~str> {
#[ignore(reason = "buildbots don't have ncurses installed and I can't mock everything I need")]
fn test_get_dbpath_for_term() {
// woefully inadequate test coverage
// note: current tests won't work with non-standard terminfo hierarchies (e.g. OS X's)
use std::os::{setenv, unsetenv};
fn x(t: &str) -> ~str { get_dbpath_for_term(t).expect("no terminfo entry found").to_str() };
assert!(x("screen") == ~"/usr/share/terminfo/s/screen");
Expand Down

5 comments on commit 8f1edd5

@bors
Copy link
Contributor

@bors bors commented on 8f1edd5 Jun 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from thestinger
at lilyball@8f1edd5

@bors
Copy link
Contributor

@bors bors commented on 8f1edd5 Jun 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging kballard/rust/terminfo-searcher-paths = 8f1edd5 into auto

@bors
Copy link
Contributor

@bors bors commented on 8f1edd5 Jun 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kballard/rust/terminfo-searcher-paths = 8f1edd5 merged ok, testing candidate = 37733c7

@bors
Copy link
Contributor

@bors bors commented on 8f1edd5 Jun 11, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 8f1edd5 Jun 11, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 37733c7

Please sign in to comment.