10#define WIN32_LEAN_AND_MEAN
29Dimensions& FallbackSize() {
30#if defined(__EMSCRIPTEN__)
35 constexpr int fallback_width = 140;
36 constexpr int fallback_height = 43;
41 constexpr int fallback_width = 80;
42 constexpr int fallback_height = 24;
44 static Dimensions g_fallback_size{
48 return g_fallback_size;
51const char* Safe(
const char* c) {
52 return (c !=
nullptr) ? c :
"";
55bool Contains(
const std::string& s,
const char* key) {
56 return s.find(key) != std::string::npos;
60#if defined(__EMSCRIPTEN__)
64 std::string COLORTERM = Safe(std::getenv(
"COLORTERM"));
65 if (Contains(COLORTERM,
"24bit") || Contains(COLORTERM,
"truecolor")) {
69 std::string TERM = Safe(std::getenv(
"TERM"));
70 if (Contains(COLORTERM,
"256") || Contains(TERM,
"256")) {
74#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
79 if (TERM.empty() && COLORTERM.empty()) {
95#if defined(__EMSCRIPTEN__)
100 return FallbackSize();
102 CONSOLE_SCREEN_BUFFER_INFO csbi;
104 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {
105 return Dimensions{csbi.srWindow.Right - csbi.srWindow.Left + 1,
106 csbi.srWindow.Bottom - csbi.srWindow.Top + 1};
109 return FallbackSize();
112 const int status = ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
115 if (w.ws_col == 0 || w.ws_row == 0 || status < 0) {
116 return FallbackSize();
125 FallbackSize() = fallbackSize;
133 g_cached_supported_color = ComputeColorSupport();
135 return g_cached_supported_color;
142 g_cached_supported_color =
color;
void SetColorSupport(Color color)
Override terminal color support in case auto-detection fails.
void SetFallbackSize(const Dimensions &fallbackSize)
Override terminal size in case auto-detection fails.
Dimensions Size()
Get the terminal size.
Color ColorSupport()
Get the color support of the terminal.
Decorator color(Color)
Decorate using a foreground color.