mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-16 08:04:21 +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,18 +2,17 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include "ftxui/screen_interactive.hpp"
|
||||
#include "ftxui/component/input.hpp"
|
||||
#include "ftxui/component/component_vertical.hpp"
|
||||
#include "ftxui/component/input.hpp"
|
||||
#include "ftxui/component/screen_interactive.hpp"
|
||||
#include "ftxui/util/string.hpp"
|
||||
|
||||
using namespace ftxui::component;
|
||||
using namespace ftxui::dom;
|
||||
using namespace ftxui;
|
||||
|
||||
class MyComponent : ComponentVertical {
|
||||
public:
|
||||
MyComponent(ftxui::component::Delegate* delegate)
|
||||
MyComponent(Delegate* delegate)
|
||||
: ComponentVertical(delegate),
|
||||
input_1(delegate->NewChild()),
|
||||
input_2(delegate->NewChild()),
|
||||
@@ -45,7 +44,7 @@ class MyComponent : ComponentVertical {
|
||||
};
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
auto screen = ftxui::ScreenInteractive::TerminalOutput();
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
MyComponent component(screen.delegate());
|
||||
component.on_enter = screen.ExitLoopClosure();
|
||||
screen.Loop();
|
||||
|
@@ -2,18 +2,15 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include "ftxui/screen_interactive.hpp"
|
||||
#include "ftxui/component/menu.hpp"
|
||||
#include "ftxui/component/screen_interactive.hpp"
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
auto screen = ftxui::ScreenInteractive::FixedSize(30, 3);
|
||||
ftxui::component::Menu menu(screen.delegate());
|
||||
menu.entries = {
|
||||
L"entry 1",
|
||||
L"entry 2",
|
||||
L"entry 3"
|
||||
};
|
||||
int main(int argc, const char* argv[]) {
|
||||
using namespace ftxui::component;
|
||||
using namespace ftxui::screen;
|
||||
auto screen = ScreenInteractive::FixedSize(30, 3);
|
||||
Menu menu(screen.delegate());
|
||||
menu.entries = {L"entry 1", L"entry 2", L"entry 3"};
|
||||
menu.selected = 0;
|
||||
menu.on_enter = screen.ExitLoopClosure();
|
||||
|
||||
|
@@ -2,10 +2,10 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include "ftxui/screen_interactive.hpp"
|
||||
#include "ftxui/component/menu.hpp"
|
||||
#include "ftxui/component/component_horizontal.hpp"
|
||||
#include "ftxui/component/component_vertical.hpp"
|
||||
#include "ftxui/component/menu.hpp"
|
||||
#include "ftxui/component/screen_interactive.hpp"
|
||||
#include "ftxui/util/string.hpp"
|
||||
|
||||
using namespace ftxui::component;
|
||||
@@ -13,7 +13,7 @@ using namespace ftxui::dom;
|
||||
|
||||
class MyComponent : ComponentHorizontal {
|
||||
public:
|
||||
MyComponent(ftxui::component::Delegate* delegate)
|
||||
MyComponent(Delegate* delegate)
|
||||
: ComponentHorizontal(delegate),
|
||||
left_menu(delegate->NewChild()),
|
||||
right_menu(delegate->NewChild()) {
|
||||
@@ -66,7 +66,7 @@ class MyComponent : ComponentHorizontal {
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
auto screen = ftxui::ScreenInteractive::TerminalOutput();
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
MyComponent component(screen.delegate());
|
||||
component.on_enter = screen.ExitLoopClosure();
|
||||
screen.Loop();
|
||||
|
@@ -3,16 +3,15 @@
|
||||
|
||||
#include "ftxui/component/component_horizontal.hpp"
|
||||
#include "ftxui/component/menu.hpp"
|
||||
#include "ftxui/screen_interactive.hpp"
|
||||
#include "ftxui/component/screen_interactive.hpp"
|
||||
#include "ftxui/util/string.hpp"
|
||||
|
||||
using namespace ftxui;
|
||||
using namespace ftxui::component;
|
||||
using namespace ftxui::dom;
|
||||
|
||||
class MyComponent : ComponentHorizontal {
|
||||
public:
|
||||
MyComponent(ftxui::component::Delegate* delegate)
|
||||
MyComponent(Delegate* delegate)
|
||||
: ComponentHorizontal(delegate),
|
||||
menu_1(delegate->NewChild()),
|
||||
menu_2(delegate->NewChild()),
|
||||
@@ -76,8 +75,7 @@ class MyComponent : ComponentHorizontal {
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
//auto screen = ftxui::ScreenInteractive::TerminalOutput();
|
||||
auto screen = ftxui::ScreenInteractive::Fullscreen();
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
MyComponent component(screen.delegate());
|
||||
component.on_enter = screen.ExitLoopClosure();
|
||||
screen.Loop();
|
||||
|
@@ -2,18 +2,17 @@
|
||||
#include <thread>
|
||||
|
||||
#include "ftxui/component/component_vertical.hpp"
|
||||
#include "ftxui/component/toggle.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"
|
||||
|
||||
using namespace ftxui;
|
||||
using namespace ftxui::component;
|
||||
using namespace ftxui::dom;
|
||||
|
||||
class MyComponent : ComponentVertical {
|
||||
public:
|
||||
MyComponent(ftxui::component::Delegate* delegate)
|
||||
MyComponent(Delegate* delegate)
|
||||
: ComponentVertical(delegate),
|
||||
toggle(delegate->NewChild()),
|
||||
menu(delegate->NewChild()) {
|
||||
@@ -39,7 +38,7 @@ class MyComponent : ComponentVertical {
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
auto screen = ftxui::ScreenInteractive::TerminalOutput();
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
MyComponent component(screen.delegate());
|
||||
component.on_enter = screen.ExitLoopClosure();
|
||||
screen.Loop();
|
||||
|
@@ -2,19 +2,18 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include "ftxui/screen_interactive.hpp"
|
||||
#include "ftxui/component/toggle.hpp"
|
||||
#include "ftxui/component/component_horizontal.hpp"
|
||||
#include "ftxui/component/component_vertical.hpp"
|
||||
#include "ftxui/component/screen_interactive.hpp"
|
||||
#include "ftxui/component/toggle.hpp"
|
||||
#include "ftxui/util/string.hpp"
|
||||
|
||||
using namespace ftxui;
|
||||
using namespace ftxui::component;
|
||||
using namespace ftxui::dom;
|
||||
|
||||
class MyComponent : ComponentVertical {
|
||||
public:
|
||||
MyComponent(ftxui::component::Delegate* delegate)
|
||||
MyComponent(Delegate* delegate)
|
||||
: ComponentVertical(delegate),
|
||||
toggle_1(delegate->NewChild()),
|
||||
toggle_2(delegate->NewChild()),
|
||||
@@ -62,7 +61,7 @@ class MyComponent : ComponentVertical {
|
||||
};
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
auto screen = ftxui::ScreenInteractive::TerminalOutput();
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
MyComponent component(screen.delegate());
|
||||
component.on_enter = screen.ExitLoopClosure();
|
||||
screen.Loop();
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
using namespace ftxui;
|
||||
using namespace ftxui::screen;
|
||||
using namespace ftxui::dom;
|
||||
auto document =
|
||||
hbox(
|
||||
@@ -12,7 +12,7 @@ int main(int argc, const char *argv[])
|
||||
text(L"blink") | blink,
|
||||
text(L". Do you like it?")
|
||||
);
|
||||
auto screen = ftxui::Screen::TerminalOutput(document);
|
||||
auto screen = Screen::TerminalOutput(document);
|
||||
Render(screen, document.get());
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
using namespace ftxui;
|
||||
using namespace ftxui::screen;
|
||||
using namespace ftxui::dom;
|
||||
auto document =
|
||||
hbox(
|
||||
@@ -12,7 +12,7 @@ int main(int argc, const char *argv[])
|
||||
text(L"bold") | bold,
|
||||
text(L". Do you like it?")
|
||||
);
|
||||
auto screen = ftxui::Screen::TerminalOutput(document);
|
||||
auto screen = Screen::TerminalOutput(document);
|
||||
Render(screen, document.get());
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
using namespace ftxui;
|
||||
using namespace ftxui::screen;
|
||||
using namespace ftxui::dom;
|
||||
auto document =
|
||||
hbox(
|
||||
@@ -49,7 +49,7 @@ int main(int argc, const char *argv[])
|
||||
filler()
|
||||
);
|
||||
|
||||
auto screen = ftxui::Screen::TerminalOutput(document);
|
||||
auto screen = Screen::TerminalOutput(document);
|
||||
Render(screen, document.get());
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
@@ -1,10 +1,11 @@
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
using namespace ftxui::dom;
|
||||
using namespace ftxui::screen;
|
||||
auto document =
|
||||
dbox(
|
||||
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());
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
using namespace ftxui;
|
||||
using namespace ftxui::screen;
|
||||
using namespace ftxui::dom;
|
||||
auto document =
|
||||
hbox(
|
||||
@@ -12,7 +12,7 @@ int main(int argc, const char *argv[])
|
||||
text(L"dim") | dim,
|
||||
text(L". Do you like it?")
|
||||
);
|
||||
auto screen = ftxui::Screen::TerminalOutput(document);
|
||||
auto screen = Screen::TerminalOutput(document);
|
||||
Render(screen, document.get());
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
@@ -2,12 +2,13 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
using namespace ftxui::dom;
|
||||
using namespace ftxui::screen;
|
||||
auto document =
|
||||
hbox(
|
||||
window(text(L" main frame ") | hcenter,
|
||||
@@ -43,7 +44,7 @@ int main(int argc, const char *argv[])
|
||||
),
|
||||
filler()
|
||||
);
|
||||
auto screen = ftxui::Screen::TerminalOutput(document);
|
||||
auto screen = Screen::TerminalOutput(document);
|
||||
Render(screen, document.get());
|
||||
std::cout << screen.ToString() << std::endl;
|
||||
}
|
||||
|
@@ -2,26 +2,30 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
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) {
|
||||
std::wstring data_downloaded =
|
||||
std::to_wstring(int(percentage * 5000)) + L"/5000";
|
||||
using namespace ftxui::dom;
|
||||
auto document =
|
||||
hbox(
|
||||
text(L"downloading:"),
|
||||
gauge(percentage) | flex,
|
||||
text(L" " + data_downloaded)
|
||||
);
|
||||
auto screen = ftxui::Screen(100, 1);
|
||||
auto screen = Screen(100, 1);
|
||||
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::cout << std::endl;
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
using namespace ftxui;
|
||||
using namespace ftxui::screen;
|
||||
using namespace ftxui::dom;
|
||||
auto document =
|
||||
hbox(
|
||||
@@ -12,7 +12,7 @@ int main(int argc, const char *argv[])
|
||||
text(L"inverted") | inverted,
|
||||
text(L". Do you like it?")
|
||||
);
|
||||
auto screen = ftxui::Screen::TerminalOutput(document);
|
||||
auto screen = Screen::TerminalOutput(document);
|
||||
Render(screen, document.get());
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
@@ -2,17 +2,17 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "ftxui/util/string.hpp"
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
using namespace ftxui;
|
||||
using namespace ftxui::dom;
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
using namespace ftxui::screen;
|
||||
using namespace ftxui::dom;
|
||||
|
||||
struct Task {
|
||||
std::wstring name;
|
||||
int number_of_threads;
|
||||
@@ -119,7 +119,7 @@ int main(int argc, const char *argv[])
|
||||
|
||||
// Draw.
|
||||
auto document = render();
|
||||
auto screen = ftxui::Screen::TerminalOutput(document);
|
||||
auto screen = Screen::TerminalOutput(document);
|
||||
Render(screen, document.get());
|
||||
std::cout << reset_position << screen.ToString() << std::flush;
|
||||
reset_position = screen.ResetPosition();
|
||||
|
@@ -1,10 +1,11 @@
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
using namespace ftxui::dom;
|
||||
using namespace ftxui::screen;
|
||||
auto document =
|
||||
hbox(
|
||||
text(L"left-column"),
|
||||
@@ -15,7 +16,7 @@ int main(int argc, const char *argv[])
|
||||
center(text(L"bottom-column"))
|
||||
))
|
||||
);
|
||||
auto screen = ftxui::Screen::TerminalFullscreen();
|
||||
auto screen = Screen::TerminalFullscreen();
|
||||
Render(screen, document.get());
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
using namespace ftxui;
|
||||
using namespace ftxui::screen;
|
||||
using namespace ftxui::dom;
|
||||
auto document =
|
||||
hbox(
|
||||
@@ -17,7 +17,7 @@ int main(int argc, const char *argv[])
|
||||
text(L"color") | color(Color::Blue) , text(L" ") ,
|
||||
text(L"bgcolor") | bgcolor(Color::Blue)
|
||||
);
|
||||
auto screen = ftxui::Screen::TerminalOutput(document);
|
||||
auto screen = Screen::TerminalOutput(document);
|
||||
Render(screen, document.get());
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
using namespace ftxui;
|
||||
using namespace ftxui::screen;
|
||||
using namespace ftxui::dom;
|
||||
auto document =
|
||||
hbox(
|
||||
@@ -12,7 +12,7 @@ int main(int argc, const char *argv[])
|
||||
text(L"underlined") | underlined,
|
||||
text(L". Do you like it?")
|
||||
);
|
||||
auto screen = ftxui::Screen::TerminalOutput(document);
|
||||
auto screen = Screen::TerminalOutput(document);
|
||||
Render(screen, document.get());
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
@@ -1,9 +1,11 @@
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
using namespace ftxui::screen;
|
||||
using namespace ftxui::dom;
|
||||
auto document =
|
||||
vbox(
|
||||
@@ -27,7 +29,7 @@ int main(int argc, const char *argv[])
|
||||
text(L"south-east")
|
||||
)
|
||||
);
|
||||
auto screen = ftxui::Screen::TerminalFullscreen();
|
||||
auto screen = Screen::TerminalFullscreen();
|
||||
Render(screen, document.get());
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
@@ -2,26 +2,28 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include "ftxui/screen_interactive.hpp"
|
||||
#include "ftxui/component/component.hpp"
|
||||
#include "ftxui/component/screen_interactive.hpp"
|
||||
#include "ftxui/util/string.hpp"
|
||||
|
||||
class DrawKey : public ftxui::component::Component {
|
||||
using namespace ftxui::component;
|
||||
|
||||
class DrawKey : public Component {
|
||||
public:
|
||||
DrawKey(ftxui::component::Delegate* delegate)
|
||||
: ftxui::component::Component(delegate) {}
|
||||
DrawKey(Delegate* delegate)
|
||||
: Component(delegate) {}
|
||||
|
||||
ftxui::dom::Element Render() override {
|
||||
using namespace ftxui::dom;
|
||||
Children children;
|
||||
for (size_t i = std::max(0, (int)keys.size() - 10); i < keys.size(); ++i) {
|
||||
std::string code = "";
|
||||
for(size_t j = 0; j<5; ++j)
|
||||
std::string code = "";
|
||||
for (size_t j = 0; j < 5; ++j)
|
||||
code += " " + std::to_string(keys[i].values[j]);
|
||||
|
||||
try {
|
||||
std::string line = code + " -> " + std::to_string(keys[i].values[0]) + " (" +
|
||||
char(keys[i].values[0]) + ")";
|
||||
std::string line = code + " -> " + std::to_string(keys[i].values[0]) +
|
||||
" (" + char(keys[i].values[0]) + ")";
|
||||
children.push_back(text(to_wstring(line)));
|
||||
} catch (...) {
|
||||
std::string line =
|
||||
@@ -32,17 +34,17 @@ class DrawKey : public ftxui::component::Component {
|
||||
return vbox(std::move(children));
|
||||
}
|
||||
|
||||
bool OnEvent(ftxui::Event event) override {
|
||||
bool OnEvent(Event event) override {
|
||||
keys.push_back(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<ftxui::Event> keys;
|
||||
std::vector<Event> keys;
|
||||
};
|
||||
|
||||
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());
|
||||
screen.Loop();
|
||||
}
|
||||
|
Reference in New Issue
Block a user