-
-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clang(windows) getenv deprecation warn fix #900
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it means FTXUI won't work under UWP? This sounds problematic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be honest, I haven't tested this under UWP, but I can assume that UWP applications don't have access to environment variables. |
||
#else | ||
size_t len = 0; | ||
char buf[1024]; | ||
bool ok = ::getenv_s(&len, buf, sizeof(buf), field) == 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know.😅 |
||
return ok ? buf : std::string{}; | ||
#endif | ||
#else // revert to getenv | ||
char *buf = ::getenv(field); // NOLINT(*-mt-unsafe) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the previous implementation was meant to fix this |
||
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; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any warning on my bots:
https://github.com/ArthurSonzogni/FTXUI/actions/runs/9695462958/job/26755276508
What configs should I add to reproduce?
Are you using the build config the FTXUI project define (e.g. are you using CMake at the end)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I'm sorry. This is not msvc, but clang for windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArthurSonzogni see workflow run on my fork
https://github.com/alexv-ds/FTXUI/actions/runs/10021288139/job/27699782082#step:6:72