FTXUI/src/ftxui/screen/terminal.cpp

52 lines
1.2 KiB
C++
Raw Normal View History

2020-03-23 05:32:44 +08:00
#include "ftxui/screen/terminal.hpp"
2018-09-18 14:48:40 +08:00
#include <stdio.h>
#include <cstdlib>
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <Windows.h>
#else
#include <sys/ioctl.h>
#include <unistd.h>
#endif
2018-09-18 14:48:40 +08:00
2020-03-23 05:32:44 +08:00
#include <iostream>
2018-09-18 14:48:40 +08:00
namespace ftxui {
Terminal::Dimensions Terminal::Size() {
#if defined(__EMSCRIPTEN__)
return Dimensions{80, 43};
#elif defined(_WIN32)
CONSOLE_SCREEN_BUFFER_INFO csbi;
int columns, rows;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
return Dimensions{columns, rows};
#else
2018-09-18 14:48:40 +08:00
winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
return Dimensions{w.ws_col, w.ws_row};
#endif
2018-09-18 14:48:40 +08:00
}
bool Terminal::CanSupportTrueColors() {
char *COLORTERM_RAW = std::getenv("COLORTERM");
if (nullptr == COLORTERM_RAW) {
return false;
}
std::string COLORTERM = COLORTERM_RAW;
return COLORTERM.compare("24bit") || COLORTERM.compare("trueColor");
}
} // namespace ftxui
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.