7#define WIN32_LEAN_AND_MEAN
26Dimensions& FallbackSize() {
27#if defined(__EMSCRIPTEN__)
32 constexpr int fallback_width = 140;
33 constexpr int fallback_height = 43;
38 constexpr int fallback_width = 80;
39 constexpr int fallback_height = 24;
41 static Dimensions g_fallback_size{fallback_width, fallback_height};
42 return g_fallback_size;
45const char* Safe(
const char* c) {
46 return (c !=
nullptr) ? c :
"";
49bool Contains(
const std::string& s,
const char* key) {
50 return s.find(key) != std::string::npos;
54#if defined(__EMSCRIPTEN__)
58 std::string COLORTERM = Safe(std::getenv(
"COLORTERM"));
59 if (Contains(COLORTERM,
"24bit") || Contains(COLORTERM,
"truecolor")) {
63 std::string TERM = Safe(std::getenv(
"TERM"));
64 if (Contains(COLORTERM,
"256") || Contains(TERM,
"256")) {
68#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
73 if (TERM ==
"" && COLORTERM ==
"") {
85#if defined(__EMSCRIPTEN__)
90 return FallbackSize();
92 CONSOLE_SCREEN_BUFFER_INFO csbi;
94 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {
95 return Dimensions{csbi.srWindow.Right - csbi.srWindow.Left + 1,
96 csbi.srWindow.Bottom - csbi.srWindow.Top + 1};
99 return FallbackSize();
102 const int status = ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
105 if (w.ws_col == 0 || w.ws_row == 0 || status < 0) {
106 return FallbackSize();
115 FallbackSize() = fallbackSize;
121 g_cached_supported_color = ComputeColorSupport();
123 return g_cached_supported_color;
128 g_cached_supported_color =
color;
void SetColorSupport(Color color)
void SetFallbackSize(const Dimensions &fallbackSize)
Override terminal size in case auto-detection fails.
Decorator color(Color)
Decorate using a foreground color.