mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-07-27 23:58:00 +08:00
Fix terminal color detection support. (#65)
There was many obvious bugs, discovered here:
ad2a085469/Open-Source-Project-Anatomy/FTXUI.md
This commit is contained in:
parent
3a3ec13eb0
commit
305346542a
@ -41,15 +41,19 @@ const char* Safe(const char* c) {
|
|||||||
return c ? c : "";
|
return c ? c : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Contains(const std::string& s, const char* key) {
|
||||||
|
return s.find(key) != std::string::npos;
|
||||||
|
}
|
||||||
|
|
||||||
static bool cached = false;
|
static bool cached = false;
|
||||||
Terminal::Color cached_supported_color;
|
Terminal::Color cached_supported_color;
|
||||||
Terminal::Color ComputeColorSupport() {
|
Terminal::Color ComputeColorSupport() {
|
||||||
std::string COLORTERM = Safe(std::getenv("COLORTERM"));
|
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;
|
return Terminal::Color::TrueColor;
|
||||||
|
|
||||||
std::string TERM = Safe(std::getenv("TERM"));
|
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::Palette256;
|
||||||
|
|
||||||
return Terminal::Color::Palette16;
|
return Terminal::Color::Palette16;
|
||||||
|
Loading…
Reference in New Issue
Block a user