7 #define WIN32_LEAN_AND_MEAN
15 #include <sys/ioctl.h>
22 Dimensions& FallbackSize() {
23 #if defined(__EMSCRIPTEN__)
28 constexpr
int fallback_width = 140;
29 constexpr
int fallback_height = 43;
34 constexpr
int fallback_width = 80;
35 constexpr
int fallback_height = 24;
37 static Dimensions g_fallback_size{fallback_width, fallback_height};
38 return g_fallback_size;
41 const char* Safe(
const char* c) {
42 return (c !=
nullptr) ? c :
"";
45 bool Contains(
const std::string& s,
const char* key) {
46 return s.find(key) != std::string::npos;
50 #if defined(__EMSCRIPTEN__)
54 std::string COLORTERM = Safe(std::getenv(
"COLORTERM"));
55 if (Contains(COLORTERM,
"24bit") || Contains(COLORTERM,
"truecolor")) {
59 std::string TERM = Safe(std::getenv(
"TERM"));
60 if (Contains(COLORTERM,
"256") || Contains(TERM,
"256")) {
64 #if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
69 if (TERM ==
"" && COLORTERM ==
"") {
80 #if defined(__EMSCRIPTEN__)
85 return FallbackSize();
87 CONSOLE_SCREEN_BUFFER_INFO csbi;
89 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {
90 return Dimensions{csbi.srWindow.Right - csbi.srWindow.Left + 1,
91 csbi.srWindow.Bottom - csbi.srWindow.Top + 1};
94 return FallbackSize();
97 const int status = ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
100 if (w.ws_col == 0 || w.ws_row == 0 || status < 0) {
101 return FallbackSize();
110 FallbackSize() = fallbackSize;
114 static bool cached =
false;
118 cached_supported_color = ComputeColorSupport();
120 return cached_supported_color;
void SetFallbackSize(const Dimensions &fallbackSize)
Override terminal size in case auto-detection fails.