Check max_colors with rest of checks in input.cpp.

... with a terminal set up.
This commit is contained in:
Aaron Gyes 2016-07-19 08:01:01 -07:00
parent 23ea77be76
commit 9aad3781fb
2 changed files with 7 additions and 6 deletions

View file

@ -299,9 +299,11 @@ static int interrupt_handler() {
} }
void update_fish_color_support(void) { void update_fish_color_support(void) {
// Infer term256 support. If fish_term256 is set, we respect it; otherwise try to detect it from // Detect or infer term256 support. If fish_term256 is set, we respect it;
// the TERM variable. // otherwise try to detect terminfo else infer it from the TERM variable.
env_var_t fish_term256 = env_get_string(L"fish_term256"); env_var_t fish_term256 = env_get_string(L"fish_term256");
int err_ret;
bool support_term256; bool support_term256;
if (!fish_term256.missing_or_empty()) { if (!fish_term256.missing_or_empty()) {
support_term256 = from_string<bool>(fish_term256); support_term256 = from_string<bool>(fish_term256);
@ -309,6 +311,8 @@ void update_fish_color_support(void) {
env_var_t term = env_get_string(L"TERM"); env_var_t term = env_get_string(L"TERM");
if (term.missing()) { if (term.missing()) {
support_term256 = false; support_term256 = false;
} else if (setupterm(NULL, STDOUT_FILENO, &err_ret) != ERR) {
support_term256 = (max_colors >= 256);
} else if (term.find(L"256color") != wcstring::npos) { } else if (term.find(L"256color") != wcstring::npos) {
// Explicitly supported. // Explicitly supported.
support_term256 = true; support_term256 = true;

View file

@ -47,10 +47,7 @@ int (*output_get_writer())(char) { return out; }
// Returns true if we think the term256 support is "native" as opposed to forced. // Returns true if we think the term256 support is "native" as opposed to forced.
static bool term256_support_is_native(void) { return max_colors >= 256; } static bool term256_support_is_native(void) { return max_colors >= 256; }
color_support_t output_get_color_support(void) { color_support_t output_get_color_support(void) { return color_support; }
if (term256_support_is_native()) { return color_support_term256 | color_support; }
return color_support;
}
void output_set_color_support(color_support_t val) { color_support = val; } void output_set_color_support(color_support_t val) { color_support = val; }