Fix format. Try compile on Windows.

This commit is contained in:
ArthurSonzogni 2020-03-22 22:32:44 +01:00
parent 4ff45ee540
commit a402cb4fbb
67 changed files with 615 additions and 569 deletions

View File

@ -14,19 +14,17 @@ notifications:
jobs: jobs:
include: include:
# ubuntu 16.04, gcc-9 # Ubuntu
- os: linux - os: linux
dist: bionic
compiler: gcc compiler: gcc
addons: { apt: { packages: ["g++-9", "ninja-build"],
sources: ["ubuntu-toolchain-r-test"] } }
# ubuntu 16.04, clang-8 # Ubuntu
- os: linux - os: linux
dist: bionic
compiler: clang compiler: clang
addons: { apt: { packages: ["clang-8", "ninja-build"],
sources: ["llvm-toolchain-xenial-8"] } }
# OS X High Sierra 10.13 # OS X
- os: osx - os: osx
# Windows # Windows

View File

@ -10,7 +10,6 @@ option(FTXUI_ENABLE_INSTALL "Generate the install target" ON)
enable_testing() enable_testing()
cmake_minimum_required(VERSION 3.0)
find_package(Threads) find_package(Threads)
add_library(screen add_library(screen
@ -72,10 +71,14 @@ foreach(lib screen dom component)
PUBLIC PUBLIC
$<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE src PRIVATE
src
) )
set_property(TARGET ${lib} PROPERTY CXX_STANDARD 17) set_property(TARGET ${lib} PROPERTY CXX_STANDARD 17)
target_compile_options(${lib} PRIVATE -Wall -Werror -pedantic -Wextra -Wno-sign-compare) target_compile_options(${lib} PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -pedantic -Werror -Wno-sign-compare>
)
endforeach() endforeach()
if(FTXUI_ENABLE_INSTALL) if(FTXUI_ENABLE_INSTALL)

View File

@ -1,4 +1,5 @@
#include "ftxui/component/checkbox.hpp" #include "ftxui/component/checkbox.hpp"
#include "ftxui/component/component.hpp" #include "ftxui/component/component.hpp"
#include "ftxui/component/container.hpp" #include "ftxui/component/container.hpp"
#include "ftxui/component/screen_interactive.hpp" #include "ftxui/component/screen_interactive.hpp"
@ -6,25 +7,26 @@
using namespace ftxui; using namespace ftxui;
class MyComponent : public Component { class MyComponent : public Component {
private: private:
CheckBox box_1_; CheckBox box_1_;
CheckBox box_2_; CheckBox box_2_;
CheckBox box_3_; CheckBox box_3_;
Container container_ = Container::Vertical(); Container container_ = Container::Vertical();
public:
MyComponent() { public:
Add(&container_); MyComponent() {
container_.Add(&box_1_); Add(&container_);
container_.Add(&box_2_); container_.Add(&box_1_);
container_.Add(&box_3_); container_.Add(&box_2_);
box_1_.label = L"Build examples"; container_.Add(&box_3_);
box_2_.label = L"Build tests"; box_1_.label = L"Build examples";
box_3_.label = L"Use WebAssembly"; box_2_.label = L"Build tests";
box_3_.state = true; box_3_.label = L"Use WebAssembly";
} box_3_.state = true;
}
}; };
int main(int argc, const char *argv[]) { int main(int argc, const char* argv[]) {
auto screen = ScreenInteractive::TerminalOutput(); auto screen = ScreenInteractive::TerminalOutput();
MyComponent component; MyComponent component;
screen.Loop(&component); screen.Loop(&component);

View File

@ -2,7 +2,6 @@
#include "ftxui/component/container.hpp" #include "ftxui/component/container.hpp"
#include "ftxui/component/input.hpp" #include "ftxui/component/input.hpp"
#include "ftxui/component/menu.hpp" #include "ftxui/component/menu.hpp"
#include "ftxui/component/checkbox.hpp"
#include "ftxui/component/screen_interactive.hpp" #include "ftxui/component/screen_interactive.hpp"
#include "ftxui/component/toggle.hpp" #include "ftxui/component/toggle.hpp"
#include "ftxui/screen/string.hpp" #include "ftxui/screen/string.hpp"
@ -14,15 +13,16 @@ class MyComponent : public Component {
MyComponent() { MyComponent() {
Add(&container); Add(&container);
checkbox.resize(30); checkbox.resize(30);
for(int i = 0; i<checkbox.size(); ++i) { for (int i = 0; i < checkbox.size(); ++i) {
checkbox[i].label = (L"CheckBox " + to_wstring(i)); checkbox[i].label = (L"CheckBox " + to_wstring(i));
container.Add(&checkbox[i]); container.Add(&checkbox[i]);
} }
} }
// clang-format off
Element Render() override { Element Render() override {
Elements content; Elements content;
for(auto& it : checkbox) { for (auto& it : checkbox) {
content.push_back(it.Render()); content.push_back(it.Render());
} }
return vbox(std::move(content)) return vbox(std::move(content))

View File

@ -1,8 +1,8 @@
#include "ftxui/component/checkbox.hpp"
#include "ftxui/component/container.hpp" #include "ftxui/component/container.hpp"
#include "ftxui/component/input.hpp" #include "ftxui/component/input.hpp"
#include "ftxui/component/menu.hpp" #include "ftxui/component/menu.hpp"
#include "ftxui/component/radiobox.hpp" #include "ftxui/component/radiobox.hpp"
#include "ftxui/component/checkbox.hpp"
#include "ftxui/component/screen_interactive.hpp" #include "ftxui/component/screen_interactive.hpp"
#include "ftxui/component/toggle.hpp" #include "ftxui/component/toggle.hpp"
@ -53,6 +53,7 @@ class MyComponent : public Component {
container.Add(&input); container.Add(&input);
} }
// clang-format off
Element Render(std::wstring name, Component& component) { Element Render(std::wstring name, Component& component) {
return return
hbox( hbox(
@ -72,6 +73,7 @@ class MyComponent : public Component {
Render(L"input", input) | size(WIDTH, LESS_THAN, 30) Render(L"input", input) | size(WIDTH, LESS_THAN, 30)
) | border; ) | border;
} }
// clang-format on
}; };
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {

View File

@ -1,5 +1,6 @@
#include <cmath> #include <cmath>
#include <thread> #include <thread>
#include "ftxui/component/checkbox.hpp" #include "ftxui/component/checkbox.hpp"
#include "ftxui/component/container.hpp" #include "ftxui/component/container.hpp"
#include "ftxui/component/input.hpp" #include "ftxui/component/input.hpp"
@ -19,7 +20,7 @@ class Graph {
for (int i = 0; i < width; ++i) { for (int i = 0; i < width; ++i) {
float v = 0; float v = 0;
v += 0.1 * sin((i + shift) * 0.1); v += 0.1 * sin((i + shift) * 0.1);
v += 0.2 * sin((i + shift+10) * 0.15); v += 0.2 * sin((i + shift + 10) * 0.15);
v += 0.1 * sin((i + shift) * 0.03); v += 0.1 * sin((i + shift) * 0.03);
v *= height; v *= height;
v += 0.5 * height; v += 0.5 * height;
@ -36,6 +37,7 @@ class HTopComponent : public Component {
HTopComponent() {} HTopComponent() {}
~HTopComponent() override {} ~HTopComponent() override {}
// clang-format off
Element Render() override { Element Render() override {
return return
hbox( hbox(
@ -77,18 +79,19 @@ class HTopComponent : public Component {
) | flex ) | flex
) | flex | border; ) | flex | border;
} }
// clang-format on
}; };
class CompilerComponent : public Component { class CompilerComponent : public Component {
Container container = Container::Horizontal(); Container container = Container::Horizontal();
RadioBox compiler; RadioBox compiler;
Container flag = Container::Vertical(); Container flag = Container::Vertical();
CheckBox flag_checkbox[4]; CheckBox flag_checkbox[4];
Container subcontainer = Container::Vertical(); Container subcontainer = Container::Vertical();
Container input_container = Container::Horizontal(); Container input_container = Container::Horizontal();
Input input_add; Input input_add;
Menu input; Menu input;
Input executable; Input executable;
public: public:
~CompilerComponent() override {} ~CompilerComponent() override {}
@ -97,45 +100,45 @@ class CompilerComponent : public Component {
// Compiler ---------------------------------------------------------------- // Compiler ----------------------------------------------------------------
compiler.entries = { compiler.entries = {
L"gcc", L"gcc",
L"clang", L"clang",
L"emcc", L"emcc",
L"game_maker" L"game_maker"
L"Ada compilers", L"Ada compilers",
L"ALGOL 60 compilers", L"ALGOL 60 compilers",
L"ALGOL 68 compilers", L"ALGOL 68 compilers",
L"Assemblers (Intel *86)", L"Assemblers (Intel *86)",
L"Assemblers (Motorola 68*)", L"Assemblers (Motorola 68*)",
L"Assemblers (Zilog Z80)", L"Assemblers (Zilog Z80)",
L"Assemblers (other)", L"Assemblers (other)",
L"BASIC Compilers", L"BASIC Compilers",
L"BASIC interpreters", L"BASIC interpreters",
L"Batch compilers", L"Batch compilers",
L"C compilers", L"C compilers",
L"Source-to-source compilers", L"Source-to-source compilers",
L"C++ compilers", L"C++ compilers",
L"C# compilers", L"C# compilers",
L"COBOL compilers", L"COBOL compilers",
L"Common Lisp compilers", L"Common Lisp compilers",
L"D compilers", L"D compilers",
L"DIBOL/DBL compilers", L"DIBOL/DBL compilers",
L"ECMAScript interpreters", L"ECMAScript interpreters",
L"Eiffel compilers", L"Eiffel compilers",
L"Fortran compilers", L"Fortran compilers",
L"Go compilers", L"Go compilers",
L"Haskell compilers", L"Haskell compilers",
L"Java compilers", L"Java compilers",
L"Pascal compilers", L"Pascal compilers",
L"Perl Interpreters", L"Perl Interpreters",
L"PHP compilers", L"PHP compilers",
L"PL/I compilers", L"PL/I compilers",
L"Python compilers", L"Python compilers",
L"Scheme compilers and interpreters", L"Scheme compilers and interpreters",
L"Smalltalk compilers", L"Smalltalk compilers",
L"Tcl Interpreters", L"Tcl Interpreters",
L"VMS Interpreters", L"VMS Interpreters",
L"Rexx Interpreters", L"Rexx Interpreters",
L"CLI compilers", L"CLI compilers",
}; };
container.Add(&compiler); container.Add(&compiler);
@ -145,11 +148,12 @@ class CompilerComponent : public Component {
flag_checkbox[1].label = L"-Werror"; flag_checkbox[1].label = L"-Werror";
flag_checkbox[2].label = L"-lpthread"; flag_checkbox[2].label = L"-lpthread";
flag_checkbox[3].label = L"-O3"; flag_checkbox[3].label = L"-O3";
for(auto& c : flag_checkbox) for (auto& c : flag_checkbox)
flag.Add(&c); flag.Add(&c);
container.Add(&subcontainer); container.Add(&subcontainer);
// Executable ---------------------------------------------------------------- // Executable
// ----------------------------------------------------------------
executable.placeholder = L"executable"; executable.placeholder = L"executable";
subcontainer.Add(&executable); subcontainer.Add(&executable);
@ -165,6 +169,7 @@ class CompilerComponent : public Component {
input_container.Add(&input); input_container.Add(&input);
} }
// clang-format off
Element Render() override { Element Render() override {
return return
vbox( vbox(
@ -194,13 +199,14 @@ class CompilerComponent : public Component {
hflow(RenderCommandLine()) hflow(RenderCommandLine())
) | border; ) | border;
} }
// clang-format on
Elements RenderCommandLine() { Elements RenderCommandLine() {
Elements line; Elements line;
// Compiler // Compiler
line.push_back(text(compiler.entries[compiler.selected]) | bold); line.push_back(text(compiler.entries[compiler.selected]) | bold);
// flags // flags
for(auto& it : flag_checkbox) { for (auto& it : flag_checkbox) {
if (it.state) { if (it.state) {
line.push_back(text(L" ")); line.push_back(text(L" "));
line.push_back(text(it.label) | dim); line.push_back(text(it.label) | dim);
@ -212,7 +218,7 @@ class CompilerComponent : public Component {
line.push_back(text(executable.content) | color(Color::BlueLight) | bold); line.push_back(text(executable.content) | color(Color::BlueLight) | bold);
} }
// Input // Input
for(auto& it : input.entries) { for (auto& it : input.entries) {
line.push_back(text(L" " + it) | color(Color::RedLight)); line.push_back(text(L" " + it) | color(Color::RedLight));
} }
return line; return line;
@ -220,6 +226,7 @@ class CompilerComponent : public Component {
}; };
class SpinnerComponent : public Component { class SpinnerComponent : public Component {
// clang-format off
Element Render() override { Element Render() override {
Elements entries; Elements entries;
for(int i = 0; i<22; ++i) { for(int i = 0; i<22; ++i) {
@ -233,9 +240,11 @@ class SpinnerComponent : public Component {
} }
return hflow(std::move(entries)) | border; return hflow(std::move(entries)) | border;
} }
// clang-format on
}; };
class ColorComponent : public Component { class ColorComponent : public Component {
// clang-format off
Element Render() override { Element Render() override {
return return
hbox( hbox(
@ -278,10 +287,12 @@ class ColorComponent : public Component {
bgcolor(Color::YellowLight, text(L"YellowLight")) bgcolor(Color::YellowLight, text(L"YellowLight"))
) )
) | hcenter | border; ) | hcenter | border;
// clang-format on
} }
}; };
class GaugeComponent : public Component { class GaugeComponent : public Component {
// clang-format off
Element RenderGauge(int delta) { Element RenderGauge(int delta) {
float progress = (shift + delta) % 1000 / 1000.f; float progress = (shift + delta) % 1000 / 1000.f;
return hbox(text(std::to_wstring(int(progress * 100)) + L"% ") | size(WIDTH, EQUAL, 5), return hbox(text(std::to_wstring(int(progress * 100)) + L"% ") | size(WIDTH, EQUAL, 5),
@ -308,46 +319,40 @@ class GaugeComponent : public Component {
RenderGauge(348) | color(Color::YellowLight) RenderGauge(348) | color(Color::YellowLight)
) | border; ) | border;
}; };
// clang-format on
}; };
class Tab : public Component { class Tab : public Component {
public: public:
Container main_container = Container::Vertical(); Container main_container = Container::Vertical();
Toggle tab_selection; Toggle tab_selection;
Container container = Container::Tab(&tab_selection.selected); Container container = Container::Tab(&tab_selection.selected);
HTopComponent htop_component; HTopComponent htop_component;
ColorComponent color_component; ColorComponent color_component;
SpinnerComponent spinner_component; SpinnerComponent spinner_component;
GaugeComponent gauge_component; GaugeComponent gauge_component;
CompilerComponent compiler_component; CompilerComponent compiler_component;
Tab() { Tab() {
Add(&main_container); Add(&main_container);
main_container.Add(&tab_selection); main_container.Add(&tab_selection);
tab_selection.entries = { tab_selection.entries = {
L"htop", L"htop", L"color", L"spinner", L"gauge", L"compiler",
L"color", };
L"spinner", main_container.Add(&container);
L"gauge", container.Add(&htop_component);
L"compiler", container.Add(&color_component);
}; container.Add(&spinner_component);
main_container.Add(&container); container.Add(&gauge_component);
container.Add(&htop_component); container.Add(&compiler_component);
container.Add(&color_component); }
container.Add(&spinner_component);
container.Add(&gauge_component);
container.Add(&compiler_component);
}
Element Render() override { Element Render() override {
return vbox( return vbox(text(L"FTXUI Demo") | bold | hcenter,
text(L"FTXUI Demo") | bold | hcenter, tab_selection.Render() | hcenter, container.Render());
tab_selection.Render() | hcenter, }
container.Render()
);
}
}; };
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {

View File

@ -1,7 +1,8 @@
#include "ftxui/component/input.hpp"
#include <iostream> #include <iostream>
#include "ftxui/component/container.hpp" #include "ftxui/component/container.hpp"
#include "ftxui/component/input.hpp"
#include "ftxui/component/screen_interactive.hpp" #include "ftxui/component/screen_interactive.hpp"
#include "ftxui/screen/string.hpp" #include "ftxui/screen/string.hpp"
@ -28,6 +29,7 @@ class MyComponent : public Component {
Input input_2; Input input_2;
Input input_3; Input input_3;
// clang-format off
Element Render() override { Element Render() override {
return return
border( border(
@ -38,6 +40,7 @@ class MyComponent : public Component {
) )
); );
} }
// clang-format on
}; };
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {

View File

@ -1,8 +1,9 @@
#include "ftxui/component/menu.hpp"
#include <chrono> #include <chrono>
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include "ftxui/component/menu.hpp"
#include "ftxui/component/screen_interactive.hpp" #include "ftxui/component/screen_interactive.hpp"
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {

View File

@ -10,27 +10,33 @@
using namespace ftxui; using namespace ftxui;
class MyComponent : public Component { class MyComponent : public Component {
public: public:
MyComponent() { MyComponent() {
Add(&container); Add(&container);
container.Add(&left_menu); container.Add(&left_menu);
container.Add(&right_menu); container.Add(&right_menu);
left_menu.entries = {L"0%", L"10%", L"20%", L"30%", L"40%", L"50%", left_menu.entries = {
L"60%", L"70%", L"80%", L"90%"}; L"0%", L"10%", L"20%", L"30%", L"40%",
right_menu.entries = {L"0%", L"1%", L"2%", L"3%", L"4%", L"5%", L"50%", L"60%", L"70%", L"80%", L"90%",
L"6%", L"7%", L"8%", L"9%", L"10%"}; };
right_menu.entries = {
L"0%", L"1%", L"2%", L"3%", L"4%", L"5%",
L"6%", L"7%", L"8%", L"9%", L"10%",
};
left_menu.on_enter = [this]() { on_enter(); }; left_menu.on_enter = [this]() { on_enter(); };
right_menu.on_enter = [this]() { on_enter(); }; right_menu.on_enter = [this]() { on_enter(); };
} }
std::function<void()> on_enter = [](){}; std::function<void()> on_enter = []() {};
private:
Container container = Container::Horizontal();
Menu left_menu;
Menu right_menu;
private:
Container container = Container::Horizontal();
Menu left_menu;
Menu right_menu;
// clang-format off
Element Render() override { Element Render() override {
int sum = left_menu.selected * 10 + right_menu.selected; int sum = left_menu.selected * 10 + right_menu.selected;
return return
@ -61,10 +67,10 @@ class MyComponent : public Component {
) )
); );
} }
// clang-format on
}; };
int main(int argc, const char *argv[]) int main(int argc, const char* argv[]) {
{
auto screen = ScreenInteractive::TerminalOutput(); auto screen = ScreenInteractive::TerminalOutput();
MyComponent component; MyComponent component;
component.on_enter = screen.ExitLoopClosure(); component.on_enter = screen.ExitLoopClosure();

View File

@ -9,50 +9,48 @@
using namespace ftxui; using namespace ftxui;
class MyComponent : public Component { class MyComponent : public Component {
public: public:
MyComponent() { MyComponent() {
Add(&container); Add(&container);
for(Menu* menu : {&menu_1, &menu_2, &menu_3, &menu_4, &menu_5, &menu_6}) { for (Menu* menu : {&menu_1, &menu_2, &menu_3, &menu_4, &menu_5, &menu_6}) {
container.Add(menu); container.Add(menu);
menu->entries = { menu->entries = {
L"Monkey", L"Monkey", L"Dog", L"Cat", L"Bird", L"Elephant",
L"Dog", };
L"Cat", menu->on_enter = [this]() { on_enter(); };
L"Bird", }
L"Elephant",
};
menu->on_enter = [this]() { on_enter(); };
}
menu_2.selected_style = color(Color::Blue); menu_2.selected_style = color(Color::Blue);
menu_2.focused_style = bold | color(Color::Blue); menu_2.focused_style = bold | color(Color::Blue);
menu_3.selected_style = color(Color::Blue); menu_3.selected_style = color(Color::Blue);
menu_3.focused_style = bgcolor(Color::Blue); menu_3.focused_style = bgcolor(Color::Blue);
menu_4.selected_style = bgcolor(Color::Blue); menu_4.selected_style = bgcolor(Color::Blue);
menu_4.focused_style = bgcolor(Color::BlueLight); menu_4.focused_style = bgcolor(Color::BlueLight);
menu_5.normal_style = bgcolor(Color::Blue); menu_5.normal_style = bgcolor(Color::Blue);
menu_5.selected_style = bgcolor(Color::Yellow); menu_5.selected_style = bgcolor(Color::Yellow);
menu_5.focused_style = bgcolor(Color::Red); menu_5.focused_style = bgcolor(Color::Red);
menu_6.normal_style = dim | color(Color::Blue); menu_6.normal_style = dim | color(Color::Blue);
menu_6.selected_style = color(Color::Blue); menu_6.selected_style = color(Color::Blue);
menu_6.focused_style = bold | color(Color::Blue); menu_6.focused_style = bold | color(Color::Blue);
} }
std::function<void()> on_enter = [](){}; std::function<void()> on_enter = []() {};
private:
Container container = Container::Horizontal();
Menu menu_1;
Menu menu_2;
Menu menu_3;
Menu menu_4;
Menu menu_5;
Menu menu_6;
private:
Container container = Container::Horizontal();
Menu menu_1;
Menu menu_2;
Menu menu_3;
Menu menu_4;
Menu menu_5;
Menu menu_6;
// clang-format off
Element Render() override { Element Render() override {
return return
hbox( hbox(
@ -64,10 +62,10 @@ class MyComponent : public Component {
menu_6.Render() | flex menu_6.Render() | flex
) | border; ) | border;
} }
// clang-format on
}; };
int main(int argc, const char *argv[]) int main(int argc, const char* argv[]) {
{
auto screen = ScreenInteractive::TerminalOutput(); auto screen = ScreenInteractive::TerminalOutput();
MyComponent component; MyComponent component;
component.on_enter = screen.ExitLoopClosure(); component.on_enter = screen.ExitLoopClosure();

View File

@ -1,4 +1,5 @@
#include "ftxui/component/radiobox.hpp" #include "ftxui/component/radiobox.hpp"
#include "ftxui/component/component.hpp" #include "ftxui/component/component.hpp"
#include "ftxui/component/container.hpp" #include "ftxui/component/container.hpp"
#include "ftxui/component/screen_interactive.hpp" #include "ftxui/component/screen_interactive.hpp"

View File

@ -14,7 +14,7 @@ class MyComponent : public Component {
public: public:
MyComponent() { MyComponent() {
for(int i = 0; i<30; ++i) { for (int i = 0; i < 30; ++i) {
radiobox.entries.push_back(L"RadioBox " + to_wstring(i)); radiobox.entries.push_back(L"RadioBox " + to_wstring(i));
} }
Add(&radiobox); Add(&radiobox);

View File

@ -44,13 +44,9 @@ class MyComponent : public Component {
std::function<void()> on_enter = []() {}; std::function<void()> on_enter = []() {};
Element Render(){ Element Render() {
return return vbox(toggle_.Render(), separator(), tab_container_.Render()) |
vbox( border;
toggle_.Render(),
separator(),
tab_container_.Render()
) | border;
} }
private: private:

View File

@ -1,10 +1,11 @@
#include "ftxui/component/toggle.hpp"
#include <chrono> #include <chrono>
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include "ftxui/component/container.hpp" #include "ftxui/component/container.hpp"
#include "ftxui/component/screen_interactive.hpp" #include "ftxui/component/screen_interactive.hpp"
#include "ftxui/component/toggle.hpp"
#include "ftxui/screen/string.hpp" #include "ftxui/screen/string.hpp"
using namespace ftxui; using namespace ftxui;
@ -33,6 +34,7 @@ class MyComponent : public Component {
Toggle toggle_3_; Toggle toggle_3_;
Toggle toggle_4_; Toggle toggle_4_;
// clang-format off
Element Render() override { Element Render() override {
return return
vbox( vbox(
@ -44,6 +46,7 @@ class MyComponent : public Component {
hbox(text(L" * Number of elements : "), toggle_4_.Render()) hbox(text(L" * Number of elements : "), toggle_4_.Render())
); );
} }
// clang-format on
}; };
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {

View File

@ -2,12 +2,12 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/screen/screen.hpp"
int main(int argc, const char *argv[]) int main(int argc, const char* argv[]) {
{
using namespace ftxui; using namespace ftxui;
// clang-format off
auto document = auto document =
hbox( hbox(
window(text(L" main frame ") | hcenter, window(text(L" main frame ") | hcenter,
@ -41,6 +41,7 @@ int main(int argc, const char *argv[])
), ),
filler() filler()
); );
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());
std::cout << screen.ToString() << std::endl; std::cout << screen.ToString() << std::endl;

View File

@ -1,10 +1,11 @@
#include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) #include "ftxui/dom/elements.hpp"
{ #include "ftxui/screen/screen.hpp"
int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off
auto document = auto document =
dbox( dbox(
vbox( vbox(
@ -16,6 +17,7 @@ int main(int argc, const char *argv[])
) | border, ) | border,
text(L"overlay") | border | center text(L"overlay") | border | center
); );
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -2,24 +2,25 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/screen/screen.hpp"
int main(int argc, const char *argv[]) int main(int argc, const char* argv[]) {
{
using namespace ftxui; using namespace ftxui;
using namespace std::chrono_literals; using namespace std::chrono_literals;
std::string reset_position; 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";
// clang-format off
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)
); );
// clang-format on
auto screen = Screen(100, 1); auto screen = Screen(100, 1);
Render(screen, document.get()); Render(screen, document.get());
std::cout << reset_position << screen.ToString() << std::flush; std::cout << reset_position << screen.ToString() << std::flush;

View File

@ -2,6 +2,7 @@
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/screen/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "ftxui/screen/string.hpp" #include "ftxui/screen/string.hpp"
@ -13,7 +14,7 @@ class Graph {
for (int i = 0; i < width; ++i) { for (int i = 0; i < width; ++i) {
float v = 0; float v = 0;
v += 0.1 * sin((i + shift) * 0.1); v += 0.1 * sin((i + shift) * 0.1);
v += 0.2 * sin((i + shift+10) * 0.15); v += 0.2 * sin((i + shift + 10) * 0.15);
v += 0.1 * sin((i + shift) * 0.03); v += 0.1 * sin((i + shift) * 0.03);
v *= height; v *= height;
v += 0.5 * height; v += 0.5 * height;
@ -40,6 +41,7 @@ int main(int argc, const char* argv[]) {
std::string reset_position; std::string reset_position;
for (int i = 0;; ++i) { for (int i = 0;; ++i) {
// clang-format off
auto document = auto document =
hbox( hbox(
vbox( vbox(
@ -55,6 +57,7 @@ int main(int argc, const char* argv[]) {
) )
| border | border
| size(HEIGHT, GREATER_THAN, 40); | size(HEIGHT, GREATER_THAN, 40);
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -1,47 +1,32 @@
#include "ftxui/screen/screen.hpp"
#include "ftxui/screen/string.hpp"
#include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) #include "ftxui/dom/elements.hpp"
{ #include "ftxui/screen/screen.hpp"
#include "ftxui/screen/string.hpp"
int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
auto make_box = [](size_t dimx, size_t dimy) { auto make_box = [](size_t dimx, size_t dimy) {
std::wstring title = to_wstring(dimx) + L"x" + to_wstring(dimy); std::wstring title = to_wstring(dimx) + L"x" + to_wstring(dimy);
return // clang-format off
window( return window(text(title) | hcenter | bold,
text(title) | hcenter | bold, text(L"content") | hcenter | dim) |
text(L"content") | hcenter | dim size(WIDTH, EQUAL, dimx) | size(HEIGHT, EQUAL, dimy);
) | size(WIDTH, EQUAL, dimx) // clang-format on
| size(HEIGHT, EQUAL, dimy)
;
}; };
// clang-format off
auto document = auto document =
hflow( hflow(make_box(7, 7), make_box(7, 5), make_box(5, 7), make_box(10, 4),
make_box(7,7), make_box(10, 4), make_box(10, 4), make_box(10, 4), make_box(11, 4),
make_box(7,5), make_box(11, 4), make_box(11, 4), make_box(11, 4), make_box(12, 4),
make_box(5,7), make_box(12, 5), make_box(12, 4), make_box(13, 4), make_box(13, 3),
make_box(10,4), make_box(13, 3), make_box(10, 3))
make_box(10,4), | size(WIDTH, GREATER_THAN, 20)
make_box(10,4),
make_box(10,4),
make_box(11,4),
make_box(11,4),
make_box(11,4),
make_box(11,4),
make_box(12,4),
make_box(12,5),
make_box(12,4),
make_box(13,4),
make_box(13,3),
make_box(13,3),
make_box(10,3)
) | size(WIDTH, GREATER_THAN, 20)
| border | border
| size(HEIGHT, GREATER_THAN, 30) | size(HEIGHT, GREATER_THAN, 30)
| size(WIDTH, LESS_THAN, 50) | size(WIDTH, LESS_THAN, 50);
; // clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -1,6 +1,7 @@
#include <chrono> #include <chrono>
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/screen/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "ftxui/screen/string.hpp" #include "ftxui/screen/string.hpp"

View File

@ -1,15 +1,14 @@
#include <chrono> #include <chrono>
#include <iostream> #include <iostream>
#include <list>
#include <thread> #include <thread>
#include <vector>
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/screen/screen.hpp" #include "ftxui/screen/screen.hpp"
#include "ftxui/screen/string.hpp" #include "ftxui/screen/string.hpp"
#include <list>
#include <vector>
int main(int argc, const char *argv[]) int main(int argc, const char* argv[]) {
{
using namespace ftxui; using namespace ftxui;
struct Task { struct Task {
@ -46,6 +45,7 @@ int main(int argc, const char *argv[])
return text(to_wstring(number)) | size(WIDTH, EQUAL, 3); return text(to_wstring(number)) | size(WIDTH, EQUAL, 3);
}; };
// clang-format off
auto renderTask = [&](const Task& task) { auto renderTask = [&](const Task& task) {
auto style = (task.downloaded == task.size) ? dim : bold; auto style = (task.downloaded == task.size) ? dim : bold;
return return
@ -87,9 +87,10 @@ int main(int argc, const char *argv[])
hbox(renderSummary(), filler()) hbox(renderSummary(), filler())
); );
}; };
// clang-format on
auto updateModel = [&](){ auto updateModel = [&]() {
for(auto& task : displayed_task) { for (auto& task : displayed_task) {
if (task.downloaded != task.size) { if (task.downloaded != task.size) {
task.downloaded++; task.downloaded++;
} else if (task.number_of_threads) { } else if (task.number_of_threads) {
@ -111,8 +112,7 @@ int main(int argc, const char *argv[])
}; };
std::string reset_position; std::string reset_position;
for(;;) { for (;;) {
// Draw. // Draw.
auto document = render(); auto document = render();
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));

View File

@ -1,13 +1,15 @@
#include "ftxui/screen/screen.hpp"
#include "ftxui/screen/string.hpp"
#include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) #include "ftxui/dom/elements.hpp"
{ #include "ftxui/screen/screen.hpp"
using namespace ftxui; #include "ftxui/screen/string.hpp"
std::wstring p = LR"(In probability theory and statistics, Bayes' theorem (alternatively Bayes' law or Bayes' rule) describes the probability of an event, based on prior knowledge of conditions that might be related to the event. For example, if cancer is related to age, then, using Bayes' theorem, a person's age can be used to more accurately assess the probability that they have cancer, compared to the assessment of the probability of cancer made without knowledge of the person's age. One of the many applications of Bayes' theorem is Bayesian inference, a particular approach to statistical inference. When applied, the probabilities involved in Bayes' theorem may have different probability interpretations. With the Bayesian probability interpretation the theorem expresses how a subjective degree of belief should rationally change to account for availability of related evidence. Bayesian inference is fundamental to Bayesian statistics.)";
int main(int argc, const char* argv[]) {
using namespace ftxui;
std::wstring p =
LR"(In probability theory and statistics, Bayes' theorem (alternatively Bayes' law or Bayes' rule) describes the probability of an event, based on prior knowledge of conditions that might be related to the event. For example, if cancer is related to age, then, using Bayes' theorem, a person's age can be used to more accurately assess the probability that they have cancer, compared to the assessment of the probability of cancer made without knowledge of the person's age. One of the many applications of Bayes' theorem is Bayesian inference, a particular approach to statistical inference. When applied, the probabilities involved in Bayes' theorem may have different probability interpretations. With the Bayesian probability interpretation the theorem expresses how a subjective degree of belief should rationally change to account for availability of related evidence. Bayesian inference is fundamental to Bayesian statistics.)";
// clang-format off
auto document = auto document =
vbox( vbox(
hbox( hbox(
@ -23,6 +25,7 @@ int main(int argc, const char *argv[])
hflow(paragraph(p)) | border hflow(paragraph(p)) | border
) | flex ) | flex
); );
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -1,10 +1,11 @@
#include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) #include "ftxui/dom/elements.hpp"
{ #include "ftxui/screen/screen.hpp"
int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off
auto document = auto document =
hbox( hbox(
text(L"left-column"), text(L"left-column"),
@ -17,6 +18,7 @@ int main(int argc, const char *argv[])
separator(), separator(),
text(L"right-column") text(L"right-column")
) | border; ) | border;
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -1,11 +1,12 @@
#include "ftxui/screen/screen.hpp"
#include "ftxui/screen/string.hpp"
#include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) #include "ftxui/dom/elements.hpp"
{ #include "ftxui/screen/screen.hpp"
#include "ftxui/screen/string.hpp"
int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off
auto make_box = [](const std::wstring title) { auto make_box = [](const std::wstring title) {
return return
window( window(
@ -21,6 +22,7 @@ int main(int argc, const char *argv[])
| size(WIDTH, EQUAL, x) | size(WIDTH, EQUAL, x)
); );
} }
// clang-format on
auto document = hbox(std::move(content)); auto document = hbox(std::move(content));
auto screen = Screen::Create(Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -17,6 +17,7 @@ int main(int argc, const char *argv[])
for(int i = 0; i<22; ++i) { for(int i = 0; i<22; ++i) {
if (i != 0) if (i != 0)
entries.push_back(separator()); entries.push_back(separator());
// clang-format off
entries.push_back( entries.push_back(
hbox( hbox(
text(to_wstring(i)) | size(WIDTH, EQUAL, 2), text(to_wstring(i)) | size(WIDTH, EQUAL, 2),
@ -24,6 +25,7 @@ int main(int argc, const char *argv[])
spinner(i, index) | bold spinner(i, index) | bold
) )
); );
// clang-format on
} }
auto document = hbox(vbox(std::move(entries)) | border, filler()); auto document = hbox(vbox(std::move(entries)) | border, filler());
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));

View File

@ -1,16 +1,18 @@
#include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) #include "ftxui/dom/elements.hpp"
{ #include "ftxui/screen/screen.hpp"
int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off
auto document = auto document =
hbox( hbox(
text(L"This text is "), text(L"This text is "),
text(L"blink") | blink, text(L"blink") | blink,
text(L". Do you like it?") text(L". Do you like it?")
); );
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -1,16 +1,18 @@
#include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) #include "ftxui/dom/elements.hpp"
{ #include "ftxui/screen/screen.hpp"
int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off
auto document = auto document =
hbox( hbox(
text(L"This text is "), text(L"This text is "),
text(L"bold") | bold, text(L"bold") | bold,
text(L". Do you like it?") text(L". Do you like it?")
); );
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -1,10 +1,11 @@
#include "ftxui/screen/screen.hpp"
#include "ftxui/dom/elements.hpp"
#include <iostream> #include <iostream>
int main(int argc, const char *argv[]) #include "ftxui/dom/elements.hpp"
{ #include "ftxui/screen/screen.hpp"
int main(int argc, const char* argv[]) {
using namespace ftxui; using namespace ftxui;
// clang-format off
auto document = auto document =
hbox( hbox(
vbox( vbox(
@ -47,6 +48,7 @@ int main(int argc, const char *argv[])
), ),
filler() filler()
); );
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -5,12 +5,14 @@
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui; using namespace ftxui;
// clang-format off
auto document = auto document =
hbox( hbox(
text(L"This text is "), text(L"This text is "),
text(L"dim") | dim, text(L"dim") | dim,
text(L". Do you like it?") text(L". Do you like it?")
); );
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -5,6 +5,7 @@
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui; using namespace ftxui;
// clang-format off
auto document = auto document =
hbox( hbox(
text(L"normal") , text(L" ") , text(L"normal") , text(L" ") ,
@ -16,6 +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)
); );
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -5,12 +5,14 @@
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui; using namespace ftxui;
// clang-format off
auto document = auto document =
hbox( hbox(
text(L"This text is "), text(L"This text is "),
text(L"inverted") | inverted, text(L"inverted") | inverted,
text(L". Do you like it?") text(L". Do you like it?")
); );
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -5,12 +5,14 @@
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui; using namespace ftxui;
// clang-format off
auto document = auto document =
hbox( hbox(
text(L"This text is "), text(L"This text is "),
text(L"underlined") | underlined, text(L"underlined") | underlined,
text(L". Do you like it?") text(L". Do you like it?")
); );
// clang-format on
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document.get()); Render(screen, document.get());

View File

@ -6,6 +6,7 @@
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui; using namespace ftxui;
// clang-format off
auto document = auto document =
vbox( vbox(
hbox( hbox(
@ -28,6 +29,7 @@ int main(int argc, const char *argv[])
text(L"south-east") text(L"south-east")
) )
); );
// clang-format on
auto screen = Screen::Create(Dimension::Full()); auto screen = Screen::Create(Dimension::Full());
Render(screen, document.get()); Render(screen, document.get());

View File

@ -1,4 +1,5 @@
#include "ftxui/component/checkbox.hpp" #include "ftxui/component/checkbox.hpp"
#include <functional> #include <functional>
namespace ftxui { namespace ftxui {
@ -17,7 +18,7 @@ bool CheckBox::OnEvent(Event event) {
on_change(); on_change();
return true; return true;
} }
return false; return false;
} }
} // namespace ftxui } // namespace ftxui

View File

@ -1,11 +1,16 @@
#include "ftxui/component/component.hpp" #include "ftxui/component/component.hpp"
#include <assert.h> #include <assert.h>
#include <algorithm>
namespace ftxui { namespace ftxui {
void Component::Detach() { if (!parent_) return; auto it = std::find(std::begin(parent_->children_), void Component::Detach() {
if (!parent_)
return;
auto it = std::find(std::begin(parent_->children_),
std::end(parent_->children_), this); std::end(parent_->children_), this);
parent_->children_.erase(it); parent_->children_.erase(it);
} }
void Component::Attach(Component* parent) { void Component::Attach(Component* parent) {
@ -23,7 +28,7 @@ Component::~Component() {
} }
bool Component::OnEvent(Event event) { bool Component::OnEvent(Event event) {
for(Component* child : children_) { for (Component* child : children_) {
if (child->OnEvent(event)) if (child->OnEvent(event))
return true; return true;
} }
@ -43,7 +48,7 @@ Element Component::Render() {
bool Component::Focused() { bool Component::Focused() {
Component* current = this; Component* current = this;
for(;;) { for (;;) {
Component* parent = current->parent_; Component* parent = current->parent_;
if (!parent) if (!parent)
return true; return true;

View File

@ -1,5 +1,7 @@
#include "ftxui/component/container.hpp" #include "ftxui/component/container.hpp"
#include <algorithm>
namespace ftxui { namespace ftxui {
// static // static

View File

@ -1,5 +1,7 @@
#include <iostream>
#include "ftxui/component/event.hpp" #include "ftxui/component/event.hpp"
#include <iostream>
#include "ftxui/screen/string.hpp" #include "ftxui/screen/string.hpp"
namespace ftxui { namespace ftxui {
@ -49,7 +51,7 @@ Event ParseCSI(std::function<char()> getchar, std::string& input) {
char c = getchar(); char c = getchar();
input += c; input += c;
if (c >= '0' && c<= '9') if (c >= '0' && c <= '9')
continue; continue;
if (c == ';') if (c == ';')
@ -93,9 +95,12 @@ Event ParseOSC(std::function<char()> getchar, std::string& input) {
Event ParseESC(std::function<char()> getchar, std::string& input) { Event ParseESC(std::function<char()> getchar, std::string& input) {
input += getchar(); input += getchar();
switch (input.back()) { switch (input.back()) {
case 'P': return ParseDCS(getchar, input); case 'P':
case '[': return ParseCSI(getchar, input); return ParseDCS(getchar, input);
case ']': return ParseOSC(getchar, input); case '[':
return ParseCSI(getchar, input);
case ']':
return ParseOSC(getchar, input);
default: default:
input += getchar(); input += getchar();
return Event::Special(input); return Event::Special(input);

View File

@ -1,5 +1,6 @@
#include "ftxui/component/input.hpp" #include "ftxui/component/input.hpp"
#include "ftxui/screen/string.hpp" #include "ftxui/screen/string.hpp"
#include <algorithm>
namespace ftxui { namespace ftxui {
@ -31,13 +32,14 @@ Element Input::Render() {
auto focused = auto focused =
is_focused ? focus : select; is_focused ? focus : select;
// clang-format off
return return
hbox( hbox(
text(part_before_cursor), text(part_before_cursor),
text(part_at_cursor) | underlined | focused, text(part_at_cursor) | underlined | focused,
text(part_after_cursor) text(part_after_cursor)
) | flex | inverted | frame | main_decorator; ) | flex | inverted | frame | main_decorator;
// clang-format off
} }
bool Input::OnEvent(Event event) { bool Input::OnEvent(Event event) {
cursor_position = std::max(0, std::min<int>(content.size(), cursor_position)); cursor_position = std::max(0, std::min<int>(content.size(), cursor_position));

View File

@ -1,6 +1,7 @@
#include "ftxui/component/menu.hpp" #include "ftxui/component/menu.hpp"
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
#include <algorithm>
namespace ftxui { namespace ftxui {

View File

@ -1,5 +1,6 @@
#include "ftxui/component/radiobox.hpp" #include "ftxui/component/radiobox.hpp"
#include <functional> #include <functional>
#include <algorithm>
namespace ftxui { namespace ftxui {

View File

@ -10,6 +10,7 @@
#include "ftxui/component/component.hpp" #include "ftxui/component/component.hpp"
#include "ftxui/screen/string.hpp" #include "ftxui/screen/string.hpp"
#include "ftxui/screen/terminal.hpp" #include "ftxui/screen/terminal.hpp"
#include <algorithm>
#if defined(__clang__) && defined (__APPLE__) #if defined(__clang__) && defined (__APPLE__)
// Quick exit is missing in standard CLang headers // Quick exit is missing in standard CLang headers

View File

@ -1,4 +1,5 @@
#include "ftxui/component/toggle.hpp" #include "ftxui/component/toggle.hpp"
#include <algorithm>
namespace ftxui { namespace ftxui {

View File

@ -1,5 +1,5 @@
#include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node_decorator.hpp"
namespace ftxui { namespace ftxui {

View File

@ -1,5 +1,5 @@
#include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node_decorator.hpp"
namespace ftxui { namespace ftxui {
@ -11,7 +11,7 @@ class Bold : public NodeDecorator {
void Render(Screen& screen) override { void Render(Screen& screen) override {
for (int y = box_.y_min; y <= box_.y_max; ++y) { for (int y = box_.y_min; y <= box_.y_max; ++y) {
for (int x = box_.x_min; x <= box_.x_max; ++x) { for (int x = box_.x_min; x <= box_.x_max; ++x) {
screen.PixelAt(x,y).bold = true; screen.PixelAt(x, y).bold = true;
} }
} }
Node::Render(screen); Node::Render(screen);

View File

@ -1,5 +1,5 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp"
namespace ftxui { namespace ftxui {
@ -17,7 +17,7 @@ class Border : public Node {
: Node(std::move(children)), charset_pixel(10, pixel) {} : Node(std::move(children)), charset_pixel(10, pixel) {}
~Border() override {} ~Border() override {}
std::vector<Pixel> charset_pixel; std::vector<Pixel> charset_pixel;
std::vector<wchar_t> charset; std::vector<wchar_t> charset;
void ComputeRequirement() override { void ComputeRequirement() override {
@ -71,13 +71,13 @@ class Border : public Node {
screen.at(box_.x_max, box_.y_min) = charset[1]; screen.at(box_.x_max, box_.y_min) = charset[1];
screen.at(box_.x_min, box_.y_max) = charset[2]; screen.at(box_.x_min, box_.y_max) = charset[2];
screen.at(box_.x_max, box_.y_max) = charset[3]; screen.at(box_.x_max, box_.y_max) = charset[3];
for(float x = box_.x_min + 1; x<box_.x_max; ++x) { for (float x = box_.x_min + 1; x < box_.x_max; ++x) {
screen.at(x, box_.y_min) = charset[4]; screen.at(x, box_.y_min) = charset[4];
screen.at(x, box_.y_max) = charset[4]; screen.at(x, box_.y_max) = charset[4];
} }
for(float y = box_.y_min + 1; y<box_.y_max; ++y) { for (float y = box_.y_min + 1; y < box_.y_max; ++y) {
screen.at(box_.x_min, y) = charset[5]; screen.at(box_.x_min, y) = charset[5];
screen.at(box_.x_max,y) = charset[5]; screen.at(box_.x_max, y) = charset[5];
} }
// Draw title. // Draw title.
@ -90,13 +90,13 @@ class Border : public Node {
screen.PixelAt(box_.x_max, box_.y_min) = charset_pixel[1]; screen.PixelAt(box_.x_max, box_.y_min) = charset_pixel[1];
screen.PixelAt(box_.x_min, box_.y_max) = charset_pixel[2]; screen.PixelAt(box_.x_min, box_.y_max) = charset_pixel[2];
screen.PixelAt(box_.x_max, box_.y_max) = charset_pixel[3]; screen.PixelAt(box_.x_max, box_.y_max) = charset_pixel[3];
for(float x = box_.x_min + 1; x<box_.x_max; ++x) { for (float x = box_.x_min + 1; x < box_.x_max; ++x) {
screen.PixelAt(x, box_.y_min) = charset_pixel[4]; screen.PixelAt(x, box_.y_min) = charset_pixel[4];
screen.PixelAt(x, box_.y_max) = charset_pixel[4]; screen.PixelAt(x, box_.y_max) = charset_pixel[4];
} }
for(float y = box_.y_min + 1; y<box_.y_max; ++y) { for (float y = box_.y_min + 1; y < box_.y_max; ++y) {
screen.PixelAt(box_.x_min, y) = charset_pixel[5]; screen.PixelAt(box_.x_min, y) = charset_pixel[5];
screen.PixelAt(box_.x_max,y) = charset_pixel[5]; screen.PixelAt(box_.x_max, y) = charset_pixel[5];
} }
} }
}; };

View File

@ -1,5 +1,5 @@
#include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node_decorator.hpp"
namespace ftxui { namespace ftxui {
@ -47,15 +47,11 @@ std::unique_ptr<Node> bgcolor(Color c, Element child) {
} }
Decorator color(Color c) { Decorator color(Color c) {
return [c](Element child) { return [c](Element child) { return color(c, std::move(child)); };
return color(c, std::move(child));
};
} }
Decorator bgcolor(Color c) { Decorator bgcolor(Color c) {
return [c](Element child) { return [c](Element child) { return bgcolor(c, std::move(child)); };
return bgcolor(c, std::move(child));
};
} }
} // namespace ftxui } // namespace ftxui

View File

@ -1,5 +1,5 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp"
namespace ftxui { namespace ftxui {
@ -19,4 +19,4 @@ std::unique_ptr<Node> align_right(Element child) {
return hbox(filler(), std::move(child)); return hbox(filler(), std::move(child));
} }
} // namespace ftxui } // namespace ftxui

View File

@ -1,5 +1,5 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp"
namespace ftxui { namespace ftxui {
@ -15,8 +15,10 @@ class DBox : public Node {
requirement_.flex.y = 0; requirement_.flex.y = 0;
for (auto& child : children) { for (auto& child : children) {
child->ComputeRequirement(); child->ComputeRequirement();
requirement_.min.x = std::max(requirement_.min.x, child->requirement().min.x); requirement_.min.x =
requirement_.min.y = std::max(requirement_.min.y, child->requirement().min.y); std::max(requirement_.min.x, child->requirement().min.x);
requirement_.min.y =
std::max(requirement_.min.y, child->requirement().min.y);
if (requirement_.selection < child->requirement().selection) { if (requirement_.selection < child->requirement().selection) {
requirement_.selection = child->requirement().selection; requirement_.selection = child->requirement().selection;

View File

@ -1,5 +1,5 @@
#include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node_decorator.hpp"
namespace ftxui { namespace ftxui {
@ -14,7 +14,7 @@ class Dim : public NodeDecorator {
Node::Render(screen); Node::Render(screen);
for (int y = box_.y_min; y <= box_.y_max; ++y) { for (int y = box_.y_min; y <= box_.y_max; ++y) {
for (int x = box_.x_min; x <= box_.x_max; ++x) { for (int x = box_.x_min; x <= box_.x_max; ++x) {
screen.PixelAt(x,y).dim = true; screen.PixelAt(x, y).dim = true;
} }
} }
} }

View File

@ -1,5 +1,5 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp"
namespace ftxui { namespace ftxui {

View File

@ -1,3 +1,5 @@
#include <algorithm>
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include "ftxui/util/autoreset.hpp" #include "ftxui/util/autoreset.hpp"

View File

@ -1,5 +1,5 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp"
namespace ftxui { namespace ftxui {
@ -24,10 +24,11 @@ class Gauge : public Node {
int x = box_.x_min; int x = box_.x_min;
while (x < limit_int) while (x < limit_int)
screen.at(x++, y) = charset[9]; screen.at(x++, y) = charset[9];
screen.at(x++, y) = charset[int(9*(limit-limit_int))]; screen.at(x++, y) = charset[int(9 * (limit - limit_int))];
while (x <= box_.x_max) while (x <= box_.x_max)
screen.at(x++, y) = charset[0]; screen.at(x++, y) = charset[0];
} }
private: private:
float progress_; float progress_;
}; };

View File

@ -1,5 +1,7 @@
#include "ftxui/dom/node.hpp" #include <algorithm>
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp"
namespace ftxui { namespace ftxui {

View File

@ -1,5 +1,5 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp"
namespace ftxui { namespace ftxui {
@ -13,7 +13,7 @@ class HFlow : public Node {
requirement_.min.y = 0; requirement_.min.y = 0;
requirement_.flex.x = 1; requirement_.flex.x = 1;
requirement_.flex.y = 1; requirement_.flex.y = 1;
for(auto& child : children) for (auto& child : children)
child->ComputeRequirement(); child->ComputeRequirement();
} }
@ -23,7 +23,7 @@ class HFlow : public Node {
// The position of the first component. // The position of the first component.
int x = box.x_min; int x = box.x_min;
int y = box.y_min; int y = box.y_min;
int y_next = y; // The position of next row of elements. int y_next = y; // The position of next row of elements.
for (auto& child : children) { for (auto& child : children) {
Requirement requirement = child->requirement(); Requirement requirement = child->requirement();
@ -37,7 +37,7 @@ class HFlow : public Node {
// Does the current row big enough to contain the element? // Does the current row big enough to contain the element?
if (y + requirement.min.y > box.y_max + 1) if (y + requirement.min.y > box.y_max + 1)
break; // No? Ignore the element. break; // No? Ignore the element.
Box children_box; Box children_box;
children_box.x_min = x; children_box.x_min = x;

View File

@ -1,5 +1,5 @@
#include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node_decorator.hpp"
namespace ftxui { namespace ftxui {
@ -14,7 +14,7 @@ class Inverted : public NodeDecorator {
Node::Render(screen); Node::Render(screen);
for (int y = box_.y_min; y <= box_.y_max; ++y) { for (int y = box_.y_min; y <= box_.y_max; ++y) {
for (int x = box_.x_min; x <= box_.x_max; ++x) { for (int x = box_.x_min; x <= box_.x_max; ++x) {
screen.PixelAt(x,y).inverted = true; screen.PixelAt(x, y).inverted = true;
} }
} }
} }

View File

@ -10,7 +10,7 @@ Node::Node(std::vector<std::unique_ptr<Node>> children)
Node::~Node() {} Node::~Node() {}
void Node::ComputeRequirement() { void Node::ComputeRequirement() {
for(auto& child : children) for (auto& child : children)
child->ComputeRequirement(); child->ComputeRequirement();
} }
@ -19,20 +19,20 @@ void Node::SetBox(Box box) {
} }
void Node::Render(Screen& screen) { void Node::Render(Screen& screen) {
for(auto& child : children) for (auto& child : children)
child->Render(screen); child->Render(screen);
} }
void Render(Screen& screen, Node* node) { void Render(Screen& screen, Node* node) {
// Step 1: Find what dimension this elements wants to be. // Step 1: Find what dimension this elements wants to be.
node->ComputeRequirement(); node->ComputeRequirement();
Box box; Box box;
box.x_min = 0; box.x_min = 0;
box.y_min = 0; box.y_min = 0;
box.x_max = screen.dimx() - 1; box.x_max = screen.dimx() - 1;
box.y_max = screen.dimy() - 1; box.y_max = screen.dimy() - 1;
// Step 2: Assign a dimension to the element. // Step 2: Assign a dimension to the element.
node->SetBox(box); node->SetBox(box);
screen.stencil = box; screen.stencil = box;

View File

@ -1,8 +1,8 @@
#ifndef FTXUI_DOM_NODE_DECORATOR_H_ #ifndef FTXUI_DOM_NODE_DECORATOR_H_
#define FTXUI_DOM_NODE_DECORATOR_H_ #define FTXUI_DOM_NODE_DECORATOR_H_
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp"
namespace ftxui { namespace ftxui {

View File

@ -1,4 +1,5 @@
#include <sstream> #include <sstream>
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
namespace ftxui { namespace ftxui {

View File

@ -1,3 +1,5 @@
#include <algorithm>
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
@ -41,7 +43,7 @@ class Size : public Node {
Node::SetBox(box); Node::SetBox(box);
if (direction_ == WIDTH) { if (direction_ == WIDTH) {
switch(constraint_) { switch (constraint_) {
case LESS_THAN: case LESS_THAN:
case EQUAL: case EQUAL:
box.x_max = std::min(box.x_min + value_ + 1, box.x_max); box.x_max = std::min(box.x_min + value_ + 1, box.x_max);
@ -50,7 +52,7 @@ class Size : public Node {
break; break;
} }
} else { } else {
switch(constraint_) { switch (constraint_) {
case LESS_THAN: case LESS_THAN:
case EQUAL: case EQUAL:
box.y_max = std::min(box.y_min + value_ + 1, box.y_max); box.y_max = std::min(box.y_min + value_ + 1, box.y_max);

View File

@ -1,277 +1,259 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp"
namespace ftxui { namespace ftxui {
using namespace ftxui; using namespace ftxui;
static const std::vector<std::vector<std::vector<std::wstring>>> elements = { static const std::vector<std::vector<std::vector<std::wstring>>> elements = {
{
{L"Replaced by the gauge"},
},
{
{L". "},
{L".. "},
{L"..."},
},
{
{L"|"},
{L"/"},
{L"-"},
{L"\\"},
},
{
{L"+"},
{L"x"},
},
{
{L"| "},
{L"|| "},
{L"|||"},
},
{
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
},
{
{L"(*----------)"},
{L"(-*---------)"},
{L"(--*--------)"},
{L"(---*-------)"},
{L"(----*------)"},
{L"(-----*-----)"},
{L"(------*----)"},
{L"(-------*---)"},
{L"(--------*--)"},
{L"(---------*-)"},
{L"(----------*)"},
{L"(---------*-)"},
{L"(--------*--)"},
{L"(-------*---)"},
{L"(------*----)"},
{L"(-----*-----)"},
{L"(----*------)"},
{L"(---*-------)"},
{L"(--*--------)"},
{L"(-*---------)"},
},
{
{L"[ ]"},
{L"[= ]"},
{L"[== ]"},
{L"[=== ]"},
{L"[==== ]"},
{L"[===== ]"},
{L"[======]"},
{L"[===== ]"},
{L"[==== ]"},
{L"[=== ]"},
{L"[== ]"},
{L"[= ]"},
},
{
{L"[ ]"},
{L"[= ]"},
{L"[== ]"},
{L"[=== ]"},
{L"[==== ]"},
{L"[===== ]"},
{L"[======]"},
{L"[ =====]"},
{L"[ ====]"},
{L"[ ===]"},
{L"[ ==]"},
{L"[ =]"},
},
{
{L"[== ]"},
{L"[== ]"},
{L"[== ]"},
{L"[== ]"},
{L"[== ]"},
{L" [== ]"},
{L"[ == ]"},
{L"[ == ]"},
{L"[ ==]"},
{L"[ ==]"},
{L"[ ==]"},
{L"[ ==]"},
{L"[ ==]"},
{L"[ ==] "},
{L"[ == ]"},
{L"[ == ]"},
},
{
{ {
L" ─╮", {L"Replaced by the gauge"},
L"",
L" ",
}, },
{ {
L" ", {L". "},
L"", {L".. "},
L"", {L"..."},
}, },
{ {
L" ", {L"|"},
L"", {L"/"},
L" ─╯", {L"-"},
{L"\\"},
}, },
{ {
L" ", {L"+"},
L" ", {L"x"},
L"╰─╯",
}, },
{ {
L" ", {L"| "},
L"", {L"|| "},
L"╰─ ", {L"|||"},
}, },
{ {
L"", {L""},
L"", {L""},
L"", {L""},
{L""},
{L""},
{L""},
{L""},
{L""},
}, },
{ {
L"╭─ ", {L""},
L"", {L""},
L" ", {L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
}, },
{ {
L"╭─╮", {L""},
L" ", {L""},
L" ", {L""},
} {L""},
}, {L""},
{ {L""},
{ {L""},
L" /\\O ", {L""},
L" /\\/ ", {L""},
L" /\\ ", {L""},
L" / \\ ", {L""},
L"LOL LOL", {L""},
}, },
{ {
L" _O ", {L""},
L" //|_ ", {L""},
L" | ", {L""},
L" /| ", {L""},
L" LLOL ",
}, },
{ {
L" O ", {L""},
L" /_ ", {L""},
L" |\\ ", {L""},
L" / | ", {L""},
L" LOLLOL ", },
} {
} {L""},
}; {L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
},
{
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
{L""},
},
{
{L"(*----------)"}, {L"(-*---------)"}, {L"(--*--------)"},
{L"(---*-------)"}, {L"(----*------)"}, {L"(-----*-----)"},
{L"(------*----)"}, {L"(-------*---)"}, {L"(--------*--)"},
{L"(---------*-)"}, {L"(----------*)"}, {L"(---------*-)"},
{L"(--------*--)"}, {L"(-------*---)"}, {L"(------*----)"},
{L"(-----*-----)"}, {L"(----*------)"}, {L"(---*-------)"},
{L"(--*--------)"}, {L"(-*---------)"},
},
{
{L"[ ]"},
{L"[= ]"},
{L"[== ]"},
{L"[=== ]"},
{L"[==== ]"},
{L"[===== ]"},
{L"[======]"},
{L"[===== ]"},
{L"[==== ]"},
{L"[=== ]"},
{L"[== ]"},
{L"[= ]"},
},
{
{L"[ ]"},
{L"[= ]"},
{L"[== ]"},
{L"[=== ]"},
{L"[==== ]"},
{L"[===== ]"},
{L"[======]"},
{L"[ =====]"},
{L"[ ====]"},
{L"[ ===]"},
{L"[ ==]"},
{L"[ =]"},
},
{
{L"[== ]"},
{L"[== ]"},
{L"[== ]"},
{L"[== ]"},
{L"[== ]"},
{L" [== ]"},
{L"[ == ]"},
{L"[ == ]"},
{L"[ ==]"},
{L"[ ==]"},
{L"[ ==]"},
{L"[ ==]"},
{L"[ ==]"},
{L"[ ==] "},
{L"[ == ]"},
{L"[ == ]"},
},
{{
L" ─╮",
L"",
L" ",
},
{
L"",
L"",
L"",
},
{
L" ",
L"",
L" ─╯",
},
{
L" ",
L" ",
L"╰─╯",
},
{
L" ",
L"",
L"╰─ ",
},
{
L"",
L"",
L"",
},
{
L"╭─ ",
L"",
L" ",
},
{
L"╭─╮",
L" ",
L" ",
}},
{{
L" /\\O ",
L" /\\/ ",
L" /\\ ",
L" / \\ ",
L"LOL LOL",
},
{
L" _O ",
L" //|_ ",
L" | ",
L" /| ",
L" LLOL ",
},
{
L" O ",
L" /_ ",
L" |\\ ",
L" / | ",
L" LOLLOL ",
}}};
std::unique_ptr<Node> spinner(int c, size_t index) { std::unique_ptr<Node> spinner(int c, size_t index) {
if (c == 0) { if (c == 0) {
index %= 40; index %= 40;
if (index > 20) if (index > 20)
index = 40-index; index = 40 - index;
return gauge(index * 0.05); return gauge(index * 0.05);
} }
c %= elements.size(); c %= elements.size();
index %= elements[c].size(); index %= elements[c].size();
std::vector<Element> lines; std::vector<Element> lines;
for(const auto& it : elements[c][index]) for (const auto& it : elements[c][index])
lines.push_back(text(it)); lines.push_back(text(it));
return vbox(std::move(lines)); return vbox(std::move(lines));
} }

View File

@ -1,5 +1,5 @@
#include "ftxui/dom/node_decorator.hpp"
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node_decorator.hpp"
namespace ftxui { namespace ftxui {

View File

@ -7,10 +7,7 @@ Element nothing(Element element) {
} }
Decorator compose(Decorator a, Decorator b) { Decorator compose(Decorator a, Decorator b) {
return [ return [a = std::move(a), b = std::move(b)](Element element) {
a = std::move(a),
b = std::move(b)
](Element element) {
return b(a(std::move(element))); return b(a(std::move(element)));
}; };
} }

View File

@ -1,3 +1,5 @@
#include <algorithm>
#include "ftxui/dom/elements.hpp" #include "ftxui/dom/elements.hpp"
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"

View File

@ -1,4 +1,5 @@
#include "ftxui/screen/box.hpp" #include "ftxui/screen/box.hpp"
#include <algorithm> #include <algorithm>
namespace ftxui { namespace ftxui {

View File

@ -1,10 +1,12 @@
#include "ftxui/screen/screen.hpp" #include "ftxui/screen/screen.hpp"
#include <algorithm>
#include <sstream>
#include "ftxui/dom/node.hpp" #include "ftxui/dom/node.hpp"
#include "ftxui/screen/string.hpp" #include "ftxui/screen/string.hpp"
#include "ftxui/screen/terminal.hpp" #include "ftxui/screen/terminal.hpp"
#include <sstream>
namespace ftxui { namespace ftxui {
namespace { namespace {

View File

@ -1,9 +1,10 @@
#include "ftxui/screen/terminal.hpp"
#include <stdio.h> #include <stdio.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <unistd.h> #include <unistd.h>
#include <iostream>
#include "ftxui/screen/terminal.hpp" #include <iostream>
namespace ftxui { namespace ftxui {

View File

@ -7,7 +7,7 @@ using namespace ftxui;
TEST(GaugeTest, zero) { TEST(GaugeTest, zero) {
auto root = gauge(0); auto root = gauge(0);
Screen screen(11,1); Screen screen(11, 1);
Render(screen, root.get()); Render(screen, root.get());
EXPECT_EQ(" ", screen.ToString()); EXPECT_EQ(" ", screen.ToString());
@ -15,7 +15,7 @@ TEST(GaugeTest, zero) {
TEST(GaugeTest, half) { TEST(GaugeTest, half) {
auto root = gauge(0.5); auto root = gauge(0.5);
Screen screen(11,1); Screen screen(11, 1);
Render(screen, root.get()); Render(screen, root.get());
EXPECT_EQ("█████▍ ", screen.ToString()); EXPECT_EQ("█████▍ ", screen.ToString());
@ -24,7 +24,7 @@ TEST(GaugeTest, half) {
TEST(GaugeTest, one) { TEST(GaugeTest, one) {
auto root = gauge(1.0); auto root = gauge(1.0);
Screen screen(11,1); Screen screen(11, 1);
Render(screen, root.get()); Render(screen, root.get());
EXPECT_EQ("███████████", screen.ToString()); EXPECT_EQ("███████████", screen.ToString());