mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-24 03:30:49 +08:00
Compare commits
3 Commits
00be7cdd49
...
2aa4a9abc0
Author | SHA1 | Date | |
---|---|---|---|
|
2aa4a9abc0 | ||
|
55af678fb9 | ||
|
baa5973128 |
@ -339,6 +339,7 @@ Feel free to add your projects here:
|
||||
- [2048-cpp](https://github.com/Chessom/2048-cpp)
|
||||
- [Memory game](https://github.com/mikolajlubiak/memory)
|
||||
- [Terminal Animation](https://github.com/mikolajlubiak/terminal_animation)
|
||||
- [pciex](https://github.com/s0nx/pciex)
|
||||
|
||||
|
||||
### [cpp-best-practices/game_jam](https://github.com/cpp-best-practices/game_jam)
|
||||
|
@ -48,25 +48,38 @@ Dimensions& FallbackSize() {
|
||||
return g_fallback_size;
|
||||
}
|
||||
|
||||
const char* Safe(const char* c) {
|
||||
return (c != nullptr) ? c : "";
|
||||
}
|
||||
|
||||
bool Contains(const std::string& s, const char* key) {
|
||||
return s.find(key) != std::string::npos;
|
||||
}
|
||||
|
||||
// https://github.com/gabime/spdlog/blob/885b5473e291833b148eeac3b7ce227e582cd88b/include/spdlog/details/os-inl.h#L566
|
||||
std::string getenv_safe(const char *field) {
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(__cplusplus_winrt)
|
||||
return std::string{}; // not supported under uwp
|
||||
#else
|
||||
size_t len = 0;
|
||||
char buf[1024];
|
||||
bool ok = ::getenv_s(&len, buf, sizeof(buf), field) == 0;
|
||||
return ok ? buf : std::string{};
|
||||
#endif
|
||||
#else // revert to getenv
|
||||
char *buf = ::getenv(field); // NOLINT(*-mt-unsafe)
|
||||
return buf ? buf : std::string{};
|
||||
#endif
|
||||
}
|
||||
|
||||
Terminal::Color ComputeColorSupport() {
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
return Terminal::Color::TrueColor;
|
||||
#endif
|
||||
|
||||
std::string COLORTERM = Safe(std::getenv("COLORTERM")); // NOLINT
|
||||
std::string COLORTERM = getenv_safe("COLORTERM");
|
||||
if (Contains(COLORTERM, "24bit") || Contains(COLORTERM, "truecolor")) {
|
||||
return Terminal::Color::TrueColor;
|
||||
}
|
||||
|
||||
std::string TERM = Safe(std::getenv("TERM")); // NOLINT
|
||||
std::string TERM = getenv_safe("TERM");
|
||||
if (Contains(COLORTERM, "256") || Contains(TERM, "256")) {
|
||||
return Terminal::Color::Palette256;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user