Skip to content

Add simple terminfo detection to std::term #6453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/libstd/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use core::io;
use core::option;
use core::os;
use core::path;

// FIXME (#2807): Windows support.

Expand Down Expand Up @@ -45,17 +46,20 @@ pub fn reset(writer: @io::Writer) {

/// Returns true if the terminal supports color
pub fn color_supported() -> bool {
let supported_terms = ~[~"xterm-color", ~"xterm",
~"screen-bce", ~"xterm-256color"];
return match os::getenv(~"TERM") {
option::Some(ref env) => {
for supported_terms.each |term| {
if *term == *env { return true; }
}
false
}
option::None => false
};
let term = match os::getenv(~"TERM") {
option::Some(env) => env,
option::None => ~""
};
let terminfodir = match os::getenv(~"TERMINFO") {
option::Some(env) => env,
option::None => ~"/usr/share/terminfo"
};
if os::path_exists(&path::PosixPath(terminfodir + "/" + str::substr(term, 0, 1) + "/" +
term)) {
return true;
} else {
return false;
}
}

pub fn set_color(writer: @io::Writer, first_char: u8, color: u8) {
Expand Down