Add support for nxxm.

[nxxm](https://nxxm.github.io)
This commit is contained in:
ArthurSonzogni
2019-02-02 01:59:48 +01:00
parent 2eddd0fa17
commit ef0de8d873
72 changed files with 309 additions and 165 deletions

61
src/ftxui/dom/color.cpp Normal file
View File

@@ -0,0 +1,61 @@
#include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui {
class BgColor : public NodeDecorator {
public:
BgColor(Elements children, Color color)
: NodeDecorator(std::move(children)), color_(color) {}
void Render(Screen& screen) override {
for (int y = box_.y_min; y <= box_.y_max; ++y) {
for (int x = box_.x_min; x <= box_.x_max; ++x) {
screen.PixelAt(x, y).background_color = color_;
}
}
NodeDecorator::Render(screen);
}
Color color_;
};
class FgColor : public NodeDecorator {
public:
FgColor(Elements children, Color color)
: NodeDecorator(std::move(children)), color_(color) {}
~FgColor() override {}
void Render(Screen& screen) override {
for (int y = box_.y_min; y <= box_.y_max; ++y) {
for (int x = box_.x_min; x <= box_.x_max; ++x) {
screen.PixelAt(x, y).foreground_color = color_;
}
}
NodeDecorator::Render(screen);
}
Color color_;
};
std::unique_ptr<Node> color(Color c, Element child) {
return std::make_unique<FgColor>(unpack(std::move(child)), c);
}
std::unique_ptr<Node> bgcolor(Color c, Element child) {
return std::make_unique<BgColor>(unpack(std::move(child)), c);
}
Decorator color(Color c) {
return [c](Element child) {
return color(c, std::move(child));
};
}
Decorator bgcolor(Color c) {
return [c](Element child) {
return bgcolor(c, std::move(child));
};
}
}; // namespace ftxui