Refactor directory structure.

The goal is to increase the separation in between:

 * ftxui::screen
 * ftxui::dom
 * ftxui::component
This commit is contained in:
Arthur Sonzogni 2019-01-06 17:10:35 +01:00
parent 1d29645cf5
commit 5887114793
70 changed files with 324 additions and 361 deletions

View File

@ -2,18 +2,17 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include "ftxui/screen_interactive.hpp"
#include "ftxui/component/input.hpp"
#include "ftxui/component/component_vertical.hpp" #include "ftxui/component/component_vertical.hpp"
#include "ftxui/component/input.hpp"
#include "ftxui/component/screen_interactive.hpp"
#include "ftxui/util/string.hpp" #include "ftxui/util/string.hpp"
using namespace ftxui::component; using namespace ftxui::component;
using namespace ftxui::dom; using namespace ftxui::dom;
using namespace ftxui;
class MyComponent : ComponentVertical { class MyComponent : ComponentVertical {
public: public:
MyComponent(ftxui::component::Delegate* delegate) MyComponent(Delegate* delegate)
: ComponentVertical(delegate), : ComponentVertical(delegate),
input_1(delegate->NewChild()), input_1(delegate->NewChild()),
input_2(delegate->NewChild()), input_2(delegate->NewChild()),
@ -45,7 +44,7 @@ class MyComponent : ComponentVertical {
}; };
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
auto screen = ftxui::ScreenInteractive::TerminalOutput(); auto screen = ScreenInteractive::TerminalOutput();
MyComponent component(screen.delegate()); MyComponent component(screen.delegate());
component.on_enter = screen.ExitLoopClosure(); component.on_enter = screen.ExitLoopClosure();
screen.Loop(); screen.Loop();

View File

@ -2,18 +2,15 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include "ftxui/screen_interactive.hpp"
#include "ftxui/component/menu.hpp" #include "ftxui/component/menu.hpp"
#include "ftxui/component/screen_interactive.hpp"
int main(int argc, const char *argv[]) int main(int argc, const char* argv[]) {
{ using namespace ftxui::component;
auto screen = ftxui::ScreenInteractive::FixedSize(30, 3); using namespace ftxui::screen;
ftxui::component::Menu menu(screen.delegate()); auto screen = ScreenInteractive::FixedSize(30, 3);
menu.entries = { Menu menu(screen.delegate());
L"entry 1", menu.entries = {L"entry 1", L"entry 2", L"entry 3"};
L"entry 2",
L"entry 3"
};
menu.selected = 0; menu.selected = 0;
menu.on_enter = screen.ExitLoopClosure(); menu.on_enter = screen.ExitLoopClosure();

View File

@ -2,10 +2,10 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include "ftxui/screen_interactive.hpp"
#include "ftxui/component/menu.hpp"
#include "ftxui/component/component_horizontal.hpp" #include "ftxui/component/component_horizontal.hpp"
#include "ftxui/component/component_vertical.hpp" #include "ftxui/component/component_vertical.hpp"
#include "ftxui/component/menu.hpp"
#include "ftxui/component/screen_interactive.hpp"
#include "ftxui/util/string.hpp" #include "ftxui/util/string.hpp"
using namespace ftxui::component; using namespace ftxui::component;
@ -13,7 +13,7 @@ using namespace ftxui::dom;
class MyComponent : ComponentHorizontal { class MyComponent : ComponentHorizontal {
public: public:
MyComponent(ftxui::component::Delegate* delegate) MyComponent(Delegate* delegate)
: ComponentHorizontal(delegate), : ComponentHorizontal(delegate),
left_menu(delegate->NewChild()), left_menu(delegate->NewChild()),
right_menu(delegate->NewChild()) { right_menu(delegate->NewChild()) {
@ -66,7 +66,7 @@ class MyComponent : ComponentHorizontal {
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
auto screen = ftxui::ScreenInteractive::TerminalOutput(); auto screen = ScreenInteractive::TerminalOutput();
MyComponent component(screen.delegate()); MyComponent component(screen.delegate());
component.on_enter = screen.ExitLoopClosure(); component.on_enter = screen.ExitLoopClosure();
screen.Loop(); screen.Loop();

View File

@ -3,16 +3,15 @@
#include "ftxui/component/component_horizontal.hpp" #include "ftxui/component/component_horizontal.hpp"
#include "ftxui/component/menu.hpp" #include "ftxui/component/menu.hpp"
#include "ftxui/screen_interactive.hpp" #include "ftxui/component/screen_interactive.hpp"
#include "ftxui/util/string.hpp" #include "ftxui/util/string.hpp"
using namespace ftxui;
using namespace ftxui::component; using namespace ftxui::component;
using namespace ftxui::dom; using namespace ftxui::dom;
class MyComponent : ComponentHorizontal { class MyComponent : ComponentHorizontal {
public: public:
MyComponent(ftxui::component::Delegate* delegate) MyComponent(Delegate* delegate)
: ComponentHorizontal(delegate), : ComponentHorizontal(delegate),
menu_1(delegate->NewChild()), menu_1(delegate->NewChild()),
menu_2(delegate->NewChild()), menu_2(delegate->NewChild()),
@ -76,8 +75,7 @@ class MyComponent : ComponentHorizontal {
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
//auto screen = ftxui::ScreenInteractive::TerminalOutput(); auto screen = ScreenInteractive::TerminalOutput();
auto screen = ftxui::ScreenInteractive::Fullscreen();
MyComponent component(screen.delegate()); MyComponent component(screen.delegate());
component.on_enter = screen.ExitLoopClosure(); component.on_enter = screen.ExitLoopClosure();
screen.Loop(); screen.Loop();

View File

@ -2,18 +2,17 @@
#include <thread> #include <thread>
#include "ftxui/component/component_vertical.hpp" #include "ftxui/component/component_vertical.hpp"
#include "ftxui/component/toggle.hpp"
#include "ftxui/component/menu.hpp" #include "ftxui/component/menu.hpp"
#include "ftxui/screen_interactive.hpp" #include "ftxui/component/screen_interactive.hpp"
#include "ftxui/component/toggle.hpp"
#include "ftxui/util/string.hpp" #include "ftxui/util/string.hpp"
using namespace ftxui;
using namespace ftxui::component; using namespace ftxui::component;
using namespace ftxui::dom; using namespace ftxui::dom;
class MyComponent : ComponentVertical { class MyComponent : ComponentVertical {
public: public:
MyComponent(ftxui::component::Delegate* delegate) MyComponent(Delegate* delegate)
: ComponentVertical(delegate), : ComponentVertical(delegate),
toggle(delegate->NewChild()), toggle(delegate->NewChild()),
menu(delegate->NewChild()) { menu(delegate->NewChild()) {
@ -39,7 +38,7 @@ class MyComponent : ComponentVertical {
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
auto screen = ftxui::ScreenInteractive::TerminalOutput(); auto screen = ScreenInteractive::TerminalOutput();
MyComponent component(screen.delegate()); MyComponent component(screen.delegate());
component.on_enter = screen.ExitLoopClosure(); component.on_enter = screen.ExitLoopClosure();
screen.Loop(); screen.Loop();

View File

@ -2,19 +2,18 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include "ftxui/screen_interactive.hpp"
#include "ftxui/component/toggle.hpp"
#include "ftxui/component/component_horizontal.hpp" #include "ftxui/component/component_horizontal.hpp"
#include "ftxui/component/component_vertical.hpp" #include "ftxui/component/component_vertical.hpp"
#include "ftxui/component/screen_interactive.hpp"
#include "ftxui/component/toggle.hpp"
#include "ftxui/util/string.hpp" #include "ftxui/util/string.hpp"
using namespace ftxui;
using namespace ftxui::component; using namespace ftxui::component;
using namespace ftxui::dom; using namespace ftxui::dom;
class MyComponent : ComponentVertical { class MyComponent : ComponentVertical {
public: public:
MyComponent(ftxui::component::Delegate* delegate) MyComponent(Delegate* delegate)
: ComponentVertical(delegate), : ComponentVertical(delegate),
toggle_1(delegate->NewChild()), toggle_1(delegate->NewChild()),
toggle_2(delegate->NewChild()), toggle_2(delegate->NewChild()),
@ -62,7 +61,7 @@ class MyComponent : ComponentVertical {
}; };
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
auto screen = ftxui::ScreenInteractive::TerminalOutput(); auto screen = ScreenInteractive::TerminalOutput();
MyComponent component(screen.delegate()); MyComponent component(screen.delegate());
component.on_enter = screen.ExitLoopClosure(); component.on_enter = screen.ExitLoopClosure();
screen.Loop(); screen.Loop();

View File

@ -1,10 +1,10 @@
#include "ftxui/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui; using namespace ftxui::screen;
using namespace ftxui::dom; using namespace ftxui::dom;
auto document = auto document =
hbox( hbox(
@ -12,7 +12,7 @@ int main(int argc, const char *argv[])
text(L"blink") | blink, text(L"blink") | blink,
text(L". Do you like it?") text(L". Do you like it?")
); );
auto screen = ftxui::Screen::TerminalOutput(document); auto screen = Screen::TerminalOutput(document);
Render(screen, document.get()); Render(screen, document.get());
std::cout << screen.ToString(); std::cout << screen.ToString();

View File

@ -1,10 +1,10 @@
#include "ftxui/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui; using namespace ftxui::screen;
using namespace ftxui::dom; using namespace ftxui::dom;
auto document = auto document =
hbox( hbox(
@ -12,7 +12,7 @@ int main(int argc, const char *argv[])
text(L"bold") | bold, text(L"bold") | bold,
text(L". Do you like it?") text(L". Do you like it?")
); );
auto screen = ftxui::Screen::TerminalOutput(document); auto screen = Screen::TerminalOutput(document);
Render(screen, document.get()); Render(screen, document.get());
std::cout << screen.ToString(); std::cout << screen.ToString();

View File

@ -1,10 +1,10 @@
#include "ftxui/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui; using namespace ftxui::screen;
using namespace ftxui::dom; using namespace ftxui::dom;
auto document = auto document =
hbox( hbox(
@ -49,7 +49,7 @@ int main(int argc, const char *argv[])
filler() filler()
); );
auto screen = ftxui::Screen::TerminalOutput(document); auto screen = Screen::TerminalOutput(document);
Render(screen, document.get()); Render(screen, document.get());
std::cout << screen.ToString(); std::cout << screen.ToString();

View File

@ -1,10 +1,11 @@
#include "ftxui/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui::dom; using namespace ftxui::dom;
using namespace ftxui::screen;
auto document = auto document =
dbox( dbox(
frame( frame(
@ -22,7 +23,7 @@ int main(int argc, const char *argv[])
) )
) )
); );
auto screen = ftxui::Screen::TerminalOutput(document); auto screen = Screen::TerminalOutput(document);
Render(screen, document.get()); Render(screen, document.get());
std::cout << screen.ToString(); std::cout << screen.ToString();

View File

@ -1,10 +1,10 @@
#include "ftxui/screen.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/screen/screen.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui; using namespace ftxui::screen;
using namespace ftxui::dom; using namespace ftxui::dom;
auto document = auto document =
hbox( hbox(
@ -12,7 +12,7 @@ int main(int argc, const char *argv[])
text(L"dim") | dim, text(L"dim") | dim,
text(L". Do you like it?") text(L". Do you like it?")
); );
auto screen = ftxui::Screen::TerminalOutput(document); auto screen = Screen::TerminalOutput(document);
Render(screen, document.get()); Render(screen, document.get());
std::cout << screen.ToString(); std::cout << screen.ToString();

View File

@ -2,12 +2,13 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include "ftxui/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui::dom; using namespace ftxui::dom;
using namespace ftxui::screen;
auto document = auto document =
hbox( hbox(
window(text(L" main frame ") | hcenter, window(text(L" main frame ") | hcenter,
@ -43,7 +44,7 @@ int main(int argc, const char *argv[])
), ),
filler() filler()
); );
auto screen = ftxui::Screen::TerminalOutput(document); auto screen = Screen::TerminalOutput(document);
Render(screen, document.get()); Render(screen, document.get());
std::cout << screen.ToString() << std::endl; std::cout << screen.ToString() << std::endl;
} }

View File

@ -2,26 +2,30 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include "ftxui/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui::dom;
using namespace ftxui::screen;
using namespace std::chrono_literals;
std::string reset_position;
for(float percentage = 0; percentage <= 1.0; percentage+=0.002) { for(float percentage = 0; percentage <= 1.0; percentage+=0.002) {
std::wstring data_downloaded = std::wstring data_downloaded =
std::to_wstring(int(percentage * 5000)) + L"/5000"; std::to_wstring(int(percentage * 5000)) + L"/5000";
using namespace ftxui::dom;
auto document = auto document =
hbox( hbox(
text(L"downloading:"), text(L"downloading:"),
gauge(percentage) | flex, gauge(percentage) | flex,
text(L" " + data_downloaded) text(L" " + data_downloaded)
); );
auto screen = ftxui::Screen(100, 1); auto screen = Screen(100, 1);
Render(screen, document.get()); Render(screen, document.get());
std::cout << '\r' << screen.ToString() << std::flush; std::cout << reset_position << screen.ToString() << std::flush;
reset_position = screen.ResetPosition();
using namespace std::chrono_literals;
std::this_thread::sleep_for(0.01s); std::this_thread::sleep_for(0.01s);
} }
std::cout << std::endl; std::cout << std::endl;

View File

@ -1,10 +1,10 @@
#include "ftxui/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui; using namespace ftxui::screen;
using namespace ftxui::dom; using namespace ftxui::dom;
auto document = auto document =
hbox( hbox(
@ -12,7 +12,7 @@ int main(int argc, const char *argv[])
text(L"inverted") | inverted, text(L"inverted") | inverted,
text(L". Do you like it?") text(L". Do you like it?")
); );
auto screen = ftxui::Screen::TerminalOutput(document); auto screen = Screen::TerminalOutput(document);
Render(screen, document.get()); Render(screen, document.get());
std::cout << screen.ToString(); std::cout << screen.ToString();

View File

@ -2,17 +2,17 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include "ftxui/screen.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/screen/screen.hpp"
#include "ftxui/util/string.hpp" #include "ftxui/util/string.hpp"
#include <list> #include <list>
#include <vector> #include <vector>
using namespace ftxui;
using namespace ftxui::dom;
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui::screen;
using namespace ftxui::dom;
struct Task { struct Task {
std::wstring name; std::wstring name;
int number_of_threads; int number_of_threads;
@ -119,7 +119,7 @@ int main(int argc, const char *argv[])
// Draw. // Draw.
auto document = render(); auto document = render();
auto screen = ftxui::Screen::TerminalOutput(document); auto screen = Screen::TerminalOutput(document);
Render(screen, document.get()); Render(screen, document.get());
std::cout << reset_position << screen.ToString() << std::flush; std::cout << reset_position << screen.ToString() << std::flush;
reset_position = screen.ResetPosition(); reset_position = screen.ResetPosition();

View File

@ -1,10 +1,11 @@
#include "ftxui/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui::dom; using namespace ftxui::dom;
using namespace ftxui::screen;
auto document = auto document =
hbox( hbox(
text(L"left-column"), text(L"left-column"),
@ -15,7 +16,7 @@ int main(int argc, const char *argv[])
center(text(L"bottom-column")) center(text(L"bottom-column"))
)) ))
); );
auto screen = ftxui::Screen::TerminalFullscreen(); auto screen = Screen::TerminalFullscreen();
Render(screen, document.get()); Render(screen, document.get());
std::cout << screen.ToString(); std::cout << screen.ToString();

View File

@ -1,10 +1,10 @@
#include "ftxui/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui; using namespace ftxui::screen;
using namespace ftxui::dom; using namespace ftxui::dom;
auto document = auto document =
hbox( hbox(
@ -17,7 +17,7 @@ int main(int argc, const char *argv[])
text(L"color") | color(Color::Blue) , text(L" ") , text(L"color") | color(Color::Blue) , text(L" ") ,
text(L"bgcolor") | bgcolor(Color::Blue) text(L"bgcolor") | bgcolor(Color::Blue)
); );
auto screen = ftxui::Screen::TerminalOutput(document); auto screen = Screen::TerminalOutput(document);
Render(screen, document.get()); Render(screen, document.get());
std::cout << screen.ToString(); std::cout << screen.ToString();

View File

@ -1,10 +1,10 @@
#include "ftxui/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui; using namespace ftxui::screen;
using namespace ftxui::dom; using namespace ftxui::dom;
auto document = auto document =
hbox( hbox(
@ -12,7 +12,7 @@ int main(int argc, const char *argv[])
text(L"underlined") | underlined, text(L"underlined") | underlined,
text(L". Do you like it?") text(L". Do you like it?")
); );
auto screen = ftxui::Screen::TerminalOutput(document); auto screen = Screen::TerminalOutput(document);
Render(screen, document.get()); Render(screen, document.get());
std::cout << screen.ToString(); std::cout << screen.ToString();

View File

@ -1,9 +1,11 @@
#include "ftxui/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui::screen;
using namespace ftxui::dom; using namespace ftxui::dom;
auto document = auto document =
vbox( vbox(
@ -27,7 +29,7 @@ int main(int argc, const char *argv[])
text(L"south-east") text(L"south-east")
) )
); );
auto screen = ftxui::Screen::TerminalFullscreen(); auto screen = Screen::TerminalFullscreen();
Render(screen, document.get()); Render(screen, document.get());
std::cout << screen.ToString(); std::cout << screen.ToString();

View File

@ -2,26 +2,28 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include "ftxui/screen_interactive.hpp"
#include "ftxui/component/component.hpp" #include "ftxui/component/component.hpp"
#include "ftxui/component/screen_interactive.hpp"
#include "ftxui/util/string.hpp" #include "ftxui/util/string.hpp"
class DrawKey : public ftxui::component::Component { using namespace ftxui::component;
class DrawKey : public Component {
public: public:
DrawKey(ftxui::component::Delegate* delegate) DrawKey(Delegate* delegate)
: ftxui::component::Component(delegate) {} : Component(delegate) {}
ftxui::dom::Element Render() override { ftxui::dom::Element Render() override {
using namespace ftxui::dom; using namespace ftxui::dom;
Children children; Children children;
for (size_t i = std::max(0, (int)keys.size() - 10); i < keys.size(); ++i) { for (size_t i = std::max(0, (int)keys.size() - 10); i < keys.size(); ++i) {
std::string code = ""; std::string code = "";
for(size_t j = 0; j<5; ++j) for (size_t j = 0; j < 5; ++j)
code += " " + std::to_string(keys[i].values[j]); code += " " + std::to_string(keys[i].values[j]);
try { try {
std::string line = code + " -> " + std::to_string(keys[i].values[0]) + " (" + std::string line = code + " -> " + std::to_string(keys[i].values[0]) +
char(keys[i].values[0]) + ")"; " (" + char(keys[i].values[0]) + ")";
children.push_back(text(to_wstring(line))); children.push_back(text(to_wstring(line)));
} catch (...) { } catch (...) {
std::string line = std::string line =
@ -32,17 +34,17 @@ class DrawKey : public ftxui::component::Component {
return vbox(std::move(children)); return vbox(std::move(children));
} }
bool OnEvent(ftxui::Event event) override { bool OnEvent(Event event) override {
keys.push_back(event); keys.push_back(event);
return true; return true;
} }
private: private:
std::vector<ftxui::Event> keys; std::vector<Event> keys;
}; };
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
auto screen = ftxui::ScreenInteractive::FixedSize(80,10); auto screen = ScreenInteractive::FixedSize(80, 10);
DrawKey draw_key(screen.delegate()); DrawKey draw_key(screen.delegate());
screen.Loop(); screen.Loop();
} }

View File

@ -5,8 +5,10 @@ add_library(ftxui
src/ftxui/component/component_direction.cpp src/ftxui/component/component_direction.cpp
src/ftxui/component/component_horizontal.cpp src/ftxui/component/component_horizontal.cpp
src/ftxui/component/component_vertical.cpp src/ftxui/component/component_vertical.cpp
src/ftxui/component/event.cpp
src/ftxui/component/input.cpp src/ftxui/component/input.cpp
src/ftxui/component/menu.cpp src/ftxui/component/menu.cpp
src/ftxui/component/screen_interactive.cpp
src/ftxui/component/toggle.cpp src/ftxui/component/toggle.cpp
src/ftxui/dom/blink.cpp src/ftxui/dom/blink.cpp
src/ftxui/dom/bold.cpp src/ftxui/dom/bold.cpp
@ -26,9 +28,7 @@ add_library(ftxui
src/ftxui/dom/underlined.cpp src/ftxui/dom/underlined.cpp
src/ftxui/dom/util.cpp src/ftxui/dom/util.cpp
src/ftxui/dom/vbox.cpp src/ftxui/dom/vbox.cpp
src/ftxui/event.cpp src/ftxui/screen/screen.cpp
src/ftxui/screen.cpp
src/ftxui/screen_interactive.cpp
src/ftxui/terminal.cpp src/ftxui/terminal.cpp
src/ftxui/util/string.cpp src/ftxui/util/string.cpp
) )

View File

@ -1,11 +0,0 @@
#ifndef FTX_UI_CORE_BOX
#define FTX_UI_CORE_BOX
struct Box {
int left;
int right;
int top;
int bottom;
};
#endif /* end of include guard: FTX_UI_CORE_BOX */

View File

@ -2,11 +2,10 @@
#define FTXUI_COMPONENT_COMPONENT_HPP #define FTXUI_COMPONENT_COMPONENT_HPP
#include "ftxui/component/delegate.hpp" #include "ftxui/component/delegate.hpp"
#include "ftxui/component/event.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/event.hpp"
namespace ftxui { namespace ftxui::component {
namespace component {
class Delegate; class Delegate;
class Focus; class Focus;
@ -39,7 +38,6 @@ class Component {
Delegate* delegate_; Delegate* delegate_;
}; };
} // namespace component } // namespace ftxui::component
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_HPP */ #endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_HPP */

View File

@ -3,8 +3,7 @@
#include "ftxui/component/component_direction.hpp" #include "ftxui/component/component_direction.hpp"
namespace ftxui { namespace ftxui::component {
namespace component {
// A component where focus and events are automatically handled for you. // A component where focus and events are automatically handled for you.
// It assumes its children are put in the horizontal direction. // It assumes its children are put in the horizontal direction.
@ -14,7 +13,6 @@ class ComponentHorizontal : public ComponentDirection {
bool HandleDirection(Event) override; bool HandleDirection(Event) override;
}; };
} // namespace component } // namespace ftxui::component
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_HORIZONTAL_H_ */ #endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_HORIZONTAL_H_ */

View File

@ -3,8 +3,7 @@
#include "ftxui/component/component_direction.hpp" #include "ftxui/component/component_direction.hpp"
namespace ftxui { namespace ftxui::component {
namespace component {
// A component where focus and events are automatically handled for you. // A component where focus and events are automatically handled for you.
// It assumes its children are put in the vertical direction. // It assumes its children are put in the vertical direction.
@ -14,7 +13,6 @@ class ComponentVertical : public ComponentDirection {
bool HandleDirection(Event) override; bool HandleDirection(Event) override;
}; };
} // namespace component } // namespace ftxui::component
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_VERTICAL_H_ */ #endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_VERTICAL_H_ */

View File

@ -3,8 +3,7 @@
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
namespace ftxui { namespace ftxui::component {
namespace component {
class Component; class Component;
@ -28,7 +27,6 @@ class Delegate {
virtual Delegate* Root() = 0; virtual Delegate* Root() = 0;
}; };
} // namespace component } // namespace ftxui::component
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_DELEGATE_HPP */ #endif /* end of include guard: FTXUI_COMPONENT_DELEGATE_HPP */

View File

@ -1,10 +1,10 @@
#ifndef FTXUI_EVENT_H_ #ifndef FTXUI_COMPONENT_EVENT_HPP
#define FTXUI_EVENT_H_ #define FTXUI_COMPONENT_EVENT_HPP
#include <vector> #include <vector>
#include <array> #include <array>
namespace ftxui { namespace ftxui::component {
struct Event{ struct Event{
public: public:
@ -31,7 +31,7 @@ struct Event{
}; };
} // namespace ftxui } // namespace ftxui::component
#endif /* end of include guard: FTXUI_EVENT_H_ */ #endif /* end of include guard: FTXUI_COMPONENT_EVENT_HPP */

View File

@ -4,8 +4,7 @@
#include "ftxui/component/component.hpp" #include "ftxui/component/component.hpp"
#include <functional> #include <functional>
namespace ftxui { namespace ftxui::component {
namespace component {
class Input : public Component { class Input : public Component {
public: public:
@ -29,7 +28,6 @@ class Input : public Component {
int cursor_position = 0; int cursor_position = 0;
}; };
} // namespace component } // namespace ftxui::component
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_INPUT_H_ */ #endif /* end of include guard: FTXUI_COMPONENT_INPUT_H_ */

View File

@ -5,8 +5,7 @@
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include <functional> #include <functional>
namespace ftxui { namespace ftxui::component {
namespace component {
class Menu : public Component { class Menu : public Component {
public: public:
@ -30,7 +29,6 @@ class Menu : public Component {
bool OnEvent(Event) override; bool OnEvent(Event) override;
}; };
} // namespace component } // namespace ftxui::Component
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_MENU */ #endif /* end of include guard: FTXUI_COMPONENT_MENU */

View File

@ -1,18 +1,16 @@
#ifndef FTXUI_SCREEN_INTERACTIVE #ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
#define FTXUI_SCREEN_INTERACTIVE #define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
#include "ftxui/screen.hpp" #include "ftxui/screen/screen.hpp"
#include <functional> #include <functional>
#include <memory> #include <memory>
namespace ftxui { namespace ftxui::component {
namespace component { class Delegate;
class Delegate; class Component;
class Component;
} // namespace component
class ScreenInteractive : public Screen { class ScreenInteractive : public ftxui::screen::Screen {
public: public:
static ScreenInteractive FixedSize(size_t dimx, size_t dimy); static ScreenInteractive FixedSize(size_t dimx, size_t dimy);
static ScreenInteractive Fullscreen(); static ScreenInteractive Fullscreen();
@ -21,15 +19,15 @@ class ScreenInteractive : public Screen {
~ScreenInteractive(); ~ScreenInteractive();
component::Delegate* delegate(); component::Delegate* delegate();
void Loop(); void Loop();
std::function<void()> ExitLoopClosure(); std::function<void()> ExitLoopClosure();
private: private:
class Delegate; class Delegate;
std::unique_ptr<Delegate> delegate_; std::unique_ptr<Delegate> delegate_;
void Clear(); void Clear();
void Draw(); void Draw();
bool quit_ = false; bool quit_ = false;
enum class Dimension { enum class Dimension {
Fixed, Fixed,
@ -41,6 +39,6 @@ class ScreenInteractive : public Screen {
ScreenInteractive(size_t dimx, size_t dimy, Dimension dimension); ScreenInteractive(size_t dimx, size_t dimy, Dimension dimension);
}; };
} // namespace ftxui } // namespace ftxui::component
#endif /* end of include guard: FTXUI_SCREEN_INTERACTIVE */ #endif /* end of include guard: FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP */

View File

@ -5,8 +5,7 @@
#include <functional> #include <functional>
#include <string> #include <string>
namespace ftxui { namespace ftxui::component {
namespace component {
class Toggle : public Component { class Toggle : public Component {
public: public:
@ -25,7 +24,6 @@ class Toggle : public Component {
bool OnEvent(Event) override; bool OnEvent(Event) override;
}; };
} // namespace component } // namespace ftxui::Component
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_TOGGLE_H_ */ #endif /* end of include guard: FTXUI_COMPONENT_TOGGLE_H_ */

View File

@ -0,0 +1,15 @@
#ifndef FTXUI_DOM_BOX_HPP
#define FTXUI_DOM_BOX_HPP
namespace ftxui::dom {
struct Box {
int left;
int right;
int top;
int bottom;
};
}; // namespace ftxui::dom
#endif /* end of include guard: FTXUI_DOM_BOX_HPP */

View File

@ -3,16 +3,16 @@
#include <functional> #include <functional>
#include "ftxui/color.hpp"
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include "ftxui/screen/color.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
using Element = std::unique_ptr<Node>; using Element = std::unique_ptr<Node>;
using Decorator = std::function<Element(Element)>; using Decorator = std::function<Element(Element)>;
using Child = std::unique_ptr<Node>; using Child = std::unique_ptr<Node>;
using Children = std::vector<Child>; using Children = std::vector<Child>;
using Color = ftxui::screen::Color;
// --- Layout ---- // --- Layout ----
Element vbox(Children); Element vbox(Children);
@ -58,7 +58,6 @@ TAKE_ANY_ARGS(vbox)
TAKE_ANY_ARGS(hbox) TAKE_ANY_ARGS(hbox)
TAKE_ANY_ARGS(dbox) TAKE_ANY_ARGS(dbox)
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui
#endif /* end of include guard: FTXUI_DOM_ELEMENTS_HPP */ #endif /* end of include guard: FTXUI_DOM_ELEMENTS_HPP */

View File

@ -1,15 +1,14 @@
#ifndef DOM_NODE_HPP #ifndef FTXUI_DOM_NODE_HPP
#define DOM_NODE_HPP #define FTXUI_DOM_NODE_HPP
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "ftxui/requirement.hpp" #include "ftxui/dom/box.hpp"
#include "ftxui/screen.hpp" #include "ftxui/dom/requirement.hpp"
#include "ftxui/box.hpp" #include "ftxui/screen/screen.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
class Node { class Node {
public: public:
@ -28,7 +27,7 @@ class Node {
virtual void SetBox(Box box); virtual void SetBox(Box box);
// Step 3: Draw this element. // Step 3: Draw this element.
virtual void Render(Screen& screen); virtual void Render(screen::Screen& screen);
std::vector<std::unique_ptr<Node>> children; std::vector<std::unique_ptr<Node>> children;
protected: protected:
@ -36,9 +35,8 @@ class Node {
Box box_; Box box_;
}; };
void Render(Screen& screen, Node* node); void Render(screen::Screen& screen, Node* node);
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui
#endif /* end of include guard: DOM_NODE_HPP */ #endif /* end of include guard: FTXUI_DOM_NODE_HPP */

View File

@ -1,7 +1,7 @@
#ifndef FTXUI_REQUIREMENT_HPP #ifndef FTXUI_DOM_REQUIREMENT_HPP
#define FTXUI_REQUIREMENT_HPP #define FTXUI_DOM_REQUIREMENT_HPP
namespace ftxui { namespace ftxui::dom {
struct Requirement { struct Requirement {
// The required size to fully draw the element. // The required size to fully draw the element.
@ -11,6 +11,6 @@ struct Requirement {
struct { int x = 0; int y = 0; } flex; struct { int x = 0; int y = 0; } flex;
}; };
}; // namespace ftxui }; // namespace ftxui::dom
#endif /* end of include guard: FTXUI_REQUIREMENT_HPP */ #endif /* end of include guard: FTXUI_REQUIREMENT_HPP */

View File

@ -1,9 +1,9 @@
#ifndef FTXUI_COLOR_H_ #ifndef FTXUI_SCREEN_COLOR
#define FTXUI_COLOR_H_ #define FTXUI_SCREEN_COLOR
#include <cstdint> #include <cstdint>
namespace ftxui { namespace ftxui::screen {
enum class Color : uint8_t { enum class Color : uint8_t {
// --- Transparent ----- // --- Transparent -----
@ -35,6 +35,6 @@ enum class Color : uint8_t {
YellowLight = 93, YellowLight = 93,
}; };
}; // namespace ftxui }; // namespace ftxui::screen
#endif /* end of include guard: FTXUI_COLOR_H_ */ #endif /* end of include guard: FTXUI_COLOR_H_ */

View File

@ -1,17 +1,18 @@
#ifndef FTXUI_SCREEN #ifndef FTXUI_SCREEN_SCREEN
#define FTXUI_SCREEN #define FTXUI_SCREEN_SCREEN
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory> #include <memory>
#include <ftxui/color.hpp> #include "ftxui/screen/color.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
class Node; class Node;
} }
namespace ftxui::screen {
struct Pixel { struct Pixel {
wchar_t character = U' '; wchar_t character = U' ';
bool blink = false; bool blink = false;
@ -55,6 +56,6 @@ class Screen {
std::vector<std::vector<Pixel>> pixels_; std::vector<std::vector<Pixel>> pixels_;
}; };
}; // namespace ftxui }; // namespace ftxui::screen
#endif /* end of include guard: FTXUI_SCREEN */ #endif /* end of include guard: FTXUI_SCREEN_SCREEN */

View File

@ -2,8 +2,7 @@
#include "ftxui/component/delegate.hpp" #include "ftxui/component/delegate.hpp"
#include <assert.h> #include <assert.h>
namespace ftxui { namespace ftxui::component {
namespace component {
Component::Component(Delegate* delegate) { Component::Component(Delegate* delegate) {
delegate_ = delegate; delegate_ = delegate;
@ -55,5 +54,4 @@ Component* Component::Parent() {
return parent_delegate->component(); return parent_delegate->component();
} }
} // namespace component } // namespace ftxui::component
} // namespace ftxui

View File

@ -1,7 +1,6 @@
#include "ftxui/component/component_direction.hpp" #include "ftxui/component/component_direction.hpp"
namespace ftxui { namespace ftxui::component {
namespace component {
ComponentDirection::ComponentDirection(Delegate* delegate) ComponentDirection::ComponentDirection(Delegate* delegate)
: Component(delegate), active_child_(nullptr) {} : Component(delegate), active_child_(nullptr) {}
@ -27,5 +26,4 @@ void ComponentDirection::Focus(Component* child) {
active_child_ = child; active_child_ = child;
} }
} // namespace component } // namespace ftxui::Component
} // namespace ftxui

View File

@ -1,7 +1,6 @@
#include "ftxui/component/component_horizontal.hpp" #include "ftxui/component/component_horizontal.hpp"
namespace ftxui { namespace ftxui::component {
namespace component {
ComponentHorizontal::ComponentHorizontal(Delegate* delegate) ComponentHorizontal::ComponentHorizontal(Delegate* delegate)
: ComponentDirection(delegate) {} : ComponentDirection(delegate) {}
@ -28,5 +27,4 @@ bool ComponentHorizontal::HandleDirection(Event event) {
return false; return false;
} }
} // namespace component } // namespace ftxui::component
} // namespace ftxui

View File

@ -1,7 +1,6 @@
#include "ftxui/component/component_vertical.hpp" #include "ftxui/component/component_vertical.hpp"
namespace ftxui { namespace ftxui::component {
namespace component {
ComponentVertical::ComponentVertical(Delegate* delegate) ComponentVertical::ComponentVertical(Delegate* delegate)
: ComponentDirection(delegate) {} : ComponentDirection(delegate) {}
@ -28,5 +27,4 @@ bool ComponentVertical::HandleDirection(Event event) {
return false; return false;
} }
} // namespace component } // namespace ftxui::component
} // namespace ftxui

View File

@ -1,6 +1,6 @@
#include "ftxui/event.hpp" #include "ftxui/component/event.hpp"
namespace ftxui { namespace ftxui::component {
constexpr int ESC = int(27); 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::F11{ESC, '[', '2', '1', '~'}; // Same as F10 ?
Event Event::F12{ESC, '[', '2', '4', '~'}; Event Event::F12{ESC, '[', '2', '4', '~'};
} // namespace ftxui } // namespace ftxui::component

View File

@ -1,8 +1,7 @@
#include "ftxui/component/input.hpp" #include "ftxui/component/input.hpp"
#include "ftxui/util/string.hpp" #include "ftxui/util/string.hpp"
namespace ftxui { namespace ftxui::component {
namespace component {
Input::Input(Delegate* delegate): Component(delegate) {} Input::Input(Delegate* delegate): Component(delegate) {}
Input::~Input() {} Input::~Input() {}
@ -76,5 +75,4 @@ bool Input::OnEvent(Event event) {
return false; return false;
} }
} // namespace component } // namespace ftxui::component
} // namespace ftxui

View File

@ -2,8 +2,7 @@
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
namespace ftxui { namespace ftxui::component {
namespace component {
Menu::Menu(Delegate* delegate) : Component(delegate) {} Menu::Menu(Delegate* delegate) : Component(delegate) {}
@ -50,5 +49,4 @@ bool Menu::OnEvent(Event event) {
return false; return false;
} }
} // namespace component } // namespace ftxui::component
} // namespace ftxui

View File

@ -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 <stdio.h>
#include <termios.h> #include <termios.h>
#include <unistd.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 { namespace {
constexpr int ESC = 27; constexpr int ESC = 27;
constexpr int WAT = 195; constexpr int WAT = 195;
constexpr int WAT2 = 194; constexpr int WAT2 = 194;
constexpr int WATWAIT = 91; constexpr int WATWAIT = 91;
Event GetEvent() { Event GetEvent() {
int v1 = getchar(); int v1 = getchar();
if (v1 == ESC) { if (v1 == ESC) {
int v2 = getchar(); int v2 = getchar();
int v3 = getchar(); int v3 = getchar();
//if (v2 == WATWAIT) { // if (v2 == WATWAIT) {
//int v4 = getchar(); // int v4 = getchar();
//int v5 = getchar(); // int v5 = getchar();
//return Event{v1, v2, v3, v4, v5}; // return Event{v1, v2, v3, v4, v5};
//} //}
return Event{v1, v2, v3}; return Event{v1, v2, v3};
} }
if (v1 == WAT) { if (v1 == WAT) {
int v2 = getchar(); int v2 = getchar();
return Event{v1, v2}; return Event{v1, v2};
} }
if (v1 == WAT2) { if (v1 == WAT2) {
int v2 = getchar(); int v2 = getchar();
return Event{v1, v2}; return Event{v1, v2};
} }
return Event{v1}; return Event{v1};
};
}; };
}; // namespace
class ScreenInteractive::Delegate : public component::Delegate { class ScreenInteractive::Delegate : public component::Delegate {
public: public:
@ -67,7 +67,6 @@ class ScreenInteractive::Delegate : public component::Delegate {
void OnEvent(Event event) { component_->OnEvent(event); } void OnEvent(Event event) { component_->OnEvent(event); }
std::vector<component::Delegate*> children() override { std::vector<component::Delegate*> children() override {
std::vector<component::Delegate*> ret; std::vector<component::Delegate*> ret;
for (auto& it : child_) for (auto& it : child_)
@ -129,12 +128,14 @@ void ScreenInteractive::Loop() {
tcsetattr(STDIN_FILENO, TCSANOW, &terminal_configuration_new); tcsetattr(STDIN_FILENO, TCSANOW, &terminal_configuration_new);
Draw(); Draw();
while(!quit_) { while (!quit_) {
delegate_->OnEvent(GetEvent()); delegate_->OnEvent(GetEvent());
Clear(); Clear();
Draw(); Draw();
} while(!quit_); }
//std::cout << std::endl; while (!quit_)
;
// std::cout << std::endl;
// Restore the old terminal configuration. // Restore the old terminal configuration.
tcsetattr(STDIN_FILENO, TCSANOW, &terminal_configuration_old); tcsetattr(STDIN_FILENO, TCSANOW, &terminal_configuration_old);
@ -144,7 +145,7 @@ void ScreenInteractive::Draw() {
auto document = delegate_->component()->Render(); auto document = delegate_->component()->Render();
size_t dimx; size_t dimx;
size_t dimy; size_t dimy;
switch(dimension_) { switch (dimension_) {
case Dimension::Fixed: case Dimension::Fixed:
break; break;
case Dimension::TerminalOutput: case Dimension::TerminalOutput:
@ -162,7 +163,8 @@ void ScreenInteractive::Draw() {
if (dimx != dimx_ || dimy != dimy_) { if (dimx != dimx_ || dimy != dimy_) {
dimx_ = dimx; dimx_ = dimx;
dimy_ = dimy; 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()); Render(*this, document.get());
@ -182,4 +184,4 @@ std::function<void()> ScreenInteractive::ExitLoopClosure() {
return [this]() { quit_ = true; }; return [this]() { quit_ = true; };
} }
} // namespace ftxui } // namespace ftxui::component.

View File

@ -1,7 +1,6 @@
#include "ftxui/component/toggle.hpp" #include "ftxui/component/toggle.hpp"
namespace ftxui { namespace ftxui::component {
namespace component {
Toggle::Toggle(Delegate* delegate) : Component(delegate) {} Toggle::Toggle(Delegate* delegate) : Component(delegate) {}
@ -41,5 +40,4 @@ bool Toggle::OnEvent(Event event) {
return false; return false;
} }
} // namespace component } // namespace ftxui::component
} // namespace ftxui

View File

@ -1,15 +1,14 @@
#include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
class Blink : public NodeDecorator { class Blink : public NodeDecorator {
public: public:
Blink(Children children) : NodeDecorator(std::move(children)) {} Blink(Children children) : NodeDecorator(std::move(children)) {}
~Blink() override {} ~Blink() override {}
void Render(Screen& screen) override { void Render(screen::Screen& screen) override {
Node::Render(screen); Node::Render(screen);
for (int y = box_.top; y <= box_.bottom; ++y) { for (int y = box_.top; y <= box_.bottom; ++y) {
for (int x = box_.left; x <= box_.right; ++x) { 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))); return std::make_unique<Blink>(unpack(std::move(child)));
} }
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,15 +1,14 @@
#include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
class Bold : public NodeDecorator { class Bold : public NodeDecorator {
public: public:
Bold(Children children) : NodeDecorator(std::move(children)) {} Bold(Children children) : NodeDecorator(std::move(children)) {}
~Bold() override {} ~Bold() override {}
void Render(Screen& screen) override { void Render(screen::Screen& screen) override {
for (int y = box_.top; y <= box_.bottom; ++y) { for (int y = box_.top; y <= box_.bottom; ++y) {
for (int x = box_.left; x <= box_.right; ++x) { for (int x = box_.left; x <= box_.right; ++x) {
screen.PixelAt(x,y).bold = true; 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))); return std::make_unique<Bold>(unpack(std::move(child)));
} }
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,15 +1,14 @@
#include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
class BgColor : public NodeDecorator { class BgColor : public NodeDecorator {
public: public:
BgColor(Children children, Color color) BgColor(Children children, Color color)
: NodeDecorator(std::move(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 y = box_.top; y <= box_.bottom; ++y) {
for (int x = box_.left; x <= box_.right; ++x) { for (int x = box_.left; x <= box_.right; ++x) {
screen.PixelAt(x, y).background_color = color_; screen.PixelAt(x, y).background_color = color_;
@ -27,7 +26,7 @@ class FgColor : public NodeDecorator {
: NodeDecorator(std::move(children)), color_(color) {} : NodeDecorator(std::move(children)), color_(color) {}
~FgColor() override {} ~FgColor() override {}
void Render(Screen& screen) override { void Render(screen::Screen& screen) override {
for (int y = box_.top; y <= box_.bottom; ++y) { for (int y = box_.top; y <= box_.bottom; ++y) {
for (int x = box_.left; x <= box_.right; ++x) { for (int x = box_.left; x <= box_.right; ++x) {
screen.PixelAt(x, y).foreground_color = color_; screen.PixelAt(x, y).foreground_color = color_;
@ -59,5 +58,4 @@ Decorator bgcolor(Color c) {
}; };
} }
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,8 +1,7 @@
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
std::unique_ptr<Node> hcenter(Element child) { std::unique_ptr<Node> hcenter(Element child) {
return hbox(filler(), std::move(child), filler()); return hbox(filler(), std::move(child), filler());
@ -16,5 +15,4 @@ std::unique_ptr<Node> center(Element child) {
return hcenter(vcenter(std::move(child))); return hcenter(vcenter(std::move(child)));
} }
} // namespace dom } // namespace ftxui::dom
} // namespace ftxui

View File

@ -1,8 +1,7 @@
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
class DBox : public Node { class DBox : public Node {
public: public:
@ -33,5 +32,4 @@ std::unique_ptr<Node> dbox(Children children) {
return std::make_unique<DBox>(std::move(children)); return std::make_unique<DBox>(std::move(children));
} }
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,8 +1,9 @@
#include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
using ftxui::screen::Screen;
class Dim : public NodeDecorator { class Dim : public NodeDecorator {
public: public:
@ -23,5 +24,4 @@ std::unique_ptr<Node> dim(Child child) {
return std::make_unique<Dim>(unpack(std::move(child))); return std::make_unique<Dim>(unpack(std::move(child)));
} }
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,8 +1,7 @@
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
class Flex : public Node { class Flex : public Node {
public: public:
@ -35,5 +34,4 @@ std::unique_ptr<Node> flex(Element child) {
return std::make_unique<Flex>(std::move(child)); return std::make_unique<Flex>(std::move(child));
} }
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,8 +1,9 @@
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
using namespace ftxui::screen;
static wchar_t charset[] = L"┌┐└┘─│┬┴┤├"; static wchar_t charset[] = L"┌┐└┘─│┬┴┤├";
@ -94,5 +95,4 @@ Decorator boxed() {
}; };
} }
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,8 +1,9 @@
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
using namespace ftxui::screen;
static wchar_t charset[] = L" ▏▎▍▌▋▊▉█"; static wchar_t charset[] = L" ▏▎▍▌▋▊▉█";
@ -35,5 +36,4 @@ std::unique_ptr<Node> gauge(float progress) {
return std::make_unique<Gauge>(progress); return std::make_unique<Gauge>(progress);
} }
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,9 +1,9 @@
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace ftxui { using namespace ftxui::screen;
namespace dom { using namespace ftxui::dom;
TEST(GaugeTest, zero) { TEST(GaugeTest, zero) {
auto root = gauge(0); auto root = gauge(0);
@ -29,6 +29,3 @@ TEST(GaugeTest, one) {
EXPECT_EQ("███████████", screen.ToString()); EXPECT_EQ("███████████", screen.ToString());
} }
} // namespace dom
} // namespace ftxui

View File

@ -1,8 +1,7 @@
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
class HBox : public Node { class HBox : public Node {
public: public:
@ -64,5 +63,4 @@ std::unique_ptr<Node> hbox(Children children) {
return std::make_unique<HBox>(std::move(children)); return std::make_unique<HBox>(std::move(children));
} }
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,9 +1,9 @@
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace ftxui { using namespace ftxui::screen;
namespace dom { using namespace ftxui::dom;
TEST(HBoxTest, ScreenSmaller1) { TEST(HBoxTest, ScreenSmaller1) {
auto root = hbox( auto root = hbox(
@ -118,6 +118,3 @@ TEST(HBoxTest, ScreenBigger2Flex) {
EXPECT_EQ("text_1 text_2", screen.ToString()); EXPECT_EQ("text_1 text_2", screen.ToString());
} }
}; // namespace dom
}; // namespace ftxui

View File

@ -1,8 +1,9 @@
#include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
using ftxui::screen::Screen;
class Inverted : public NodeDecorator { class Inverted : public NodeDecorator {
public: public:
@ -23,5 +24,4 @@ std::unique_ptr<Node> inverted(Child child) {
return std::make_unique<Inverted>(unpack(std::move(child))); return std::make_unique<Inverted>(unpack(std::move(child)));
} }
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,7 +1,8 @@
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
using ftxui::screen::Screen;
Node::Node() {} Node::Node() {}
Node::Node(std::vector<std::unique_ptr<Node>> children) Node::Node(std::vector<std::unique_ptr<Node>> children)
@ -39,5 +40,4 @@ void Render(Screen& screen, Node* node) {
node->Render(screen); node->Render(screen);
} }
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,7 +1,6 @@
#include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/node_decorator.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
void NodeDecorator::ComputeRequirement() { void NodeDecorator::ComputeRequirement() {
Node::ComputeRequirement(); Node::ComputeRequirement();
@ -13,5 +12,4 @@ void NodeDecorator::SetBox(Box box) {
children[0]->SetBox(box); children[0]->SetBox(box);
} }
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -4,8 +4,7 @@
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
// Helper class. // Helper class.
class NodeDecorator : public Node { class NodeDecorator : public Node {
@ -16,7 +15,6 @@ class NodeDecorator : public Node {
void SetBox(Box box) override; void SetBox(Box box) override;
}; };
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui
#endif /* end of include guard: FTXUI_DOM_NODE_DECORATOR_H_ */ #endif /* end of include guard: FTXUI_DOM_NODE_DECORATOR_H_ */

View File

@ -1,7 +1,8 @@
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
using ftxui::screen::Screen;
class Separator : public Node { class Separator : public Node {
public: public:
@ -34,5 +35,4 @@ std::unique_ptr<Node> separator() {
return std::make_unique<Separator>(); return std::make_unique<Separator>();
} }
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,7 +1,8 @@
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
using ftxui::screen::Screen;
class Text : public Node { class Text : public Node {
public: public:
@ -33,5 +34,4 @@ std::unique_ptr<Node> text(std::wstring text) {
return std::make_unique<Text>(text); return std::make_unique<Text>(text);
} }
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,9 +1,9 @@
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace ftxui { using namespace ftxui::screen;
namespace dom { using namespace ftxui::dom;
TEST(TextTest, ScreenHeightSmaller) { TEST(TextTest, ScreenHeightSmaller) {
auto element = text(L"test"); auto element = text(L"test");
@ -44,6 +44,3 @@ TEST(TextTest, ScreenBigger2) {
EXPECT_EQ("test \n ", screen.ToString()); EXPECT_EQ("test \n ", screen.ToString());
} }
}; // namespace dom
}; // namespace ftxui

View File

@ -1,8 +1,9 @@
#include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
using ftxui::screen::Screen;
class Underlined : public NodeDecorator { class Underlined : public NodeDecorator {
public: public:
@ -23,5 +24,4 @@ std::unique_ptr<Node> underlined(Child child) {
return std::make_unique<Underlined>(unpack(std::move(child))); return std::make_unique<Underlined>(unpack(std::move(child)));
} }
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,7 +1,6 @@
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
Element nothing(Element element) { Element nothing(Element element) {
return std::move(element); return std::move(element);
@ -24,5 +23,4 @@ Element operator|(Element e, Decorator d) {
return d(std::move(e)); return d(std::move(e));
} }
} // namespace dom } // namespace ftxui::dom
} // namespace ftxui

View File

@ -1,8 +1,7 @@
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
namespace ftxui { namespace ftxui::dom {
namespace dom {
class VBox : public Node { class VBox : public Node {
public: public:
@ -64,5 +63,4 @@ std::unique_ptr<Node> vbox(Children children) {
return std::make_unique<VBox>(std::move(children)); return std::make_unique<VBox>(std::move(children));
} }
}; // namespace dom }; // namespace ftxui::dom
}; // namespace ftxui

View File

@ -1,9 +1,9 @@
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace ftxui { using namespace ftxui::screen;
namespace dom { using namespace ftxui::dom;
TEST(VBoxTest, ScreenSmaller1) { TEST(VBoxTest, ScreenSmaller1) {
auto root = vbox(text(L"text_1"), text(L"text_2")); 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()); EXPECT_EQ("text_1\n \n \ntext_2", screen.ToString());
} }
}; // namespace dom
}; // namespace ftxui

View File

@ -1,26 +1,46 @@
#include "ftxui/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include "ftxui/terminal.hpp" #include "ftxui/terminal.hpp"
#include "ftxui/util/string.hpp" #include "ftxui/util/string.hpp"
#include <sstream> #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) Screen::Screen(size_t dimx, size_t dimy)
: dimx_(dimx), dimy_(dimy), pixels_(dimy, std::vector<Pixel>(dimx)) {} : dimx_(dimx), dimy_(dimy), pixels_(dimy, std::vector<Pixel>(dimx)) {}
void UpdatePixelStyle(std::wstringstream& ss, Pixel& previous, Pixel& next) { void UpdatePixelStyle(std::wstringstream& ss, Pixel& previous, Pixel& next) {
if (next.bold != previous.bold) 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) 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) 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) 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) 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 || if (next.foreground_color != previous.foreground_color ||
next.background_color != previous.background_color) { next.background_color != previous.background_color) {
ss << L"\e[" + to_wstring(std::to_string((uint8_t)next.foreground_color)) + L"m"; 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())); std::vector<Pixel>(dimx_, Pixel()));
} }
}; // namespace ftxui }; // namespace ftxui::screen