mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-28 17:58:07 +08:00
Refactor directory structure.
The goal is to increase the separation in between: * ftxui::screen * ftxui::dom * ftxui::component
This commit is contained in:
@@ -2,8 +2,7 @@
|
||||
#include "ftxui/component/delegate.hpp"
|
||||
#include <assert.h>
|
||||
|
||||
namespace ftxui {
|
||||
namespace component {
|
||||
namespace ftxui::component {
|
||||
|
||||
Component::Component(Delegate* delegate) {
|
||||
delegate_ = delegate;
|
||||
@@ -55,5 +54,4 @@ Component* Component::Parent() {
|
||||
return parent_delegate->component();
|
||||
}
|
||||
|
||||
} // namespace component
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::component
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#include "ftxui/component/component_direction.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace component {
|
||||
namespace ftxui::component {
|
||||
|
||||
ComponentDirection::ComponentDirection(Delegate* delegate)
|
||||
: Component(delegate), active_child_(nullptr) {}
|
||||
@@ -27,5 +26,4 @@ void ComponentDirection::Focus(Component* child) {
|
||||
active_child_ = child;
|
||||
}
|
||||
|
||||
} // namespace component
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::Component
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#include "ftxui/component/component_horizontal.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace component {
|
||||
namespace ftxui::component {
|
||||
|
||||
ComponentHorizontal::ComponentHorizontal(Delegate* delegate)
|
||||
: ComponentDirection(delegate) {}
|
||||
@@ -28,5 +27,4 @@ bool ComponentHorizontal::HandleDirection(Event event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace component
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::component
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#include "ftxui/component/component_vertical.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace component {
|
||||
namespace ftxui::component {
|
||||
|
||||
ComponentVertical::ComponentVertical(Delegate* delegate)
|
||||
: ComponentDirection(delegate) {}
|
||||
@@ -28,5 +27,4 @@ bool ComponentVertical::HandleDirection(Event event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace component
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::component
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include "ftxui/event.hpp"
|
||||
#include "ftxui/component/event.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace ftxui::component {
|
||||
|
||||
constexpr int ESC = int(27);
|
||||
|
||||
@@ -34,4 +34,4 @@ Event Event::F10{ESC, '[', '2', '1', '~'};
|
||||
Event Event::F11{ESC, '[', '2', '1', '~'}; // Same as F10 ?
|
||||
Event Event::F12{ESC, '[', '2', '4', '~'};
|
||||
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::component
|
@@ -1,8 +1,7 @@
|
||||
#include "ftxui/component/input.hpp"
|
||||
#include "ftxui/util/string.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace component {
|
||||
namespace ftxui::component {
|
||||
|
||||
Input::Input(Delegate* delegate): Component(delegate) {}
|
||||
Input::~Input() {}
|
||||
@@ -76,5 +75,4 @@ bool Input::OnEvent(Event event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace component
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::component
|
||||
|
@@ -2,8 +2,7 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
namespace ftxui {
|
||||
namespace component {
|
||||
namespace ftxui::component {
|
||||
|
||||
Menu::Menu(Delegate* delegate) : Component(delegate) {}
|
||||
|
||||
@@ -50,5 +49,4 @@ bool Menu::OnEvent(Event event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace component
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::component
|
||||
|
@@ -1,48 +1,48 @@
|
||||
#include "ftxui/screen_interactive.hpp"
|
||||
#include "ftxui/component/screen_interactive.hpp"
|
||||
|
||||
#include "ftxui/component/component.hpp"
|
||||
#include "ftxui/component/delegate.hpp"
|
||||
#include "ftxui/terminal.hpp"
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "ftxui/component/component.hpp"
|
||||
#include "ftxui/component/delegate.hpp"
|
||||
#include "ftxui/terminal.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace ftxui::component {
|
||||
|
||||
namespace {
|
||||
constexpr int ESC = 27;
|
||||
constexpr int WAT = 195;
|
||||
constexpr int WAT2 = 194;
|
||||
constexpr int WATWAIT = 91;
|
||||
constexpr int ESC = 27;
|
||||
constexpr int WAT = 195;
|
||||
constexpr int WAT2 = 194;
|
||||
constexpr int WATWAIT = 91;
|
||||
|
||||
Event GetEvent() {
|
||||
int v1 = getchar();
|
||||
if (v1 == ESC) {
|
||||
int v2 = getchar();
|
||||
int v3 = getchar();
|
||||
Event GetEvent() {
|
||||
int v1 = getchar();
|
||||
if (v1 == ESC) {
|
||||
int v2 = getchar();
|
||||
int v3 = getchar();
|
||||
|
||||
//if (v2 == WATWAIT) {
|
||||
//int v4 = getchar();
|
||||
//int v5 = getchar();
|
||||
//return Event{v1, v2, v3, v4, v5};
|
||||
//}
|
||||
return Event{v1, v2, v3};
|
||||
}
|
||||
// if (v2 == WATWAIT) {
|
||||
// int v4 = getchar();
|
||||
// int v5 = getchar();
|
||||
// return Event{v1, v2, v3, v4, v5};
|
||||
//}
|
||||
return Event{v1, v2, v3};
|
||||
}
|
||||
|
||||
if (v1 == WAT) {
|
||||
int v2 = getchar();
|
||||
return Event{v1, v2};
|
||||
}
|
||||
if (v1 == WAT) {
|
||||
int v2 = getchar();
|
||||
return Event{v1, v2};
|
||||
}
|
||||
|
||||
if (v1 == WAT2) {
|
||||
int v2 = getchar();
|
||||
return Event{v1, v2};
|
||||
}
|
||||
if (v1 == WAT2) {
|
||||
int v2 = getchar();
|
||||
return Event{v1, v2};
|
||||
}
|
||||
|
||||
return Event{v1};
|
||||
};
|
||||
return Event{v1};
|
||||
};
|
||||
}; // namespace
|
||||
|
||||
class ScreenInteractive::Delegate : public component::Delegate {
|
||||
public:
|
||||
@@ -67,7 +67,6 @@ class ScreenInteractive::Delegate : public component::Delegate {
|
||||
|
||||
void OnEvent(Event event) { component_->OnEvent(event); }
|
||||
|
||||
|
||||
std::vector<component::Delegate*> children() override {
|
||||
std::vector<component::Delegate*> ret;
|
||||
for (auto& it : child_)
|
||||
@@ -129,12 +128,14 @@ void ScreenInteractive::Loop() {
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &terminal_configuration_new);
|
||||
|
||||
Draw();
|
||||
while(!quit_) {
|
||||
while (!quit_) {
|
||||
delegate_->OnEvent(GetEvent());
|
||||
Clear();
|
||||
Draw();
|
||||
} while(!quit_);
|
||||
//std::cout << std::endl;
|
||||
}
|
||||
while (!quit_)
|
||||
;
|
||||
// std::cout << std::endl;
|
||||
|
||||
// Restore the old terminal configuration.
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &terminal_configuration_old);
|
||||
@@ -144,7 +145,7 @@ void ScreenInteractive::Draw() {
|
||||
auto document = delegate_->component()->Render();
|
||||
size_t dimx;
|
||||
size_t dimy;
|
||||
switch(dimension_) {
|
||||
switch (dimension_) {
|
||||
case Dimension::Fixed:
|
||||
break;
|
||||
case Dimension::TerminalOutput:
|
||||
@@ -162,7 +163,8 @@ void ScreenInteractive::Draw() {
|
||||
if (dimx != dimx_ || dimy != dimy_) {
|
||||
dimx_ = dimx;
|
||||
dimy_ = dimy;
|
||||
pixels_ = std::vector<std::vector<Pixel>>(dimy, std::vector<Pixel>(dimx));
|
||||
pixels_ = std::vector<std::vector<screen::Pixel>>(
|
||||
dimy, std::vector<screen::Pixel>(dimx));
|
||||
}
|
||||
|
||||
Render(*this, document.get());
|
||||
@@ -182,4 +184,4 @@ std::function<void()> ScreenInteractive::ExitLoopClosure() {
|
||||
return [this]() { quit_ = true; };
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::component.
|
@@ -1,7 +1,6 @@
|
||||
#include "ftxui/component/toggle.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace component {
|
||||
namespace ftxui::component {
|
||||
|
||||
Toggle::Toggle(Delegate* delegate) : Component(delegate) {}
|
||||
|
||||
@@ -41,5 +40,4 @@ bool Toggle::OnEvent(Event event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace component
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::component
|
||||
|
@@ -1,15 +1,14 @@
|
||||
#include "ftxui/dom/node_decorator.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
class Blink : public NodeDecorator {
|
||||
public:
|
||||
Blink(Children children) : NodeDecorator(std::move(children)) {}
|
||||
~Blink() override {}
|
||||
|
||||
void Render(Screen& screen) override {
|
||||
void Render(screen::Screen& screen) override {
|
||||
Node::Render(screen);
|
||||
for (int y = box_.top; y <= box_.bottom; ++y) {
|
||||
for (int x = box_.left; x <= box_.right; ++x) {
|
||||
@@ -23,5 +22,4 @@ std::unique_ptr<Node> blink(Child child) {
|
||||
return std::make_unique<Blink>(unpack(std::move(child)));
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::dom
|
||||
|
@@ -1,15 +1,14 @@
|
||||
#include "ftxui/dom/node_decorator.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
class Bold : public NodeDecorator {
|
||||
public:
|
||||
Bold(Children children) : NodeDecorator(std::move(children)) {}
|
||||
~Bold() override {}
|
||||
|
||||
void Render(Screen& screen) override {
|
||||
void Render(screen::Screen& screen) override {
|
||||
for (int y = box_.top; y <= box_.bottom; ++y) {
|
||||
for (int x = box_.left; x <= box_.right; ++x) {
|
||||
screen.PixelAt(x,y).bold = true;
|
||||
@@ -23,5 +22,4 @@ std::unique_ptr<Node> bold(Child child) {
|
||||
return std::make_unique<Bold>(unpack(std::move(child)));
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::dom
|
||||
|
@@ -1,15 +1,14 @@
|
||||
#include "ftxui/dom/node_decorator.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
class BgColor : public NodeDecorator {
|
||||
public:
|
||||
BgColor(Children children, Color color)
|
||||
: NodeDecorator(std::move(children)), color_(color) {}
|
||||
|
||||
void Render(Screen& screen) override {
|
||||
void Render(screen::Screen& screen) override {
|
||||
for (int y = box_.top; y <= box_.bottom; ++y) {
|
||||
for (int x = box_.left; x <= box_.right; ++x) {
|
||||
screen.PixelAt(x, y).background_color = color_;
|
||||
@@ -27,7 +26,7 @@ class FgColor : public NodeDecorator {
|
||||
: NodeDecorator(std::move(children)), color_(color) {}
|
||||
~FgColor() override {}
|
||||
|
||||
void Render(Screen& screen) override {
|
||||
void Render(screen::Screen& screen) override {
|
||||
for (int y = box_.top; y <= box_.bottom; ++y) {
|
||||
for (int x = box_.left; x <= box_.right; ++x) {
|
||||
screen.PixelAt(x, y).foreground_color = color_;
|
||||
@@ -59,5 +58,4 @@ Decorator bgcolor(Color c) {
|
||||
};
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::dom
|
||||
|
@@ -1,8 +1,7 @@
|
||||
#include "ftxui/dom/node.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
std::unique_ptr<Node> hcenter(Element child) {
|
||||
return hbox(filler(), std::move(child), filler());
|
||||
@@ -16,5 +15,4 @@ std::unique_ptr<Node> center(Element child) {
|
||||
return hcenter(vcenter(std::move(child)));
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::dom
|
||||
|
@@ -1,8 +1,7 @@
|
||||
#include "ftxui/dom/node.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
class DBox : public Node {
|
||||
public:
|
||||
@@ -33,5 +32,4 @@ std::unique_ptr<Node> dbox(Children children) {
|
||||
return std::make_unique<DBox>(std::move(children));
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::dom
|
||||
|
@@ -1,8 +1,9 @@
|
||||
#include "ftxui/dom/node_decorator.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
using ftxui::screen::Screen;
|
||||
|
||||
class Dim : public NodeDecorator {
|
||||
public:
|
||||
@@ -23,5 +24,4 @@ std::unique_ptr<Node> dim(Child child) {
|
||||
return std::make_unique<Dim>(unpack(std::move(child)));
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::dom
|
||||
|
@@ -1,8 +1,7 @@
|
||||
#include "ftxui/dom/node.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
class Flex : public Node {
|
||||
public:
|
||||
@@ -35,5 +34,4 @@ std::unique_ptr<Node> flex(Element child) {
|
||||
return std::make_unique<Flex>(std::move(child));
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::dom
|
||||
|
@@ -1,8 +1,9 @@
|
||||
#include "ftxui/dom/node.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
using namespace ftxui::screen;
|
||||
|
||||
static wchar_t charset[] = L"┌┐└┘─│┬┴┤├";
|
||||
|
||||
@@ -94,5 +95,4 @@ Decorator boxed() {
|
||||
};
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::dom
|
||||
|
@@ -1,8 +1,9 @@
|
||||
#include "ftxui/dom/node.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
using namespace ftxui::screen;
|
||||
|
||||
static wchar_t charset[] = L" ▏▎▍▌▋▊▉█";
|
||||
|
||||
@@ -35,5 +36,4 @@ std::unique_ptr<Node> gauge(float progress) {
|
||||
return std::make_unique<Gauge>(progress);
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::dom
|
||||
|
@@ -1,9 +1,9 @@
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
using namespace ftxui::screen;
|
||||
using namespace ftxui::dom;
|
||||
|
||||
TEST(GaugeTest, zero) {
|
||||
auto root = gauge(0);
|
||||
@@ -29,6 +29,3 @@ TEST(GaugeTest, one) {
|
||||
|
||||
EXPECT_EQ("███████████", screen.ToString());
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace ftxui
|
||||
|
@@ -1,8 +1,7 @@
|
||||
#include "ftxui/dom/node.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
class HBox : public Node {
|
||||
public:
|
||||
@@ -64,5 +63,4 @@ std::unique_ptr<Node> hbox(Children children) {
|
||||
return std::make_unique<HBox>(std::move(children));
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::dom
|
||||
|
@@ -1,9 +1,9 @@
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
using namespace ftxui::screen;
|
||||
using namespace ftxui::dom;
|
||||
|
||||
TEST(HBoxTest, ScreenSmaller1) {
|
||||
auto root = hbox(
|
||||
@@ -118,6 +118,3 @@ TEST(HBoxTest, ScreenBigger2Flex) {
|
||||
|
||||
EXPECT_EQ("text_1 text_2", screen.ToString());
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
|
@@ -1,8 +1,9 @@
|
||||
#include "ftxui/dom/node_decorator.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
using ftxui::screen::Screen;
|
||||
|
||||
class Inverted : public NodeDecorator {
|
||||
public:
|
||||
@@ -23,5 +24,4 @@ std::unique_ptr<Node> inverted(Child child) {
|
||||
return std::make_unique<Inverted>(unpack(std::move(child)));
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::dom
|
||||
|
@@ -1,7 +1,8 @@
|
||||
#include "ftxui/dom/node.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
using ftxui::screen::Screen;
|
||||
|
||||
Node::Node() {}
|
||||
Node::Node(std::vector<std::unique_ptr<Node>> children)
|
||||
@@ -39,5 +40,4 @@ void Render(Screen& screen, Node* node) {
|
||||
node->Render(screen);
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::dom
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#include "ftxui/dom/node_decorator.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
void NodeDecorator::ComputeRequirement() {
|
||||
Node::ComputeRequirement();
|
||||
@@ -13,5 +12,4 @@ void NodeDecorator::SetBox(Box box) {
|
||||
children[0]->SetBox(box);
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::dom
|
||||
|
@@ -4,8 +4,7 @@
|
||||
#include "ftxui/dom/node.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
// Helper class.
|
||||
class NodeDecorator : public Node {
|
||||
@@ -16,7 +15,6 @@ class NodeDecorator : public Node {
|
||||
void SetBox(Box box) override;
|
||||
};
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::dom
|
||||
|
||||
#endif /* end of include guard: FTXUI_DOM_NODE_DECORATOR_H_ */
|
||||
|
@@ -1,7 +1,8 @@
|
||||
#include "ftxui/dom/node.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
using ftxui::screen::Screen;
|
||||
|
||||
class Separator : public Node {
|
||||
public:
|
||||
@@ -34,5 +35,4 @@ std::unique_ptr<Node> separator() {
|
||||
return std::make_unique<Separator>();
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::dom
|
||||
|
@@ -1,7 +1,8 @@
|
||||
#include "ftxui/dom/node.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
using ftxui::screen::Screen;
|
||||
|
||||
class Text : public Node {
|
||||
public:
|
||||
@@ -33,5 +34,4 @@ std::unique_ptr<Node> text(std::wstring text) {
|
||||
return std::make_unique<Text>(text);
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::dom
|
||||
|
@@ -1,9 +1,9 @@
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
using namespace ftxui::screen;
|
||||
using namespace ftxui::dom;
|
||||
|
||||
TEST(TextTest, ScreenHeightSmaller) {
|
||||
auto element = text(L"test");
|
||||
@@ -44,6 +44,3 @@ TEST(TextTest, ScreenBigger2) {
|
||||
|
||||
EXPECT_EQ("test \n ", screen.ToString());
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
|
@@ -1,8 +1,9 @@
|
||||
#include "ftxui/dom/node_decorator.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
using ftxui::screen::Screen;
|
||||
|
||||
class Underlined : public NodeDecorator {
|
||||
public:
|
||||
@@ -23,5 +24,4 @@ std::unique_ptr<Node> underlined(Child child) {
|
||||
return std::make_unique<Underlined>(unpack(std::move(child)));
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::dom
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
Element nothing(Element element) {
|
||||
return std::move(element);
|
||||
@@ -24,5 +23,4 @@ Element operator|(Element e, Decorator d) {
|
||||
return d(std::move(e));
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::dom
|
||||
|
@@ -1,8 +1,7 @@
|
||||
#include "ftxui/dom/node.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
namespace ftxui::dom {
|
||||
|
||||
class VBox : public Node {
|
||||
public:
|
||||
@@ -64,5 +63,4 @@ std::unique_ptr<Node> vbox(Children children) {
|
||||
return std::make_unique<VBox>(std::move(children));
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::dom
|
||||
|
@@ -1,9 +1,9 @@
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
using namespace ftxui::screen;
|
||||
using namespace ftxui::dom;
|
||||
|
||||
TEST(VBoxTest, ScreenSmaller1) {
|
||||
auto root = vbox(text(L"text_1"), text(L"text_2"));
|
||||
@@ -66,6 +66,3 @@ TEST(VBoxTest, ScreenBigger2Flex) {
|
||||
|
||||
EXPECT_EQ("text_1\n \n \ntext_2", screen.ToString());
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
|
@@ -1,26 +1,46 @@
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "ftxui/dom/node.hpp"
|
||||
#include "ftxui/terminal.hpp"
|
||||
#include "ftxui/util/string.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace ftxui {
|
||||
namespace ftxui::screen {
|
||||
|
||||
static const wchar_t* BOLD_SET = L"\e[1m";
|
||||
static const wchar_t* BOLD_RESET = L"\e[22m"; // Can't use 21 here.
|
||||
|
||||
static const wchar_t* DIM_SET = L"\e[2m";
|
||||
static const wchar_t* DIM_RESET = L"\e[22m";
|
||||
|
||||
static const wchar_t* UNDERLINED_SET = L"\e[4m";
|
||||
static const wchar_t* UNDERLINED_RESET = L"\e[24m";
|
||||
|
||||
static const wchar_t* BLINK_SET = L"\e[5m";
|
||||
static const wchar_t* BLINK_RESET = L"\e[25m";
|
||||
|
||||
static const wchar_t* INVERTED_SET = L"\e[7m";
|
||||
static const wchar_t* INVERTED_RESET = L"\e[27m";
|
||||
|
||||
Screen::Screen(size_t dimx, size_t dimy)
|
||||
: dimx_(dimx), dimy_(dimy), pixels_(dimy, std::vector<Pixel>(dimx)) {}
|
||||
|
||||
void UpdatePixelStyle(std::wstringstream& ss, Pixel& previous, Pixel& next) {
|
||||
if (next.bold != previous.bold)
|
||||
ss << (next.bold ? L"\e[1m" : L"\e[22m"); // Can't use 21 here.
|
||||
ss << (next.bold ? BOLD_SET : BOLD_RESET);
|
||||
|
||||
if (next.dim != previous.dim)
|
||||
ss << (next.dim ? L"\e[2m" : L"\e[22m");
|
||||
ss << (next.dim ? DIM_SET : DIM_RESET);
|
||||
|
||||
if (next.underlined != previous.underlined)
|
||||
ss << (next.underlined ? L"\e[4m" : L"\e[24m");
|
||||
ss << (next.underlined ? UNDERLINED_SET : UNDERLINED_RESET);
|
||||
|
||||
if (next.blink != previous.blink)
|
||||
ss << (next.blink ? L"\e[5m" : L"\e[25m");
|
||||
ss << (next.blink ? BLINK_SET : BLINK_RESET);
|
||||
|
||||
if (next.inverted != previous.inverted)
|
||||
ss << (next.inverted ? L"\e[7m" : L"\e[27m");
|
||||
ss << (next.inverted ? INVERTED_SET : INVERTED_RESET);
|
||||
|
||||
if (next.foreground_color != previous.foreground_color ||
|
||||
next.background_color != previous.background_color) {
|
||||
ss << L"\e[" + to_wstring(std::to_string((uint8_t)next.foreground_color)) + L"m";
|
||||
@@ -84,4 +104,4 @@ void Screen::Clear() {
|
||||
std::vector<Pixel>(dimx_, Pixel()));
|
||||
}
|
||||
|
||||
}; // namespace ftxui
|
||||
}; // namespace ftxui::screen
|
Reference in New Issue
Block a user