Add webassembly support (#79)

This commit is contained in:
Arthur Sonzogni
2021-03-22 00:26:52 +01:00
committed by GitHub
parent 65c0297789
commit 373b016ca9
35 changed files with 267 additions and 47 deletions

View File

@@ -2,6 +2,7 @@
#include <algorithm>
#include <sstream>
#include <iostream>
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/string.hpp"
@@ -149,6 +150,7 @@ Screen::Screen(int dimx, int dimy)
}
/// Produce a std::string that can be used to print the Screen on the terminal.
/// Don't forget to flush stdout. Alternatively, you can use Screen::Print();
std::string Screen::ToString() {
std::wstringstream ss;
@@ -158,7 +160,7 @@ std::string Screen::ToString() {
for (int y = 0; y < dimy_; ++y) {
if (y != 0) {
UpdatePixelStyle(ss, previous_pixel, final_pixel);
ss << '\n';
ss << L"\r\n";
}
for (int x = 0; x < dimx_;) {
auto& pixel = pixels_[y][x];
@@ -181,6 +183,10 @@ std::string Screen::ToString() {
return to_string(ss.str());
}
void Screen::Print() {
std::cout << ToString() << std::flush << (char)0;
}
/// @brief Access a character a given position.
/// @param x The character position along the x-axis.
/// @param y The character position along the y-axis.
@@ -254,6 +260,7 @@ void Screen::ApplyShader() {
}
}
}
// clang-format on
} // namespace ftxui

View File

@@ -19,7 +19,7 @@ namespace ftxui {
Terminal::Dimensions Terminal::Size() {
#if defined(__EMSCRIPTEN__)
return Dimensions{80, 43};
return Dimensions{140, 43};
#elif defined(_WIN32)
CONSOLE_SCREEN_BUFFER_INFO csbi;
int columns, rows;
@@ -48,6 +48,10 @@ bool Contains(const std::string& s, const char* key) {
static bool cached = false;
Terminal::Color cached_supported_color;
Terminal::Color ComputeColorSupport() {
#if defined(__EMSCRIPTEN__)
return Terminal::Color::TrueColor;
#endif
std::string COLORTERM = Safe(std::getenv("COLORTERM"));
if (Contains(COLORTERM, "24bit") || Contains(COLORTERM, "truecolor"))
return Terminal::Color::TrueColor;