9#define WIN32_LEAN_AND_MEAN
28Dimensions& FallbackSize() {
29#if defined(__EMSCRIPTEN__)
33 constexpr int fallback_width = 140;
34 constexpr int fallback_height = 43;
38 constexpr int fallback_width = 80;
39 constexpr int fallback_height = 24;
41 static Dimensions g_fallback_size{
45 return g_fallback_size;
48const char* Safe(
const char* c) {
49 return (c !=
nullptr) ? c :
"";
52bool Contains(
const std::string& s,
const char* key) {
53 return s.find(key) != std::string::npos;
57#if defined(__EMSCRIPTEN__)
61 std::string COLORTERM = Safe(std::getenv(
"COLORTERM"));
62 if (Contains(COLORTERM,
"24bit") || Contains(COLORTERM,
"truecolor")) {
66 std::string TERM = Safe(std::getenv(
"TERM"));
67 if (Contains(COLORTERM,
"256") || Contains(TERM,
"256")) {
71#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
74 if (TERM.empty() && COLORTERM.empty()) {
90#if defined(__EMSCRIPTEN__)
94 return FallbackSize();
96 CONSOLE_SCREEN_BUFFER_INFO csbi;
98 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {
99 return Dimensions{csbi.srWindow.Right - csbi.srWindow.Left + 1,
100 csbi.srWindow.Bottom - csbi.srWindow.Top + 1};
103 return FallbackSize();
106 const int status = ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
108 if (w.ws_col == 0 || w.ws_row == 0 || status < 0) {
109 return FallbackSize();
118 FallbackSize() = fallbackSize;
126 g_cached_supported_color = ComputeColorSupport();
128 return g_cached_supported_color;
135 g_cached_supported_color =
color;
void SetColorSupport(Color color)
在自动检测失败时覆盖终端颜色支持
Decorator color(Color)
使用前景色进行装饰。
Color
Color 是一个表示终端颜色支持的枚举。
Color ColorSupport()
获取终端的颜色支持。
FTXUI ftxui::Terminal:: 命名空间
void SetFallbackSize(const Dimensions &fallbackSize)
在自动检测失败时覆盖终端尺寸
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase