diff --git a/examples/component/input.cpp b/examples/component/input.cpp index 1a521bd4..2238de10 100644 --- a/examples/component/input.cpp +++ b/examples/component/input.cpp @@ -2,18 +2,17 @@ #include #include -#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(); diff --git a/examples/component/menu.cpp b/examples/component/menu.cpp index 177bd74a..d9f84340 100644 --- a/examples/component/menu.cpp +++ b/examples/component/menu.cpp @@ -2,18 +2,15 @@ #include #include -#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(); diff --git a/examples/component/menu2.cpp b/examples/component/menu2.cpp index 50a7ba04..5e1da52f 100644 --- a/examples/component/menu2.cpp +++ b/examples/component/menu2.cpp @@ -2,10 +2,10 @@ #include #include -#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(); diff --git a/examples/component/menu_style.cpp b/examples/component/menu_style.cpp index 342e2e9f..dc7f8cac 100644 --- a/examples/component/menu_style.cpp +++ b/examples/component/menu_style.cpp @@ -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(); diff --git a/examples/component/tab.cpp b/examples/component/tab.cpp index 228aaa40..88375dc5 100644 --- a/examples/component/tab.cpp +++ b/examples/component/tab.cpp @@ -2,18 +2,17 @@ #include #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(); diff --git a/examples/component/toggle.cpp b/examples/component/toggle.cpp index 8a6d0fd8..db679f8e 100644 --- a/examples/component/toggle.cpp +++ b/examples/component/toggle.cpp @@ -2,19 +2,18 @@ #include #include -#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(); diff --git a/examples/dom/blink.cpp b/examples/dom/blink.cpp index 4214a7db..e5c0b025 100644 --- a/examples/dom/blink.cpp +++ b/examples/dom/blink.cpp @@ -1,10 +1,10 @@ -#include "ftxui/screen.hpp" +#include "ftxui/screen/screen.hpp" #include "ftxui/dom/elements.hpp" #include 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(); diff --git a/examples/dom/bold.cpp b/examples/dom/bold.cpp index 1a03b83c..9ee59a11 100644 --- a/examples/dom/bold.cpp +++ b/examples/dom/bold.cpp @@ -1,10 +1,10 @@ -#include "ftxui/screen.hpp" +#include "ftxui/screen/screen.hpp" #include "ftxui/dom/elements.hpp" #include 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(); diff --git a/examples/dom/color.cpp b/examples/dom/color.cpp index d8f80651..7bc42a79 100644 --- a/examples/dom/color.cpp +++ b/examples/dom/color.cpp @@ -1,10 +1,10 @@ -#include "ftxui/screen.hpp" +#include "ftxui/screen/screen.hpp" #include "ftxui/dom/elements.hpp" #include 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(); diff --git a/examples/dom/dbox.cpp b/examples/dom/dbox.cpp index 0a2e31de..09483a3c 100644 --- a/examples/dom/dbox.cpp +++ b/examples/dom/dbox.cpp @@ -1,10 +1,11 @@ -#include "ftxui/screen.hpp" +#include "ftxui/screen/screen.hpp" #include "ftxui/dom/elements.hpp" #include 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(); diff --git a/examples/dom/dim.cpp b/examples/dom/dim.cpp index a8386433..7b834c43 100644 --- a/examples/dom/dim.cpp +++ b/examples/dom/dim.cpp @@ -1,10 +1,10 @@ -#include "ftxui/screen.hpp" #include "ftxui/dom/elements.hpp" +#include "ftxui/screen/screen.hpp" #include 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(); diff --git a/examples/dom/frame.cpp b/examples/dom/frame.cpp index 0cfccbc8..b995d0d6 100644 --- a/examples/dom/frame.cpp +++ b/examples/dom/frame.cpp @@ -2,12 +2,13 @@ #include #include -#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; } diff --git a/examples/dom/gauge.cpp b/examples/dom/gauge.cpp index 54ea3ae4..3b097e80 100644 --- a/examples/dom/gauge.cpp +++ b/examples/dom/gauge.cpp @@ -2,26 +2,30 @@ #include #include -#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; diff --git a/examples/dom/inverted.cpp b/examples/dom/inverted.cpp index 176dd6dd..286a0bd0 100644 --- a/examples/dom/inverted.cpp +++ b/examples/dom/inverted.cpp @@ -1,10 +1,10 @@ -#include "ftxui/screen.hpp" +#include "ftxui/screen/screen.hpp" #include "ftxui/dom/elements.hpp" #include 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(); diff --git a/examples/dom/package_manager.cpp b/examples/dom/package_manager.cpp index 1987bec6..590797bd 100644 --- a/examples/dom/package_manager.cpp +++ b/examples/dom/package_manager.cpp @@ -2,17 +2,17 @@ #include #include -#include "ftxui/screen.hpp" #include "ftxui/dom/elements.hpp" +#include "ftxui/screen/screen.hpp" #include "ftxui/util/string.hpp" #include #include -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(); diff --git a/examples/dom/separator.cpp b/examples/dom/separator.cpp index d25a14e8..18ae1b92 100644 --- a/examples/dom/separator.cpp +++ b/examples/dom/separator.cpp @@ -1,10 +1,11 @@ -#include "ftxui/screen.hpp" +#include "ftxui/screen/screen.hpp" #include "ftxui/dom/elements.hpp" #include 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(); diff --git a/examples/dom/style_gallery.cpp b/examples/dom/style_gallery.cpp index f44df662..44ec43c4 100644 --- a/examples/dom/style_gallery.cpp +++ b/examples/dom/style_gallery.cpp @@ -1,10 +1,10 @@ -#include "ftxui/screen.hpp" +#include "ftxui/screen/screen.hpp" #include "ftxui/dom/elements.hpp" #include 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(); diff --git a/examples/dom/underlined.cpp b/examples/dom/underlined.cpp index 9f50dd2a..dcc38175 100644 --- a/examples/dom/underlined.cpp +++ b/examples/dom/underlined.cpp @@ -1,10 +1,10 @@ -#include "ftxui/screen.hpp" +#include "ftxui/screen/screen.hpp" #include "ftxui/dom/elements.hpp" #include 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(); diff --git a/examples/dom/vbox_hbox.cpp b/examples/dom/vbox_hbox.cpp index 281f791a..b67b0a6b 100644 --- a/examples/dom/vbox_hbox.cpp +++ b/examples/dom/vbox_hbox.cpp @@ -1,9 +1,11 @@ -#include "ftxui/screen.hpp" +#include "ftxui/screen/screen.hpp" #include "ftxui/dom/elements.hpp" #include + 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(); diff --git a/examples/print_key_press.cpp b/examples/print_key_press.cpp index 6bdf7f7e..42815308 100644 --- a/examples/print_key_press.cpp +++ b/examples/print_key_press.cpp @@ -2,26 +2,28 @@ #include #include -#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 keys; + std::vector 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(); } diff --git a/ftxui/CMakeLists.txt b/ftxui/CMakeLists.txt index e5a86287..73aba01c 100644 --- a/ftxui/CMakeLists.txt +++ b/ftxui/CMakeLists.txt @@ -5,8 +5,10 @@ add_library(ftxui src/ftxui/component/component_direction.cpp src/ftxui/component/component_horizontal.cpp src/ftxui/component/component_vertical.cpp + src/ftxui/component/event.cpp src/ftxui/component/input.cpp src/ftxui/component/menu.cpp + src/ftxui/component/screen_interactive.cpp src/ftxui/component/toggle.cpp src/ftxui/dom/blink.cpp src/ftxui/dom/bold.cpp @@ -26,9 +28,7 @@ add_library(ftxui src/ftxui/dom/underlined.cpp src/ftxui/dom/util.cpp src/ftxui/dom/vbox.cpp - src/ftxui/event.cpp - src/ftxui/screen.cpp - src/ftxui/screen_interactive.cpp + src/ftxui/screen/screen.cpp src/ftxui/terminal.cpp src/ftxui/util/string.cpp ) diff --git a/ftxui/include/ftxui/box.hpp b/ftxui/include/ftxui/box.hpp deleted file mode 100644 index 021a5946..00000000 --- a/ftxui/include/ftxui/box.hpp +++ /dev/null @@ -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 */ diff --git a/ftxui/include/ftxui/component/component.hpp b/ftxui/include/ftxui/component/component.hpp index 1c575ef8..3ce91078 100644 --- a/ftxui/include/ftxui/component/component.hpp +++ b/ftxui/include/ftxui/component/component.hpp @@ -2,11 +2,10 @@ #define FTXUI_COMPONENT_COMPONENT_HPP #include "ftxui/component/delegate.hpp" +#include "ftxui/component/event.hpp" #include "ftxui/dom/elements.hpp" -#include "ftxui/event.hpp" -namespace ftxui { -namespace component { +namespace ftxui::component { class Delegate; class Focus; @@ -39,7 +38,6 @@ class Component { Delegate* delegate_; }; -} // namespace component -} // namespace ftxui +} // namespace ftxui::component #endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_HPP */ diff --git a/ftxui/include/ftxui/component/component_horizontal.hpp b/ftxui/include/ftxui/component/component_horizontal.hpp index 35dadf2b..d2386136 100644 --- a/ftxui/include/ftxui/component/component_horizontal.hpp +++ b/ftxui/include/ftxui/component/component_horizontal.hpp @@ -3,8 +3,7 @@ #include "ftxui/component/component_direction.hpp" -namespace ftxui { -namespace component { +namespace ftxui::component { // A component where focus and events are automatically handled for you. // It assumes its children are put in the horizontal direction. @@ -14,7 +13,6 @@ class ComponentHorizontal : public ComponentDirection { bool HandleDirection(Event) override; }; -} // namespace component -} // namespace ftxui +} // namespace ftxui::component #endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_HORIZONTAL_H_ */ diff --git a/ftxui/include/ftxui/component/component_vertical.hpp b/ftxui/include/ftxui/component/component_vertical.hpp index 22c91f25..78d59e4a 100644 --- a/ftxui/include/ftxui/component/component_vertical.hpp +++ b/ftxui/include/ftxui/component/component_vertical.hpp @@ -3,8 +3,7 @@ #include "ftxui/component/component_direction.hpp" -namespace ftxui { -namespace component { +namespace ftxui::component { // A component where focus and events are automatically handled for you. // It assumes its children are put in the vertical direction. @@ -14,7 +13,6 @@ class ComponentVertical : public ComponentDirection { bool HandleDirection(Event) override; }; -} // namespace component -} // namespace ftxui +} // namespace ftxui::component #endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_VERTICAL_H_ */ diff --git a/ftxui/include/ftxui/component/delegate.hpp b/ftxui/include/ftxui/component/delegate.hpp index d4bc236b..89be5804 100644 --- a/ftxui/include/ftxui/component/delegate.hpp +++ b/ftxui/include/ftxui/component/delegate.hpp @@ -3,8 +3,7 @@ #include "ftxui/dom/elements.hpp" -namespace ftxui { -namespace component { +namespace ftxui::component { class Component; @@ -28,7 +27,6 @@ class Delegate { virtual Delegate* Root() = 0; }; -} // namespace component -} // namespace ftxui +} // namespace ftxui::component #endif /* end of include guard: FTXUI_COMPONENT_DELEGATE_HPP */ diff --git a/ftxui/include/ftxui/event.hpp b/ftxui/include/ftxui/component/event.hpp similarity index 75% rename from ftxui/include/ftxui/event.hpp rename to ftxui/include/ftxui/component/event.hpp index c276c241..75c26e75 100644 --- a/ftxui/include/ftxui/event.hpp +++ b/ftxui/include/ftxui/component/event.hpp @@ -1,10 +1,10 @@ -#ifndef FTXUI_EVENT_H_ -#define FTXUI_EVENT_H_ +#ifndef FTXUI_COMPONENT_EVENT_HPP +#define FTXUI_COMPONENT_EVENT_HPP #include #include -namespace ftxui { +namespace ftxui::component { struct Event{ 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 */ diff --git a/ftxui/include/ftxui/component/input.hpp b/ftxui/include/ftxui/component/input.hpp index 6f8537c5..8a79bfdf 100644 --- a/ftxui/include/ftxui/component/input.hpp +++ b/ftxui/include/ftxui/component/input.hpp @@ -4,8 +4,7 @@ #include "ftxui/component/component.hpp" #include -namespace ftxui { -namespace component { +namespace ftxui::component { class Input : public Component { public: @@ -29,7 +28,6 @@ class Input : public Component { int cursor_position = 0; }; -} // namespace component -} // namespace ftxui +} // namespace ftxui::component #endif /* end of include guard: FTXUI_COMPONENT_INPUT_H_ */ diff --git a/ftxui/include/ftxui/component/menu.hpp b/ftxui/include/ftxui/component/menu.hpp index 6b4f045d..f3800d34 100644 --- a/ftxui/include/ftxui/component/menu.hpp +++ b/ftxui/include/ftxui/component/menu.hpp @@ -5,8 +5,7 @@ #include "ftxui/dom/elements.hpp" #include -namespace ftxui { -namespace component { +namespace ftxui::component { class Menu : public Component { public: @@ -30,7 +29,6 @@ class Menu : public Component { bool OnEvent(Event) override; }; -} // namespace component -} // namespace ftxui +} // namespace ftxui::Component #endif /* end of include guard: FTXUI_COMPONENT_MENU */ diff --git a/ftxui/include/ftxui/screen_interactive.hpp b/ftxui/include/ftxui/component/screen_interactive.hpp similarity index 55% rename from ftxui/include/ftxui/screen_interactive.hpp rename to ftxui/include/ftxui/component/screen_interactive.hpp index 6ae80be9..5a45348b 100644 --- a/ftxui/include/ftxui/screen_interactive.hpp +++ b/ftxui/include/ftxui/component/screen_interactive.hpp @@ -1,18 +1,16 @@ -#ifndef FTXUI_SCREEN_INTERACTIVE -#define FTXUI_SCREEN_INTERACTIVE +#ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP +#define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP -#include "ftxui/screen.hpp" +#include "ftxui/screen/screen.hpp" #include #include -namespace ftxui { +namespace ftxui::component { -namespace component { - class Delegate; - class Component; -} // namespace component +class Delegate; +class Component; -class ScreenInteractive : public Screen { +class ScreenInteractive : public ftxui::screen::Screen { public: static ScreenInteractive FixedSize(size_t dimx, size_t dimy); static ScreenInteractive Fullscreen(); @@ -21,15 +19,15 @@ class ScreenInteractive : public Screen { ~ScreenInteractive(); component::Delegate* delegate(); void Loop(); - std::function ExitLoopClosure(); + std::function ExitLoopClosure(); private: class Delegate; std::unique_ptr delegate_; - void Clear(); - void Draw(); - bool quit_ = false; + void Clear(); + void Draw(); + bool quit_ = false; enum class Dimension { Fixed, @@ -41,6 +39,6 @@ class ScreenInteractive : public Screen { 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 */ diff --git a/ftxui/include/ftxui/component/toggle.hpp b/ftxui/include/ftxui/component/toggle.hpp index 5bfe6dfc..ef6a89ab 100644 --- a/ftxui/include/ftxui/component/toggle.hpp +++ b/ftxui/include/ftxui/component/toggle.hpp @@ -5,8 +5,7 @@ #include #include -namespace ftxui { -namespace component { +namespace ftxui::component { class Toggle : public Component { public: @@ -25,7 +24,6 @@ class Toggle : public Component { bool OnEvent(Event) override; }; -} // namespace component -} // namespace ftxui +} // namespace ftxui::Component #endif /* end of include guard: FTXUI_COMPONENT_TOGGLE_H_ */ diff --git a/ftxui/include/ftxui/dom/box.hpp b/ftxui/include/ftxui/dom/box.hpp new file mode 100644 index 00000000..87104650 --- /dev/null +++ b/ftxui/include/ftxui/dom/box.hpp @@ -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 */ diff --git a/ftxui/include/ftxui/dom/elements.hpp b/ftxui/include/ftxui/dom/elements.hpp index 67ebe7de..f21d76d5 100644 --- a/ftxui/include/ftxui/dom/elements.hpp +++ b/ftxui/include/ftxui/dom/elements.hpp @@ -3,16 +3,16 @@ #include -#include "ftxui/color.hpp" #include "ftxui/dom/node.hpp" +#include "ftxui/screen/color.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { using Element = std::unique_ptr; using Decorator = std::function; using Child = std::unique_ptr; using Children = std::vector; +using Color = ftxui::screen::Color; // --- Layout ---- Element vbox(Children); @@ -58,7 +58,6 @@ TAKE_ANY_ARGS(vbox) TAKE_ANY_ARGS(hbox) TAKE_ANY_ARGS(dbox) -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom #endif /* end of include guard: FTXUI_DOM_ELEMENTS_HPP */ diff --git a/ftxui/include/ftxui/dom/node.hpp b/ftxui/include/ftxui/dom/node.hpp index 7f92be7f..ecd4b99f 100644 --- a/ftxui/include/ftxui/dom/node.hpp +++ b/ftxui/include/ftxui/dom/node.hpp @@ -1,15 +1,14 @@ -#ifndef DOM_NODE_HPP -#define DOM_NODE_HPP +#ifndef FTXUI_DOM_NODE_HPP +#define FTXUI_DOM_NODE_HPP #include #include -#include "ftxui/requirement.hpp" -#include "ftxui/screen.hpp" -#include "ftxui/box.hpp" +#include "ftxui/dom/box.hpp" +#include "ftxui/dom/requirement.hpp" +#include "ftxui/screen/screen.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { class Node { public: @@ -28,7 +27,7 @@ class Node { virtual void SetBox(Box box); // Step 3: Draw this element. - virtual void Render(Screen& screen); + virtual void Render(screen::Screen& screen); std::vector> children; protected: @@ -36,9 +35,8 @@ class Node { Box box_; }; -void Render(Screen& screen, Node* node); +void Render(screen::Screen& screen, Node* node); -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom -#endif /* end of include guard: DOM_NODE_HPP */ +#endif /* end of include guard: FTXUI_DOM_NODE_HPP */ diff --git a/ftxui/include/ftxui/requirement.hpp b/ftxui/include/ftxui/dom/requirement.hpp similarity index 69% rename from ftxui/include/ftxui/requirement.hpp rename to ftxui/include/ftxui/dom/requirement.hpp index f5a96055..d91c5baa 100644 --- a/ftxui/include/ftxui/requirement.hpp +++ b/ftxui/include/ftxui/dom/requirement.hpp @@ -1,7 +1,7 @@ -#ifndef FTXUI_REQUIREMENT_HPP -#define FTXUI_REQUIREMENT_HPP +#ifndef FTXUI_DOM_REQUIREMENT_HPP +#define FTXUI_DOM_REQUIREMENT_HPP -namespace ftxui { +namespace ftxui::dom { struct Requirement { // The required size to fully draw the element. @@ -11,6 +11,6 @@ struct Requirement { struct { int x = 0; int y = 0; } flex; }; -}; // namespace ftxui +}; // namespace ftxui::dom #endif /* end of include guard: FTXUI_REQUIREMENT_HPP */ diff --git a/ftxui/include/ftxui/color.hpp b/ftxui/include/ftxui/screen/color.hpp similarity index 80% rename from ftxui/include/ftxui/color.hpp rename to ftxui/include/ftxui/screen/color.hpp index 4853c5cb..43e5b42e 100644 --- a/ftxui/include/ftxui/color.hpp +++ b/ftxui/include/ftxui/screen/color.hpp @@ -1,9 +1,9 @@ -#ifndef FTXUI_COLOR_H_ -#define FTXUI_COLOR_H_ +#ifndef FTXUI_SCREEN_COLOR +#define FTXUI_SCREEN_COLOR #include -namespace ftxui { +namespace ftxui::screen { enum class Color : uint8_t { // --- Transparent ----- @@ -35,6 +35,6 @@ enum class Color : uint8_t { YellowLight = 93, }; -}; // namespace ftxui +}; // namespace ftxui::screen #endif /* end of include guard: FTXUI_COLOR_H_ */ diff --git a/ftxui/include/ftxui/screen.hpp b/ftxui/include/ftxui/screen/screen.hpp similarity index 82% rename from ftxui/include/ftxui/screen.hpp rename to ftxui/include/ftxui/screen/screen.hpp index 6a858b52..04829d48 100644 --- a/ftxui/include/ftxui/screen.hpp +++ b/ftxui/include/ftxui/screen/screen.hpp @@ -1,17 +1,18 @@ -#ifndef FTXUI_SCREEN -#define FTXUI_SCREEN +#ifndef FTXUI_SCREEN_SCREEN +#define FTXUI_SCREEN_SCREEN #include #include #include -#include +#include "ftxui/screen/color.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { class Node; } +namespace ftxui::screen { + struct Pixel { wchar_t character = U' '; bool blink = false; @@ -55,6 +56,6 @@ class Screen { std::vector> pixels_; }; -}; // namespace ftxui +}; // namespace ftxui::screen -#endif /* end of include guard: FTXUI_SCREEN */ +#endif /* end of include guard: FTXUI_SCREEN_SCREEN */ diff --git a/ftxui/src/ftxui/component/component.cpp b/ftxui/src/ftxui/component/component.cpp index 9b40d594..b7960311 100644 --- a/ftxui/src/ftxui/component/component.cpp +++ b/ftxui/src/ftxui/component/component.cpp @@ -2,8 +2,7 @@ #include "ftxui/component/delegate.hpp" #include -namespace ftxui { -namespace component { +namespace ftxui::component { Component::Component(Delegate* delegate) { delegate_ = delegate; @@ -55,5 +54,4 @@ Component* Component::Parent() { return parent_delegate->component(); } -} // namespace component -} // namespace ftxui +} // namespace ftxui::component diff --git a/ftxui/src/ftxui/component/component_direction.cpp b/ftxui/src/ftxui/component/component_direction.cpp index 74dc8462..3a49e5f2 100644 --- a/ftxui/src/ftxui/component/component_direction.cpp +++ b/ftxui/src/ftxui/component/component_direction.cpp @@ -1,7 +1,6 @@ #include "ftxui/component/component_direction.hpp" -namespace ftxui { -namespace component { +namespace ftxui::component { ComponentDirection::ComponentDirection(Delegate* delegate) : Component(delegate), active_child_(nullptr) {} @@ -27,5 +26,4 @@ void ComponentDirection::Focus(Component* child) { active_child_ = child; } -} // namespace component -} // namespace ftxui +} // namespace ftxui::Component diff --git a/ftxui/src/ftxui/component/component_horizontal.cpp b/ftxui/src/ftxui/component/component_horizontal.cpp index b9079cc8..fb83e778 100644 --- a/ftxui/src/ftxui/component/component_horizontal.cpp +++ b/ftxui/src/ftxui/component/component_horizontal.cpp @@ -1,7 +1,6 @@ #include "ftxui/component/component_horizontal.hpp" -namespace ftxui { -namespace component { +namespace ftxui::component { ComponentHorizontal::ComponentHorizontal(Delegate* delegate) : ComponentDirection(delegate) {} @@ -28,5 +27,4 @@ bool ComponentHorizontal::HandleDirection(Event event) { return false; } -} // namespace component -} // namespace ftxui +} // namespace ftxui::component diff --git a/ftxui/src/ftxui/component/component_vertical.cpp b/ftxui/src/ftxui/component/component_vertical.cpp index ec0141fb..2b3b009b 100644 --- a/ftxui/src/ftxui/component/component_vertical.cpp +++ b/ftxui/src/ftxui/component/component_vertical.cpp @@ -1,7 +1,6 @@ #include "ftxui/component/component_vertical.hpp" -namespace ftxui { -namespace component { +namespace ftxui::component { ComponentVertical::ComponentVertical(Delegate* delegate) : ComponentDirection(delegate) {} @@ -28,5 +27,4 @@ bool ComponentVertical::HandleDirection(Event event) { return false; } -} // namespace component -} // namespace ftxui +} // namespace ftxui::component diff --git a/ftxui/src/ftxui/event.cpp b/ftxui/src/ftxui/component/event.cpp similarity index 90% rename from ftxui/src/ftxui/event.cpp rename to ftxui/src/ftxui/component/event.cpp index ed232f28..b032c2b7 100644 --- a/ftxui/src/ftxui/event.cpp +++ b/ftxui/src/ftxui/component/event.cpp @@ -1,6 +1,6 @@ -#include "ftxui/event.hpp" +#include "ftxui/component/event.hpp" -namespace ftxui { +namespace ftxui::component { constexpr int ESC = int(27); @@ -34,4 +34,4 @@ Event Event::F10{ESC, '[', '2', '1', '~'}; Event Event::F11{ESC, '[', '2', '1', '~'}; // Same as F10 ? Event Event::F12{ESC, '[', '2', '4', '~'}; -} // namespace ftxui +} // namespace ftxui::component diff --git a/ftxui/src/ftxui/component/input.cpp b/ftxui/src/ftxui/component/input.cpp index adfd82aa..d80863e6 100644 --- a/ftxui/src/ftxui/component/input.cpp +++ b/ftxui/src/ftxui/component/input.cpp @@ -1,8 +1,7 @@ #include "ftxui/component/input.hpp" #include "ftxui/util/string.hpp" -namespace ftxui { -namespace component { +namespace ftxui::component { Input::Input(Delegate* delegate): Component(delegate) {} Input::~Input() {} @@ -76,5 +75,4 @@ bool Input::OnEvent(Event event) { return false; } -} // namespace component -} // namespace ftxui +} // namespace ftxui::component diff --git a/ftxui/src/ftxui/component/menu.cpp b/ftxui/src/ftxui/component/menu.cpp index 0c9ff32b..d1c0a99d 100644 --- a/ftxui/src/ftxui/component/menu.cpp +++ b/ftxui/src/ftxui/component/menu.cpp @@ -2,8 +2,7 @@ #include #include -namespace ftxui { -namespace component { +namespace ftxui::component { Menu::Menu(Delegate* delegate) : Component(delegate) {} @@ -50,5 +49,4 @@ bool Menu::OnEvent(Event event) { return false; } -} // namespace component -} // namespace ftxui +} // namespace ftxui::component diff --git a/ftxui/src/ftxui/screen_interactive.cpp b/ftxui/src/ftxui/component/screen_interactive.cpp similarity index 81% rename from ftxui/src/ftxui/screen_interactive.cpp rename to ftxui/src/ftxui/component/screen_interactive.cpp index 8ba98fb1..7111e233 100644 --- a/ftxui/src/ftxui/screen_interactive.cpp +++ b/ftxui/src/ftxui/component/screen_interactive.cpp @@ -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 #include #include #include +#include +#include "ftxui/component/component.hpp" +#include "ftxui/component/delegate.hpp" +#include "ftxui/terminal.hpp" -namespace ftxui { +namespace ftxui::component { namespace { - constexpr int ESC = 27; - constexpr int WAT = 195; - constexpr int WAT2 = 194; - constexpr int WATWAIT = 91; +constexpr int ESC = 27; +constexpr int WAT = 195; +constexpr int WAT2 = 194; +constexpr int WATWAIT = 91; - Event GetEvent() { - int v1 = getchar(); - if (v1 == ESC) { - int v2 = getchar(); - int v3 = getchar(); +Event GetEvent() { + int v1 = getchar(); + if (v1 == ESC) { + int v2 = getchar(); + int v3 = getchar(); - //if (v2 == WATWAIT) { - //int v4 = getchar(); - //int v5 = getchar(); - //return Event{v1, v2, v3, v4, v5}; - //} - return Event{v1, v2, v3}; - } + // if (v2 == WATWAIT) { + // int v4 = getchar(); + // int v5 = getchar(); + // return Event{v1, v2, v3, v4, v5}; + //} + return Event{v1, v2, v3}; + } - if (v1 == WAT) { - int v2 = getchar(); - return Event{v1, v2}; - } + if (v1 == WAT) { + int v2 = getchar(); + return Event{v1, v2}; + } - if (v1 == WAT2) { - int v2 = getchar(); - return Event{v1, v2}; - } + if (v1 == WAT2) { + int v2 = getchar(); + return Event{v1, v2}; + } - return Event{v1}; - }; + return Event{v1}; }; +}; // namespace class ScreenInteractive::Delegate : public component::Delegate { public: @@ -67,7 +67,6 @@ class ScreenInteractive::Delegate : public component::Delegate { void OnEvent(Event event) { component_->OnEvent(event); } - std::vector children() override { std::vector ret; for (auto& it : child_) @@ -129,12 +128,14 @@ void ScreenInteractive::Loop() { tcsetattr(STDIN_FILENO, TCSANOW, &terminal_configuration_new); Draw(); - while(!quit_) { + while (!quit_) { delegate_->OnEvent(GetEvent()); Clear(); Draw(); - } while(!quit_); - //std::cout << std::endl; + } + while (!quit_) + ; + // std::cout << std::endl; // Restore the old terminal configuration. tcsetattr(STDIN_FILENO, TCSANOW, &terminal_configuration_old); @@ -144,7 +145,7 @@ void ScreenInteractive::Draw() { auto document = delegate_->component()->Render(); size_t dimx; size_t dimy; - switch(dimension_) { + switch (dimension_) { case Dimension::Fixed: break; case Dimension::TerminalOutput: @@ -162,7 +163,8 @@ void ScreenInteractive::Draw() { if (dimx != dimx_ || dimy != dimy_) { dimx_ = dimx; dimy_ = dimy; - pixels_ = std::vector>(dimy, std::vector(dimx)); + pixels_ = std::vector>( + dimy, std::vector(dimx)); } Render(*this, document.get()); @@ -182,4 +184,4 @@ std::function ScreenInteractive::ExitLoopClosure() { return [this]() { quit_ = true; }; } -} // namespace ftxui +} // namespace ftxui::component. diff --git a/ftxui/src/ftxui/component/toggle.cpp b/ftxui/src/ftxui/component/toggle.cpp index 39f12e70..a2d04c3d 100644 --- a/ftxui/src/ftxui/component/toggle.cpp +++ b/ftxui/src/ftxui/component/toggle.cpp @@ -1,7 +1,6 @@ #include "ftxui/component/toggle.hpp" -namespace ftxui { -namespace component { +namespace ftxui::component { Toggle::Toggle(Delegate* delegate) : Component(delegate) {} @@ -41,5 +40,4 @@ bool Toggle::OnEvent(Event event) { return false; } -} // namespace component -} // namespace ftxui +} // namespace ftxui::component diff --git a/ftxui/src/ftxui/dom/blink.cpp b/ftxui/src/ftxui/dom/blink.cpp index a24f20a2..4a6aa34d 100644 --- a/ftxui/src/ftxui/dom/blink.cpp +++ b/ftxui/src/ftxui/dom/blink.cpp @@ -1,15 +1,14 @@ #include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { class Blink : public NodeDecorator { public: Blink(Children children) : NodeDecorator(std::move(children)) {} ~Blink() override {} - void Render(Screen& screen) override { + void Render(screen::Screen& screen) override { Node::Render(screen); for (int y = box_.top; y <= box_.bottom; ++y) { for (int x = box_.left; x <= box_.right; ++x) { @@ -23,5 +22,4 @@ std::unique_ptr blink(Child child) { return std::make_unique(unpack(std::move(child))); } -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/bold.cpp b/ftxui/src/ftxui/dom/bold.cpp index 49c214a3..8ba87f50 100644 --- a/ftxui/src/ftxui/dom/bold.cpp +++ b/ftxui/src/ftxui/dom/bold.cpp @@ -1,15 +1,14 @@ #include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { class Bold : public NodeDecorator { public: Bold(Children children) : NodeDecorator(std::move(children)) {} ~Bold() override {} - void Render(Screen& screen) override { + void Render(screen::Screen& screen) override { for (int y = box_.top; y <= box_.bottom; ++y) { for (int x = box_.left; x <= box_.right; ++x) { screen.PixelAt(x,y).bold = true; @@ -23,5 +22,4 @@ std::unique_ptr bold(Child child) { return std::make_unique(unpack(std::move(child))); } -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/color.cpp b/ftxui/src/ftxui/dom/color.cpp index cf63704e..bace671d 100644 --- a/ftxui/src/ftxui/dom/color.cpp +++ b/ftxui/src/ftxui/dom/color.cpp @@ -1,15 +1,14 @@ #include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { class BgColor : public NodeDecorator { public: BgColor(Children children, Color color) : NodeDecorator(std::move(children)), color_(color) {} - void Render(Screen& screen) override { + void Render(screen::Screen& screen) override { for (int y = box_.top; y <= box_.bottom; ++y) { for (int x = box_.left; x <= box_.right; ++x) { screen.PixelAt(x, y).background_color = color_; @@ -27,7 +26,7 @@ class FgColor : public NodeDecorator { : NodeDecorator(std::move(children)), color_(color) {} ~FgColor() override {} - void Render(Screen& screen) override { + void Render(screen::Screen& screen) override { for (int y = box_.top; y <= box_.bottom; ++y) { for (int x = box_.left; x <= box_.right; ++x) { screen.PixelAt(x, y).foreground_color = color_; @@ -59,5 +58,4 @@ Decorator bgcolor(Color c) { }; } -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/composite_decorator.cpp b/ftxui/src/ftxui/dom/composite_decorator.cpp index 2f64105e..eda0155b 100644 --- a/ftxui/src/ftxui/dom/composite_decorator.cpp +++ b/ftxui/src/ftxui/dom/composite_decorator.cpp @@ -1,8 +1,7 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { std::unique_ptr hcenter(Element child) { return hbox(filler(), std::move(child), filler()); @@ -16,5 +15,4 @@ std::unique_ptr center(Element child) { return hcenter(vcenter(std::move(child))); } -} // namespace dom -} // namespace ftxui +} // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/dbox.cpp b/ftxui/src/ftxui/dom/dbox.cpp index 3704387e..9639da41 100644 --- a/ftxui/src/ftxui/dom/dbox.cpp +++ b/ftxui/src/ftxui/dom/dbox.cpp @@ -1,8 +1,7 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { class DBox : public Node { public: @@ -33,5 +32,4 @@ std::unique_ptr dbox(Children children) { return std::make_unique(std::move(children)); } -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/dim.cpp b/ftxui/src/ftxui/dom/dim.cpp index ef7cdb96..e72b9d6b 100644 --- a/ftxui/src/ftxui/dom/dim.cpp +++ b/ftxui/src/ftxui/dom/dim.cpp @@ -1,8 +1,9 @@ #include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { + +using ftxui::screen::Screen; class Dim : public NodeDecorator { public: @@ -23,5 +24,4 @@ std::unique_ptr dim(Child child) { return std::make_unique(unpack(std::move(child))); } -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/flex.cpp b/ftxui/src/ftxui/dom/flex.cpp index 7741a779..fbd79ba4 100644 --- a/ftxui/src/ftxui/dom/flex.cpp +++ b/ftxui/src/ftxui/dom/flex.cpp @@ -1,8 +1,7 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { class Flex : public Node { public: @@ -35,5 +34,4 @@ std::unique_ptr flex(Element child) { return std::make_unique(std::move(child)); } -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/frame.cpp b/ftxui/src/ftxui/dom/frame.cpp index 1bbe056f..41fcedba 100644 --- a/ftxui/src/ftxui/dom/frame.cpp +++ b/ftxui/src/ftxui/dom/frame.cpp @@ -1,8 +1,9 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { + +using namespace ftxui::screen; static wchar_t charset[] = L"┌┐└┘─│┬┴┤├"; @@ -94,5 +95,4 @@ Decorator boxed() { }; } -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/gauge.cpp b/ftxui/src/ftxui/dom/gauge.cpp index 603d5e27..c6ccebe8 100644 --- a/ftxui/src/ftxui/dom/gauge.cpp +++ b/ftxui/src/ftxui/dom/gauge.cpp @@ -1,8 +1,9 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { + +using namespace ftxui::screen; static wchar_t charset[] = L" ▏▎▍▌▋▊▉█"; @@ -35,5 +36,4 @@ std::unique_ptr gauge(float progress) { return std::make_unique(progress); } -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/gauge_test.cpp b/ftxui/src/ftxui/dom/gauge_test.cpp index ef78951a..9b7b2b88 100644 --- a/ftxui/src/ftxui/dom/gauge_test.cpp +++ b/ftxui/src/ftxui/dom/gauge_test.cpp @@ -1,9 +1,9 @@ #include "ftxui/dom/elements.hpp" -#include "ftxui/screen.hpp" +#include "ftxui/screen/screen.hpp" #include "gtest/gtest.h" -namespace ftxui { -namespace dom { +using namespace ftxui::screen; +using namespace ftxui::dom; TEST(GaugeTest, zero) { auto root = gauge(0); @@ -29,6 +29,3 @@ TEST(GaugeTest, one) { EXPECT_EQ("███████████", screen.ToString()); } - -} // namespace dom -} // namespace ftxui diff --git a/ftxui/src/ftxui/dom/hbox.cpp b/ftxui/src/ftxui/dom/hbox.cpp index a96049e2..6cbc202c 100644 --- a/ftxui/src/ftxui/dom/hbox.cpp +++ b/ftxui/src/ftxui/dom/hbox.cpp @@ -1,8 +1,7 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { class HBox : public Node { public: @@ -64,5 +63,4 @@ std::unique_ptr hbox(Children children) { return std::make_unique(std::move(children)); } -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/hbox_test.cpp b/ftxui/src/ftxui/dom/hbox_test.cpp index 859852ef..a81723f7 100644 --- a/ftxui/src/ftxui/dom/hbox_test.cpp +++ b/ftxui/src/ftxui/dom/hbox_test.cpp @@ -1,9 +1,9 @@ #include "ftxui/dom/elements.hpp" -#include "ftxui/screen.hpp" +#include "ftxui/screen/screen.hpp" #include "gtest/gtest.h" -namespace ftxui { -namespace dom { +using namespace ftxui::screen; +using namespace ftxui::dom; TEST(HBoxTest, ScreenSmaller1) { auto root = hbox( @@ -118,6 +118,3 @@ TEST(HBoxTest, ScreenBigger2Flex) { EXPECT_EQ("text_1 text_2", screen.ToString()); } - -}; // namespace dom -}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/inverted.cpp b/ftxui/src/ftxui/dom/inverted.cpp index 2e231ee8..b1b3e92d 100644 --- a/ftxui/src/ftxui/dom/inverted.cpp +++ b/ftxui/src/ftxui/dom/inverted.cpp @@ -1,8 +1,9 @@ #include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { + +using ftxui::screen::Screen; class Inverted : public NodeDecorator { public: @@ -23,5 +24,4 @@ std::unique_ptr inverted(Child child) { return std::make_unique(unpack(std::move(child))); } -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/node.cpp b/ftxui/src/ftxui/dom/node.cpp index 648c1211..5e01589f 100644 --- a/ftxui/src/ftxui/dom/node.cpp +++ b/ftxui/src/ftxui/dom/node.cpp @@ -1,7 +1,8 @@ #include "ftxui/dom/node.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { + +using ftxui::screen::Screen; Node::Node() {} Node::Node(std::vector> children) @@ -39,5 +40,4 @@ void Render(Screen& screen, Node* node) { node->Render(screen); } -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/node_decorator.cpp b/ftxui/src/ftxui/dom/node_decorator.cpp index 8ba35a92..ec217068 100644 --- a/ftxui/src/ftxui/dom/node_decorator.cpp +++ b/ftxui/src/ftxui/dom/node_decorator.cpp @@ -1,7 +1,6 @@ #include "ftxui/dom/node_decorator.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { void NodeDecorator::ComputeRequirement() { Node::ComputeRequirement(); @@ -13,5 +12,4 @@ void NodeDecorator::SetBox(Box box) { children[0]->SetBox(box); } -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/node_decorator.hpp b/ftxui/src/ftxui/dom/node_decorator.hpp index cc53ef31..23e6a341 100644 --- a/ftxui/src/ftxui/dom/node_decorator.hpp +++ b/ftxui/src/ftxui/dom/node_decorator.hpp @@ -4,8 +4,7 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { // Helper class. class NodeDecorator : public Node { @@ -16,7 +15,6 @@ class NodeDecorator : public Node { void SetBox(Box box) override; }; -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom #endif /* end of include guard: FTXUI_DOM_NODE_DECORATOR_H_ */ diff --git a/ftxui/src/ftxui/dom/separator.cpp b/ftxui/src/ftxui/dom/separator.cpp index b298e06c..fcbfb5b4 100644 --- a/ftxui/src/ftxui/dom/separator.cpp +++ b/ftxui/src/ftxui/dom/separator.cpp @@ -1,7 +1,8 @@ #include "ftxui/dom/node.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { + +using ftxui::screen::Screen; class Separator : public Node { public: @@ -34,5 +35,4 @@ std::unique_ptr separator() { return std::make_unique(); } -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/text.cpp b/ftxui/src/ftxui/dom/text.cpp index 218ed06f..6b38093e 100644 --- a/ftxui/src/ftxui/dom/text.cpp +++ b/ftxui/src/ftxui/dom/text.cpp @@ -1,7 +1,8 @@ #include "ftxui/dom/node.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { + +using ftxui::screen::Screen; class Text : public Node { public: @@ -33,5 +34,4 @@ std::unique_ptr text(std::wstring text) { return std::make_unique(text); } -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/text_test.cpp b/ftxui/src/ftxui/dom/text_test.cpp index f18f99d5..4765496b 100644 --- a/ftxui/src/ftxui/dom/text_test.cpp +++ b/ftxui/src/ftxui/dom/text_test.cpp @@ -1,9 +1,9 @@ #include "ftxui/dom/elements.hpp" -#include "ftxui/screen.hpp" +#include "ftxui/screen/screen.hpp" #include "gtest/gtest.h" -namespace ftxui { -namespace dom { +using namespace ftxui::screen; +using namespace ftxui::dom; TEST(TextTest, ScreenHeightSmaller) { auto element = text(L"test"); @@ -44,6 +44,3 @@ TEST(TextTest, ScreenBigger2) { EXPECT_EQ("test \n ", screen.ToString()); } - -}; // namespace dom -}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/underlined.cpp b/ftxui/src/ftxui/dom/underlined.cpp index b2cd7f9d..32fe3cab 100644 --- a/ftxui/src/ftxui/dom/underlined.cpp +++ b/ftxui/src/ftxui/dom/underlined.cpp @@ -1,8 +1,9 @@ #include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { + +using ftxui::screen::Screen; class Underlined : public NodeDecorator { public: @@ -23,5 +24,4 @@ std::unique_ptr underlined(Child child) { return std::make_unique(unpack(std::move(child))); } -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/util.cpp b/ftxui/src/ftxui/dom/util.cpp index afdb3dec..3ca4b789 100644 --- a/ftxui/src/ftxui/dom/util.cpp +++ b/ftxui/src/ftxui/dom/util.cpp @@ -1,7 +1,6 @@ #include "ftxui/dom/elements.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { Element nothing(Element element) { return std::move(element); @@ -24,5 +23,4 @@ Element operator|(Element e, Decorator d) { return d(std::move(e)); } -} // namespace dom -} // namespace ftxui +} // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/vbox.cpp b/ftxui/src/ftxui/dom/vbox.cpp index 3f504e60..ab2e2b78 100644 --- a/ftxui/src/ftxui/dom/vbox.cpp +++ b/ftxui/src/ftxui/dom/vbox.cpp @@ -1,8 +1,7 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui { -namespace dom { +namespace ftxui::dom { class VBox : public Node { public: @@ -64,5 +63,4 @@ std::unique_ptr vbox(Children children) { return std::make_unique(std::move(children)); } -}; // namespace dom -}; // namespace ftxui +}; // namespace ftxui::dom diff --git a/ftxui/src/ftxui/dom/vbox_test.cpp b/ftxui/src/ftxui/dom/vbox_test.cpp index 6f24fb8b..1ac7d39e 100644 --- a/ftxui/src/ftxui/dom/vbox_test.cpp +++ b/ftxui/src/ftxui/dom/vbox_test.cpp @@ -1,9 +1,9 @@ #include "ftxui/dom/elements.hpp" -#include "ftxui/screen.hpp" +#include "ftxui/screen/screen.hpp" #include "gtest/gtest.h" -namespace ftxui { -namespace dom { +using namespace ftxui::screen; +using namespace ftxui::dom; TEST(VBoxTest, ScreenSmaller1) { auto root = vbox(text(L"text_1"), text(L"text_2")); @@ -66,6 +66,3 @@ TEST(VBoxTest, ScreenBigger2Flex) { EXPECT_EQ("text_1\n \n \ntext_2", screen.ToString()); } - -}; // namespace dom -}; // namespace ftxui diff --git a/ftxui/src/ftxui/screen.cpp b/ftxui/src/ftxui/screen/screen.cpp similarity index 70% rename from ftxui/src/ftxui/screen.cpp rename to ftxui/src/ftxui/screen/screen.cpp index 27cc923f..30f0bfbb 100644 --- a/ftxui/src/ftxui/screen.cpp +++ b/ftxui/src/ftxui/screen/screen.cpp @@ -1,26 +1,46 @@ -#include "ftxui/screen.hpp" +#include "ftxui/screen/screen.hpp" #include "ftxui/dom/node.hpp" #include "ftxui/terminal.hpp" #include "ftxui/util/string.hpp" #include -namespace ftxui { +namespace ftxui::screen { + +static const wchar_t* BOLD_SET = L"\e[1m"; +static const wchar_t* BOLD_RESET = L"\e[22m"; // Can't use 21 here. + +static const wchar_t* DIM_SET = L"\e[2m"; +static const wchar_t* DIM_RESET = L"\e[22m"; + +static const wchar_t* UNDERLINED_SET = L"\e[4m"; +static const wchar_t* UNDERLINED_RESET = L"\e[24m"; + +static const wchar_t* BLINK_SET = L"\e[5m"; +static const wchar_t* BLINK_RESET = L"\e[25m"; + +static const wchar_t* INVERTED_SET = L"\e[7m"; +static const wchar_t* INVERTED_RESET = L"\e[27m"; Screen::Screen(size_t dimx, size_t dimy) : dimx_(dimx), dimy_(dimy), pixels_(dimy, std::vector(dimx)) {} void UpdatePixelStyle(std::wstringstream& ss, Pixel& previous, Pixel& next) { if (next.bold != previous.bold) - ss << (next.bold ? L"\e[1m" : L"\e[22m"); // Can't use 21 here. + ss << (next.bold ? BOLD_SET : BOLD_RESET); + if (next.dim != previous.dim) - ss << (next.dim ? L"\e[2m" : L"\e[22m"); + ss << (next.dim ? DIM_SET : DIM_RESET); + if (next.underlined != previous.underlined) - ss << (next.underlined ? L"\e[4m" : L"\e[24m"); + ss << (next.underlined ? UNDERLINED_SET : UNDERLINED_RESET); + if (next.blink != previous.blink) - ss << (next.blink ? L"\e[5m" : L"\e[25m"); + ss << (next.blink ? BLINK_SET : BLINK_RESET); + if (next.inverted != previous.inverted) - ss << (next.inverted ? L"\e[7m" : L"\e[27m"); + ss << (next.inverted ? INVERTED_SET : INVERTED_RESET); + if (next.foreground_color != previous.foreground_color || next.background_color != previous.background_color) { ss << L"\e[" + to_wstring(std::to_string((uint8_t)next.foreground_color)) + L"m"; @@ -84,4 +104,4 @@ void Screen::Clear() { std::vector(dimx_, Pixel())); } -}; // namespace ftxui +}; // namespace ftxui::screen