From 305346542afc4c5c32807593e2078c242d1e00bf Mon Sep 17 00:00:00 2001 From: Arthur Sonzogni Date: Wed, 23 Dec 2020 12:20:01 +0100 Subject: [PATCH] Fix terminal color detection support. (#65) There was many obvious bugs, discovered here: https://github.com/Gusabary/SAIL/blob/ad2a085469d80cfdcccd13abc5efcbabf1154cd4/Open-Source-Project-Anatomy/FTXUI.md --- src/ftxui/screen/terminal.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ftxui/screen/terminal.cpp b/src/ftxui/screen/terminal.cpp index 1ff573b..fae1de8 100644 --- a/src/ftxui/screen/terminal.cpp +++ b/src/ftxui/screen/terminal.cpp @@ -41,15 +41,19 @@ const char* Safe(const char* c) { return c ? c : ""; } +bool Contains(const std::string& s, const char* key) { + return s.find(key) != std::string::npos; +} + static bool cached = false; Terminal::Color cached_supported_color; Terminal::Color ComputeColorSupport() { std::string COLORTERM = Safe(std::getenv("COLORTERM")); - if (COLORTERM.compare("24bit") || COLORTERM.compare("trueColor")) + if (Contains(COLORTERM, "24bit") || Contains(COLORTERM, "truecolor")) return Terminal::Color::TrueColor; std::string TERM = Safe(std::getenv("TERM")); - if (COLORTERM.compare("256") || COLORTERM.compare("256")) + if (Contains(COLORTERM, "256") || Contains(TERM, "256")) return Terminal::Color::Palette256; return Terminal::Color::Palette16;