From 9aad3781fb3e45a2c18aaf42a698c43261f4cebc Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Tue, 19 Jul 2016 08:01:01 -0700 Subject: [PATCH] Check max_colors with rest of checks in input.cpp. ... with a terminal set up. --- src/input.cpp | 8 ++++++-- src/output.cpp | 5 +---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index 2155e485e..d0ce72ea1 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -299,9 +299,11 @@ static int interrupt_handler() { } void update_fish_color_support(void) { - // Infer term256 support. If fish_term256 is set, we respect it; otherwise try to detect it from - // the TERM variable. + // Detect or infer term256 support. If fish_term256 is set, we respect it; + // otherwise try to detect terminfo else infer it from the TERM variable. env_var_t fish_term256 = env_get_string(L"fish_term256"); + int err_ret; + bool support_term256; if (!fish_term256.missing_or_empty()) { support_term256 = from_string(fish_term256); @@ -309,6 +311,8 @@ void update_fish_color_support(void) { env_var_t term = env_get_string(L"TERM"); if (term.missing()) { 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) { // Explicitly supported. support_term256 = true; diff --git a/src/output.cpp b/src/output.cpp index af6fe24f2..85f1f1b9c 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -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. static bool term256_support_is_native(void) { return max_colors >= 256; } -color_support_t output_get_color_support(void) { - if (term256_support_is_native()) { return color_support_term256 | color_support; } - return color_support; -} +color_support_t output_get_color_support(void) { return color_support; } void output_set_color_support(color_support_t val) { color_support = val; }