From 21644eea6bf802399b0b60e3eedf5b5cf1d69fae Mon Sep 17 00:00:00 2001 From: Arthur Sonzogni Date: Sat, 12 Jan 2019 15:00:08 +0100 Subject: [PATCH] Flatten the namespaces. Remove: * ftxui::screen * ftxui::dom * ftxui::component Keep: * ftxui --- examples/component/input.cpp | 3 +- examples/component/menu.cpp | 3 +- examples/component/menu2.cpp | 3 +- examples/component/menu_style.cpp | 3 +- examples/component/tab.cpp | 3 +- examples/component/toggle.cpp | 3 +- examples/dom/blink.cpp | 3 +- examples/dom/bold.cpp | 3 +- examples/dom/color.cpp | 3 +- examples/dom/dbox.cpp | 3 +- examples/dom/dim.cpp | 3 +- examples/dom/frame.cpp | 3 +- examples/dom/gauge.cpp | 3 +- examples/dom/inverted.cpp | 3 +- examples/dom/package_manager.cpp | 3 +- examples/dom/separator.cpp | 3 +- examples/dom/spinner.cpp | 2 - examples/dom/style_gallery.cpp | 3 +- examples/dom/underlined.cpp | 3 +- examples/dom/vbox_hbox.cpp | 3 +- examples/print_key_press.cpp | 7 +-- ftxui/CMakeLists.txt | 60 +++++-------------- ftxui/include/ftxui/README.md | 10 ++-- ftxui/include/ftxui/component/component.hpp | 27 ++++++++- .../ftxui/component/component_direction.hpp | 2 - .../ftxui/component/component_horizontal.hpp | 4 +- .../ftxui/component/component_vertical.hpp | 4 +- ftxui/include/ftxui/component/delegate.hpp | 23 +------ ftxui/include/ftxui/component/event.hpp | 4 +- ftxui/include/ftxui/component/input.hpp | 6 +- ftxui/include/ftxui/component/menu.hpp | 10 ++-- .../ftxui/component/screen_interactive.hpp | 12 ++-- ftxui/include/ftxui/component/toggle.hpp | 4 +- ftxui/include/ftxui/dom/box.hpp | 4 +- ftxui/include/ftxui/dom/elements.hpp | 6 +- ftxui/include/ftxui/dom/node.hpp | 8 +-- ftxui/include/ftxui/dom/requirement.hpp | 4 +- ftxui/include/ftxui/screen/color.hpp | 4 +- ftxui/include/ftxui/screen/screen.hpp | 10 ++-- .../include/ftxui/{util => screen}/string.hpp | 0 ftxui/src/ftxui/component/component.cpp | 8 +-- .../ftxui/component/component_direction.cpp | 3 +- .../ftxui/component/component_horizontal.cpp | 4 +- .../ftxui/component/component_vertical.cpp | 4 +- ftxui/src/ftxui/component/event.cpp | 4 +- ftxui/src/ftxui/component/input.cpp | 7 +-- ftxui/src/ftxui/component/menu.cpp | 7 +-- .../ftxui/component/screen_interactive.cpp | 41 ++++++------- ftxui/src/ftxui/component/toggle.cpp | 7 +-- ftxui/src/ftxui/dom/blink.cpp | 6 +- ftxui/src/ftxui/dom/bold.cpp | 6 +- ftxui/src/ftxui/dom/color.cpp | 8 +-- ftxui/src/ftxui/dom/composite_decorator.cpp | 4 +- ftxui/src/ftxui/dom/dbox.cpp | 4 +- ftxui/src/ftxui/dom/dim.cpp | 6 +- ftxui/src/ftxui/dom/flex.cpp | 4 +- ftxui/src/ftxui/dom/frame.cpp | 6 +- ftxui/src/ftxui/dom/gauge.cpp | 6 +- ftxui/src/ftxui/dom/gauge_test.cpp | 4 +- ftxui/src/ftxui/dom/hbox.cpp | 4 +- ftxui/src/ftxui/dom/hbox_test.cpp | 4 +- ftxui/src/ftxui/dom/inverted.cpp | 6 +- ftxui/src/ftxui/dom/node.cpp | 6 +- ftxui/src/ftxui/dom/node_decorator.cpp | 4 +- ftxui/src/ftxui/dom/node_decorator.hpp | 4 +- ftxui/src/ftxui/dom/separator.cpp | 6 +- ftxui/src/ftxui/dom/size.cpp | 4 +- ftxui/src/ftxui/dom/spinner.cpp | 6 +- ftxui/src/ftxui/dom/text.cpp | 6 +- ftxui/src/ftxui/dom/text_test.cpp | 4 +- ftxui/src/ftxui/dom/underlined.cpp | 6 +- ftxui/src/ftxui/dom/util.cpp | 4 +- ftxui/src/ftxui/dom/vbox.cpp | 4 +- ftxui/src/ftxui/dom/vbox_test.cpp | 4 +- ftxui/src/ftxui/screen/screen.cpp | 12 ++-- ftxui/src/ftxui/{util => screen}/string.cpp | 0 ftxui/src/ftxui/{ => screen}/terminal.cpp | 2 +- ftxui/src/ftxui/{ => screen}/terminal.hpp | 0 78 files changed, 219 insertions(+), 274 deletions(-) rename ftxui/include/ftxui/{util => screen}/string.hpp (100%) rename ftxui/src/ftxui/{util => screen}/string.cpp (100%) rename ftxui/src/ftxui/{ => screen}/terminal.cpp (86%) rename ftxui/src/ftxui/{ => screen}/terminal.hpp (100%) diff --git a/examples/component/input.cpp b/examples/component/input.cpp index 2238de1..66ac17c 100644 --- a/examples/component/input.cpp +++ b/examples/component/input.cpp @@ -7,8 +7,7 @@ #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: diff --git a/examples/component/menu.cpp b/examples/component/menu.cpp index d9f8434..4a75585 100644 --- a/examples/component/menu.cpp +++ b/examples/component/menu.cpp @@ -6,8 +6,7 @@ #include "ftxui/component/screen_interactive.hpp" int main(int argc, const char* argv[]) { - using namespace ftxui::component; - using namespace ftxui::screen; + using namespace ftxui; auto screen = ScreenInteractive::FixedSize(30, 3); Menu menu(screen.delegate()); menu.entries = {L"entry 1", L"entry 2", L"entry 3"}; diff --git a/examples/component/menu2.cpp b/examples/component/menu2.cpp index 5e1da52..03c26ab 100644 --- a/examples/component/menu2.cpp +++ b/examples/component/menu2.cpp @@ -8,8 +8,7 @@ #include "ftxui/component/screen_interactive.hpp" #include "ftxui/util/string.hpp" -using namespace ftxui::component; -using namespace ftxui::dom; +using namespace ftxui; class MyComponent : ComponentHorizontal { public: diff --git a/examples/component/menu_style.cpp b/examples/component/menu_style.cpp index dc7f8ca..b770641 100644 --- a/examples/component/menu_style.cpp +++ b/examples/component/menu_style.cpp @@ -6,8 +6,7 @@ #include "ftxui/component/screen_interactive.hpp" #include "ftxui/util/string.hpp" -using namespace ftxui::component; -using namespace ftxui::dom; +using namespace ftxui; class MyComponent : ComponentHorizontal { public: diff --git a/examples/component/tab.cpp b/examples/component/tab.cpp index 88375dc..92d6f29 100644 --- a/examples/component/tab.cpp +++ b/examples/component/tab.cpp @@ -7,8 +7,7 @@ #include "ftxui/component/toggle.hpp" #include "ftxui/util/string.hpp" -using namespace ftxui::component; -using namespace ftxui::dom; +using namespace ftxui; class MyComponent : ComponentVertical { public: diff --git a/examples/component/toggle.cpp b/examples/component/toggle.cpp index db679f8..2fbda8d 100644 --- a/examples/component/toggle.cpp +++ b/examples/component/toggle.cpp @@ -8,8 +8,7 @@ #include "ftxui/component/toggle.hpp" #include "ftxui/util/string.hpp" -using namespace ftxui::component; -using namespace ftxui::dom; +using namespace ftxui; class MyComponent : ComponentVertical { public: diff --git a/examples/dom/blink.cpp b/examples/dom/blink.cpp index e5c0b02..a40f95d 100644 --- a/examples/dom/blink.cpp +++ b/examples/dom/blink.cpp @@ -4,8 +4,7 @@ int main(int argc, const char *argv[]) { - using namespace ftxui::screen; - using namespace ftxui::dom; + using namespace ftxui; auto document = hbox( text(L"This text is "), diff --git a/examples/dom/bold.cpp b/examples/dom/bold.cpp index 9ee59a1..24d0fb5 100644 --- a/examples/dom/bold.cpp +++ b/examples/dom/bold.cpp @@ -4,8 +4,7 @@ int main(int argc, const char *argv[]) { - using namespace ftxui::screen; - using namespace ftxui::dom; + using namespace ftxui; auto document = hbox( text(L"This text is "), diff --git a/examples/dom/color.cpp b/examples/dom/color.cpp index 7bc42a7..2002b54 100644 --- a/examples/dom/color.cpp +++ b/examples/dom/color.cpp @@ -4,8 +4,7 @@ int main(int argc, const char *argv[]) { - using namespace ftxui::screen; - using namespace ftxui::dom; + using namespace ftxui; auto document = hbox( vbox( diff --git a/examples/dom/dbox.cpp b/examples/dom/dbox.cpp index 09483a3..cdfbed9 100644 --- a/examples/dom/dbox.cpp +++ b/examples/dom/dbox.cpp @@ -4,8 +4,7 @@ int main(int argc, const char *argv[]) { - using namespace ftxui::dom; - using namespace ftxui::screen; + using namespace ftxui; auto document = dbox( frame( diff --git a/examples/dom/dim.cpp b/examples/dom/dim.cpp index 7b834c4..57a9bd4 100644 --- a/examples/dom/dim.cpp +++ b/examples/dom/dim.cpp @@ -4,8 +4,7 @@ int main(int argc, const char *argv[]) { - using namespace ftxui::screen; - using namespace ftxui::dom; + using namespace ftxui; auto document = hbox( text(L"This text is "), diff --git a/examples/dom/frame.cpp b/examples/dom/frame.cpp index b995d0d..dd2f49e 100644 --- a/examples/dom/frame.cpp +++ b/examples/dom/frame.cpp @@ -7,8 +7,7 @@ int main(int argc, const char *argv[]) { - using namespace ftxui::dom; - using namespace ftxui::screen; + using namespace ftxui; auto document = hbox( window(text(L" main frame ") | hcenter, diff --git a/examples/dom/gauge.cpp b/examples/dom/gauge.cpp index 3b097e8..fa3fada 100644 --- a/examples/dom/gauge.cpp +++ b/examples/dom/gauge.cpp @@ -7,8 +7,7 @@ int main(int argc, const char *argv[]) { - using namespace ftxui::dom; - using namespace ftxui::screen; + using namespace ftxui; using namespace std::chrono_literals; std::string reset_position; diff --git a/examples/dom/inverted.cpp b/examples/dom/inverted.cpp index 286a0bd..53e03f9 100644 --- a/examples/dom/inverted.cpp +++ b/examples/dom/inverted.cpp @@ -4,8 +4,7 @@ int main(int argc, const char *argv[]) { - using namespace ftxui::screen; - using namespace ftxui::dom; + using namespace ftxui; auto document = hbox( text(L"This text is "), diff --git a/examples/dom/package_manager.cpp b/examples/dom/package_manager.cpp index b57ebb4..a066d02 100644 --- a/examples/dom/package_manager.cpp +++ b/examples/dom/package_manager.cpp @@ -10,8 +10,7 @@ int main(int argc, const char *argv[]) { - using namespace ftxui::screen; - using namespace ftxui::dom; + using namespace ftxui; struct Task { std::wstring name; diff --git a/examples/dom/separator.cpp b/examples/dom/separator.cpp index 18ae1b9..01ca83b 100644 --- a/examples/dom/separator.cpp +++ b/examples/dom/separator.cpp @@ -4,8 +4,7 @@ int main(int argc, const char *argv[]) { - using namespace ftxui::dom; - using namespace ftxui::screen; + using namespace ftxui; auto document = hbox( text(L"left-column"), diff --git a/examples/dom/spinner.cpp b/examples/dom/spinner.cpp index cc01487..a7d888f 100644 --- a/examples/dom/spinner.cpp +++ b/examples/dom/spinner.cpp @@ -9,8 +9,6 @@ int main(int argc, const char *argv[]) { using namespace ftxui; - using namespace ftxui::dom; - using namespace ftxui::screen; using namespace std::chrono_literals; std::string reset_position; diff --git a/examples/dom/style_gallery.cpp b/examples/dom/style_gallery.cpp index 44ec43c..9ecc0aa 100644 --- a/examples/dom/style_gallery.cpp +++ b/examples/dom/style_gallery.cpp @@ -4,8 +4,7 @@ int main(int argc, const char *argv[]) { - using namespace ftxui::screen; - using namespace ftxui::dom; + using namespace ftxui; auto document = hbox( text(L"normal") , text(L" ") , diff --git a/examples/dom/underlined.cpp b/examples/dom/underlined.cpp index dcc3817..c5f68f1 100644 --- a/examples/dom/underlined.cpp +++ b/examples/dom/underlined.cpp @@ -4,8 +4,7 @@ int main(int argc, const char *argv[]) { - using namespace ftxui::screen; - using namespace ftxui::dom; + using namespace ftxui; auto document = hbox( text(L"This text is "), diff --git a/examples/dom/vbox_hbox.cpp b/examples/dom/vbox_hbox.cpp index b67b0a6..a9cec20 100644 --- a/examples/dom/vbox_hbox.cpp +++ b/examples/dom/vbox_hbox.cpp @@ -5,8 +5,7 @@ int main(int argc, const char *argv[]) { - using namespace ftxui::screen; - using namespace ftxui::dom; + using namespace ftxui; auto document = vbox( hbox( diff --git a/examples/print_key_press.cpp b/examples/print_key_press.cpp index 4281530..fa66009 100644 --- a/examples/print_key_press.cpp +++ b/examples/print_key_press.cpp @@ -6,15 +6,14 @@ #include "ftxui/component/screen_interactive.hpp" #include "ftxui/util/string.hpp" -using namespace ftxui::component; +using namespace ftxui; class DrawKey : public Component { public: - DrawKey(Delegate* delegate) + DrawKey(Component::Delegate* delegate) : Component(delegate) {} - ftxui::dom::Element Render() override { - using namespace ftxui::dom; + Element Render() override { Children children; for (size_t i = std::max(0, (int)keys.size() - 10); i < keys.size(); ++i) { std::string code = ""; diff --git a/ftxui/CMakeLists.txt b/ftxui/CMakeLists.txt index f72a844..f45da5b 100644 --- a/ftxui/CMakeLists.txt +++ b/ftxui/CMakeLists.txt @@ -1,27 +1,11 @@ cmake_minimum_required(VERSION 3.0) -#################### -# ftxui::screen -#################### add_library(screen src/ftxui/screen/screen.cpp - src/ftxui/terminal.cpp - src/ftxui/util/string.cpp + src/ftxui/screen/terminal.cpp + src/ftxui/screen/string.cpp ) -target_include_directories(screen - PUBLIC - $ - $ - PRIVATE src -) - -target_compile_features(screen PUBLIC cxx_std_17) -target_compile_options(screen PRIVATE -Wall) - -#################### -# ftxui::dom -#################### add_library(dom src/ftxui/dom/blink.cpp src/ftxui/dom/bold.cpp @@ -45,23 +29,6 @@ add_library(dom src/ftxui/dom/vbox.cpp ) -target_include_directories(dom - PUBLIC - $ - $ - PRIVATE src -) - -target_link_libraries(dom - PUBLIC screen -) - -target_compile_features(dom PUBLIC cxx_std_17) -target_compile_options(dom PRIVATE -Wall) - -#################### -# ftxui::component -#################### add_library(component src/ftxui/component/component.cpp src/ftxui/component/component_direction.cpp @@ -74,19 +41,20 @@ add_library(component src/ftxui/component/toggle.cpp ) -target_include_directories(component - PUBLIC - $ - $ - PRIVATE src -) +target_link_libraries(dom PUBLIC screen) +target_link_libraries(component PUBLIC dom) -target_link_libraries(component - PUBLIC dom -) -target_compile_features(component PUBLIC cxx_std_17) -target_compile_options(component PRIVATE -Wall) +foreach(lib screen dom component) + target_include_directories(${lib} + PUBLIC + $ + $ + PRIVATE src + ) + target_compile_features(${lib} PUBLIC cxx_std_17) + target_compile_options(${lib} PRIVATE -Wall) +endforeach() include(GNUInstallDirs) install(TARGETS screen dom component diff --git a/ftxui/include/ftxui/README.md b/ftxui/include/ftxui/README.md index d1d2855..65de251 100644 --- a/ftxui/include/ftxui/README.md +++ b/ftxui/include/ftxui/README.md @@ -1,8 +1,8 @@ # * Level 0: terminal output. * Level 1: ftxui::Screen -* Level 2: ftxui::dom::Node -* Level 3: ftxui::component::Component +* Level 2: ftxui::Node +* Level 3: ftxui::Component ## Level 0: terminal output. The terminal you know, you can append text on it. It is represented by @@ -12,16 +12,16 @@ A rectangular grid of characters. Use Terminal::ToString() to append its content into the console. -## Level 2: ftxui::dom::Node +## Level 2: ftxui::Node A hierarchical set of element. They handle layout and Render themself on the screen. See ftxui/dom/elements.hpp You can make implement your own. -## Level 3: ftxui::component::Component +## Level 3: ftxui::Component A hierarchical set of component. A component render itself by producing - ftxui::dom::Node in Component::Render(). + ftxui::Node in Component::Render(). Some component can handle events: * keyboard diff --git a/ftxui/include/ftxui/component/component.hpp b/ftxui/include/ftxui/component/component.hpp index 3ce9107..351f792 100644 --- a/ftxui/include/ftxui/component/component.hpp +++ b/ftxui/include/ftxui/component/component.hpp @@ -5,19 +5,40 @@ #include "ftxui/component/event.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui::component { +namespace ftxui { class Delegate; class Focus; class Component { public: + + class Delegate { + public: + Delegate() {} + virtual ~Delegate() {} + + // A Delegate shadows a component. + virtual void Register(Component* component) = 0; + virtual Component* component() = 0; + + // Create new children. + virtual Delegate* NewChild() = 0; + virtual std::vector children() = 0; + + // Navigate in the tree. + virtual Delegate* PreviousSibling() = 0; + virtual Delegate* NextSibling() = 0; + virtual Delegate* Parent() = 0; + virtual Delegate* Root() = 0; + }; + // Constructor/Destructor. Component(Delegate* delegate); virtual ~Component(); // Render the component. - virtual dom::Element Render(); + virtual Element Render(); // Handle an event. By default, it calls this function on each children. virtual bool OnEvent(Event even); @@ -38,6 +59,6 @@ class Component { Delegate* delegate_; }; -} // namespace ftxui::component +} // namespace ftxui #endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_HPP */ diff --git a/ftxui/include/ftxui/component/component_direction.hpp b/ftxui/include/ftxui/component/component_direction.hpp index 1b7c6a2..ec3b23e 100644 --- a/ftxui/include/ftxui/component/component_direction.hpp +++ b/ftxui/include/ftxui/component/component_direction.hpp @@ -4,7 +4,6 @@ #include "ftxui/component/component.hpp" namespace ftxui { -namespace component { // A component where focus and events are automatically handled for you. // Please use ComponentVertical or ComponentHorizontal. @@ -20,7 +19,6 @@ class ComponentDirection : public Component { Component* active_child_; }; -} // namespace component } // namespace ftxui #endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_DIRECTION_H_ */ diff --git a/ftxui/include/ftxui/component/component_horizontal.hpp b/ftxui/include/ftxui/component/component_horizontal.hpp index d238613..5d3efe1 100644 --- a/ftxui/include/ftxui/component/component_horizontal.hpp +++ b/ftxui/include/ftxui/component/component_horizontal.hpp @@ -3,7 +3,7 @@ #include "ftxui/component/component_direction.hpp" -namespace ftxui::component { +namespace ftxui { // A component where focus and events are automatically handled for you. // It assumes its children are put in the horizontal direction. @@ -13,6 +13,6 @@ class ComponentHorizontal : public ComponentDirection { bool HandleDirection(Event) override; }; -} // namespace ftxui::component +} // namespace ftxui #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 78d59e4..cef6475 100644 --- a/ftxui/include/ftxui/component/component_vertical.hpp +++ b/ftxui/include/ftxui/component/component_vertical.hpp @@ -3,7 +3,7 @@ #include "ftxui/component/component_direction.hpp" -namespace ftxui::component { +namespace ftxui { // A component where focus and events are automatically handled for you. // It assumes its children are put in the vertical direction. @@ -13,6 +13,6 @@ class ComponentVertical : public ComponentDirection { bool HandleDirection(Event) override; }; -} // namespace ftxui::component +} // namespace ftxui #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 89be580..beb72f0 100644 --- a/ftxui/include/ftxui/component/delegate.hpp +++ b/ftxui/include/ftxui/component/delegate.hpp @@ -3,30 +3,11 @@ #include "ftxui/dom/elements.hpp" -namespace ftxui::component { +namespace ftxui { class Component; -class Delegate { - public: - Delegate() {} - virtual ~Delegate() {} - // A Delegate shadows a component. - virtual void Register(Component* component) = 0; - virtual Component* component() = 0; - - // Create new children. - virtual Delegate* NewChild() = 0; - virtual std::vector children() = 0; - - // Navigate in the tree. - virtual Delegate* PreviousSibling() = 0; - virtual Delegate* NextSibling() = 0; - virtual Delegate* Parent() = 0; - virtual Delegate* Root() = 0; -}; - -} // namespace ftxui::component +} // namespace ftxui #endif /* end of include guard: FTXUI_COMPONENT_DELEGATE_HPP */ diff --git a/ftxui/include/ftxui/component/event.hpp b/ftxui/include/ftxui/component/event.hpp index 75c26e7..724ab73 100644 --- a/ftxui/include/ftxui/component/event.hpp +++ b/ftxui/include/ftxui/component/event.hpp @@ -4,7 +4,7 @@ #include #include -namespace ftxui::component { +namespace ftxui { struct Event{ public: @@ -31,7 +31,7 @@ struct Event{ }; -} // namespace ftxui::component +} // namespace ftxui #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 8a79bfd..132ac52 100644 --- a/ftxui/include/ftxui/component/input.hpp +++ b/ftxui/include/ftxui/component/input.hpp @@ -4,7 +4,7 @@ #include "ftxui/component/component.hpp" #include -namespace ftxui::component { +namespace ftxui { class Input : public Component { public: @@ -21,13 +21,13 @@ class Input : public Component { std::function on_enter = [](){}; // Component implementation. - dom::Element Render() override; + Element Render() override; bool OnEvent(Event) override; private: int cursor_position = 0; }; -} // namespace ftxui::component +} // namespace ftxui #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 f3800d3..4d9fe9f 100644 --- a/ftxui/include/ftxui/component/menu.hpp +++ b/ftxui/include/ftxui/component/menu.hpp @@ -5,7 +5,7 @@ #include "ftxui/dom/elements.hpp" #include -namespace ftxui::component { +namespace ftxui { class Menu : public Component { public: @@ -16,16 +16,16 @@ class Menu : public Component { std::vector entries = {}; int selected = 0; - dom::Decorator active_style = dom::inverted; - dom::Decorator selected_style = dom::bold; - dom::Decorator normal_style = dom::nothing; + Decorator active_style = inverted; + Decorator selected_style = bold; + Decorator normal_style = nothing; // State update callback. std::function on_change = [](){}; std::function on_enter = [](){}; // Component implementation. - dom::Element Render() override; + Element Render() override; bool OnEvent(Event) override; }; diff --git a/ftxui/include/ftxui/component/screen_interactive.hpp b/ftxui/include/ftxui/component/screen_interactive.hpp index ac56a9c..ae2e7b9 100644 --- a/ftxui/include/ftxui/component/screen_interactive.hpp +++ b/ftxui/include/ftxui/component/screen_interactive.hpp @@ -1,26 +1,26 @@ #ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP #define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP +#include "ftxui/component/component.hpp" #include "ftxui/screen/screen.hpp" #include #include -namespace ftxui::component { +namespace ftxui { -class Delegate; -class Component; -class ScreenInteractive : public ftxui::screen::Screen { +class ScreenInteractive : public ftxui::Screen { public: static ScreenInteractive FixedSize(size_t dimx, size_t dimy); static ScreenInteractive Fullscreen(); static ScreenInteractive TerminalOutput(); ~ScreenInteractive(); - component::Delegate* delegate(); void Loop(); std::function ExitLoopClosure(); + Component::Delegate* delegate(); + private: class Delegate; std::unique_ptr delegate_; @@ -38,6 +38,6 @@ class ScreenInteractive : public ftxui::screen::Screen { ScreenInteractive(size_t dimx, size_t dimy, Dimension dimension); }; -} // namespace ftxui::component +} // namespace ftxui #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 ef6a89a..3773725 100644 --- a/ftxui/include/ftxui/component/toggle.hpp +++ b/ftxui/include/ftxui/component/toggle.hpp @@ -5,7 +5,7 @@ #include #include -namespace ftxui::component { +namespace ftxui { class Toggle : public Component { public: @@ -20,7 +20,7 @@ class Toggle : public Component { std::function on_change = [](){}; // Component implementation. - dom::Element Render() override; + Element Render() override; bool OnEvent(Event) override; }; diff --git a/ftxui/include/ftxui/dom/box.hpp b/ftxui/include/ftxui/dom/box.hpp index 8710465..ec1e5b4 100644 --- a/ftxui/include/ftxui/dom/box.hpp +++ b/ftxui/include/ftxui/dom/box.hpp @@ -1,7 +1,7 @@ #ifndef FTXUI_DOM_BOX_HPP #define FTXUI_DOM_BOX_HPP -namespace ftxui::dom { +namespace ftxui { struct Box { int left; @@ -10,6 +10,6 @@ struct Box { int bottom; }; -}; // namespace ftxui::dom +}; // namespace ftxui #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 8c3b0b0..e2672ad 100644 --- a/ftxui/include/ftxui/dom/elements.hpp +++ b/ftxui/include/ftxui/dom/elements.hpp @@ -6,13 +6,13 @@ #include "ftxui/dom/node.hpp" #include "ftxui/screen/color.hpp" -namespace ftxui::dom { +namespace ftxui { using Element = std::unique_ptr; using Decorator = std::function; using Child = std::unique_ptr; using Children = std::vector; -using Color = ftxui::screen::Color; +using Color = ftxui::Color; // --- Layout ---- Element vbox(Children); @@ -64,6 +64,6 @@ TAKE_ANY_ARGS(vbox) TAKE_ANY_ARGS(hbox) TAKE_ANY_ARGS(dbox) -}; // namespace ftxui::dom +}; // namespace ftxui #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 ecd4b99..1283262 100644 --- a/ftxui/include/ftxui/dom/node.hpp +++ b/ftxui/include/ftxui/dom/node.hpp @@ -8,7 +8,7 @@ #include "ftxui/dom/requirement.hpp" #include "ftxui/screen/screen.hpp" -namespace ftxui::dom { +namespace ftxui { class Node { public: @@ -27,7 +27,7 @@ class Node { virtual void SetBox(Box box); // Step 3: Draw this element. - virtual void Render(screen::Screen& screen); + virtual void Render(Screen& screen); std::vector> children; protected: @@ -35,8 +35,8 @@ class Node { Box box_; }; -void Render(screen::Screen& screen, Node* node); +void Render(Screen& screen, Node* node); -}; // namespace ftxui::dom +}; // namespace ftxui #endif /* end of include guard: FTXUI_DOM_NODE_HPP */ diff --git a/ftxui/include/ftxui/dom/requirement.hpp b/ftxui/include/ftxui/dom/requirement.hpp index d91c5ba..1a32e74 100644 --- a/ftxui/include/ftxui/dom/requirement.hpp +++ b/ftxui/include/ftxui/dom/requirement.hpp @@ -1,7 +1,7 @@ #ifndef FTXUI_DOM_REQUIREMENT_HPP #define FTXUI_DOM_REQUIREMENT_HPP -namespace ftxui::dom { +namespace ftxui { 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::dom +}; // namespace ftxui #endif /* end of include guard: FTXUI_REQUIREMENT_HPP */ diff --git a/ftxui/include/ftxui/screen/color.hpp b/ftxui/include/ftxui/screen/color.hpp index 43e5b42..faeb35d 100644 --- a/ftxui/include/ftxui/screen/color.hpp +++ b/ftxui/include/ftxui/screen/color.hpp @@ -3,7 +3,7 @@ #include -namespace ftxui::screen { +namespace ftxui { enum class Color : uint8_t { // --- Transparent ----- @@ -35,6 +35,6 @@ enum class Color : uint8_t { YellowLight = 93, }; -}; // namespace ftxui::screen +}; // namespace ftxui #endif /* end of include guard: FTXUI_COLOR_H_ */ diff --git a/ftxui/include/ftxui/screen/screen.hpp b/ftxui/include/ftxui/screen/screen.hpp index 04829d4..28fb51b 100644 --- a/ftxui/include/ftxui/screen/screen.hpp +++ b/ftxui/include/ftxui/screen/screen.hpp @@ -7,11 +7,11 @@ #include "ftxui/screen/color.hpp" -namespace ftxui::dom { +namespace ftxui { class Node; } -namespace ftxui::screen { +namespace ftxui { struct Pixel { wchar_t character = U' '; @@ -31,9 +31,9 @@ class Screen { // Constructor using the terminal. static Screen TerminalFullscreen(); - static Screen TerminalOutput(std::unique_ptr& element); + static Screen TerminalOutput(std::unique_ptr& element); - // dom::Node write into the screen using Screen::at. + // Node write into the screen using Screen::at. wchar_t& at(size_t x, size_t y); Pixel& PixelAt(size_t x, size_t y); @@ -56,6 +56,6 @@ class Screen { std::vector> pixels_; }; -}; // namespace ftxui::screen +}; // namespace ftxui #endif /* end of include guard: FTXUI_SCREEN_SCREEN */ diff --git a/ftxui/include/ftxui/util/string.hpp b/ftxui/include/ftxui/screen/string.hpp similarity index 100% rename from ftxui/include/ftxui/util/string.hpp rename to ftxui/include/ftxui/screen/string.hpp diff --git a/ftxui/src/ftxui/component/component.cpp b/ftxui/src/ftxui/component/component.cpp index b796031..7425198 100644 --- a/ftxui/src/ftxui/component/component.cpp +++ b/ftxui/src/ftxui/component/component.cpp @@ -2,7 +2,7 @@ #include "ftxui/component/delegate.hpp" #include -namespace ftxui::component { +namespace ftxui { Component::Component(Delegate* delegate) { delegate_ = delegate; @@ -11,8 +11,8 @@ Component::Component(Delegate* delegate) { Component::~Component() {} -dom::Element Component::Render() { - using namespace ftxui::dom; +Element Component::Render() { + using namespace ftxui; return text(L"Not implemented component"); } @@ -54,4 +54,4 @@ Component* Component::Parent() { return parent_delegate->component(); } -} // namespace ftxui::component +} // namespace ftxui diff --git a/ftxui/src/ftxui/component/component_direction.cpp b/ftxui/src/ftxui/component/component_direction.cpp index 3a49e5f..da03b72 100644 --- a/ftxui/src/ftxui/component/component_direction.cpp +++ b/ftxui/src/ftxui/component/component_direction.cpp @@ -1,6 +1,6 @@ #include "ftxui/component/component_direction.hpp" -namespace ftxui::component { +namespace ftxui { ComponentDirection::ComponentDirection(Delegate* delegate) : Component(delegate), active_child_(nullptr) {} @@ -16,6 +16,7 @@ bool ComponentDirection::OnEvent(Event event) { return true; return HandleDirection(event); + } Component* ComponentDirection::GetActiveChild() { diff --git a/ftxui/src/ftxui/component/component_horizontal.cpp b/ftxui/src/ftxui/component/component_horizontal.cpp index fb83e77..20cd173 100644 --- a/ftxui/src/ftxui/component/component_horizontal.cpp +++ b/ftxui/src/ftxui/component/component_horizontal.cpp @@ -1,6 +1,6 @@ #include "ftxui/component/component_horizontal.hpp" -namespace ftxui::component { +namespace ftxui { ComponentHorizontal::ComponentHorizontal(Delegate* delegate) : ComponentDirection(delegate) {} @@ -27,4 +27,4 @@ bool ComponentHorizontal::HandleDirection(Event event) { return false; } -} // namespace ftxui::component +} // namespace ftxui diff --git a/ftxui/src/ftxui/component/component_vertical.cpp b/ftxui/src/ftxui/component/component_vertical.cpp index 2b3b009..1233303 100644 --- a/ftxui/src/ftxui/component/component_vertical.cpp +++ b/ftxui/src/ftxui/component/component_vertical.cpp @@ -1,6 +1,6 @@ #include "ftxui/component/component_vertical.hpp" -namespace ftxui::component { +namespace ftxui { ComponentVertical::ComponentVertical(Delegate* delegate) : ComponentDirection(delegate) {} @@ -27,4 +27,4 @@ bool ComponentVertical::HandleDirection(Event event) { return false; } -} // namespace ftxui::component +} // namespace ftxui diff --git a/ftxui/src/ftxui/component/event.cpp b/ftxui/src/ftxui/component/event.cpp index b032c2b..85c8054 100644 --- a/ftxui/src/ftxui/component/event.cpp +++ b/ftxui/src/ftxui/component/event.cpp @@ -1,6 +1,6 @@ #include "ftxui/component/event.hpp" -namespace ftxui::component { +namespace ftxui { 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::component +} // namespace ftxui diff --git a/ftxui/src/ftxui/component/input.cpp b/ftxui/src/ftxui/component/input.cpp index d80863e..b5f1109 100644 --- a/ftxui/src/ftxui/component/input.cpp +++ b/ftxui/src/ftxui/component/input.cpp @@ -1,14 +1,13 @@ #include "ftxui/component/input.hpp" #include "ftxui/util/string.hpp" -namespace ftxui::component { +namespace ftxui { Input::Input(Delegate* delegate): Component(delegate) {} Input::~Input() {} // Component implementation. -dom::Element Input::Render() { - using namespace dom; +Element Input::Render() { bool is_focused = Focused(); // Placeholder. @@ -75,4 +74,4 @@ bool Input::OnEvent(Event event) { return false; } -} // namespace ftxui::component +} // namespace ftxui diff --git a/ftxui/src/ftxui/component/menu.cpp b/ftxui/src/ftxui/component/menu.cpp index d1c0a99..c1bc75e 100644 --- a/ftxui/src/ftxui/component/menu.cpp +++ b/ftxui/src/ftxui/component/menu.cpp @@ -2,12 +2,11 @@ #include #include -namespace ftxui::component { +namespace ftxui { Menu::Menu(Delegate* delegate) : Component(delegate) {} -dom::Element Menu::Render() { - using namespace dom; +Element Menu::Render() { std::vector elements; bool focused = Focused(); for (size_t i = 0; i < entries.size(); ++i) { @@ -49,4 +48,4 @@ bool Menu::OnEvent(Event event) { return false; } -} // namespace ftxui::component +} // namespace ftxui diff --git a/ftxui/src/ftxui/component/screen_interactive.cpp b/ftxui/src/ftxui/component/screen_interactive.cpp index d964ff9..13284e7 100644 --- a/ftxui/src/ftxui/component/screen_interactive.cpp +++ b/ftxui/src/ftxui/component/screen_interactive.cpp @@ -6,9 +6,9 @@ #include #include "ftxui/component/component.hpp" #include "ftxui/component/delegate.hpp" -#include "ftxui/terminal.hpp" +#include "ftxui/screen/terminal.hpp" -namespace ftxui::component { +namespace ftxui { namespace { constexpr int ESC = 27; @@ -42,13 +42,14 @@ Event GetEvent() { return Event{v1}; }; + }; // namespace -class ScreenInteractive::Delegate : public component::Delegate { +class ScreenInteractive::Delegate : public Component::Delegate { public: Delegate() : root_(this) {} - void Register(component::Component* c) override { component_ = c; } + void Register(Component* c) override { component_ = c; } std::vector> child_; Delegate* NewChild() override { @@ -67,24 +68,24 @@ class ScreenInteractive::Delegate : public component::Delegate { void OnEvent(Event event) { component_->OnEvent(event); } - std::vector children() override { - std::vector ret; + std::vector children() override { + std::vector ret; for (auto& it : child_) ret.push_back(it.get()); return ret; } - Delegate* root_; - Delegate* parent_ = nullptr; - Delegate* previous_sibling_ = nullptr; - Delegate* next_sibling_ = nullptr; - component::Component* component_; + Component::Delegate* root_; + Component::Delegate* parent_ = nullptr; + Component::Delegate* previous_sibling_ = nullptr; + Component::Delegate* next_sibling_ = nullptr; + Component* component_; - Delegate* Root() override { return root_; } - Delegate* Parent() override { return parent_; } - Delegate* PreviousSibling() override { return previous_sibling_; } - Delegate* NextSibling() override { return next_sibling_; } - component::Component* component() override { return component_; } + Component::Delegate* Root() override { return root_; } + Component::Delegate* Parent() override { return parent_; } + Component::Delegate* PreviousSibling() override { return previous_sibling_; } + Component::Delegate* NextSibling() override { return next_sibling_; } + Component* component() override { return component_; } }; ScreenInteractive::ScreenInteractive(size_t dimx, @@ -162,14 +163,14 @@ void ScreenInteractive::PrepareDraw() { 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()); } -component::Delegate* ScreenInteractive::delegate() { +Component::Delegate* ScreenInteractive::delegate() { return delegate_.get(); } @@ -177,4 +178,4 @@ std::function ScreenInteractive::ExitLoopClosure() { return [this]() { quit_ = true; }; } -} // namespace ftxui::component. +} // namespace ftxui. diff --git a/ftxui/src/ftxui/component/toggle.cpp b/ftxui/src/ftxui/component/toggle.cpp index a2d04c3..c3d3ad4 100644 --- a/ftxui/src/ftxui/component/toggle.cpp +++ b/ftxui/src/ftxui/component/toggle.cpp @@ -1,11 +1,10 @@ #include "ftxui/component/toggle.hpp" -namespace ftxui::component { +namespace ftxui { Toggle::Toggle(Delegate* delegate) : Component(delegate) {} -dom::Element Toggle::Render() { - using namespace dom; +Element Toggle::Render() { auto highlight = Focused() ? inverted : bold; Children children; @@ -40,4 +39,4 @@ bool Toggle::OnEvent(Event event) { return false; } -} // namespace ftxui::component +} // namespace ftxui diff --git a/ftxui/src/ftxui/dom/blink.cpp b/ftxui/src/ftxui/dom/blink.cpp index 4a6aa34..9d4084d 100644 --- a/ftxui/src/ftxui/dom/blink.cpp +++ b/ftxui/src/ftxui/dom/blink.cpp @@ -1,14 +1,14 @@ #include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui::dom { +namespace ftxui { class Blink : public NodeDecorator { public: Blink(Children children) : NodeDecorator(std::move(children)) {} ~Blink() override {} - void Render(screen::Screen& screen) override { + void Render(Screen& screen) override { Node::Render(screen); for (int y = box_.top; y <= box_.bottom; ++y) { for (int x = box_.left; x <= box_.right; ++x) { @@ -22,4 +22,4 @@ std::unique_ptr blink(Child child) { return std::make_unique(unpack(std::move(child))); } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/bold.cpp b/ftxui/src/ftxui/dom/bold.cpp index 8ba87f5..8cf20a4 100644 --- a/ftxui/src/ftxui/dom/bold.cpp +++ b/ftxui/src/ftxui/dom/bold.cpp @@ -1,14 +1,14 @@ #include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui::dom { +namespace ftxui { class Bold : public NodeDecorator { public: Bold(Children children) : NodeDecorator(std::move(children)) {} ~Bold() override {} - void Render(screen::Screen& screen) override { + void Render(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; @@ -22,4 +22,4 @@ std::unique_ptr bold(Child child) { return std::make_unique(unpack(std::move(child))); } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/color.cpp b/ftxui/src/ftxui/dom/color.cpp index bace671..8c2beb3 100644 --- a/ftxui/src/ftxui/dom/color.cpp +++ b/ftxui/src/ftxui/dom/color.cpp @@ -1,14 +1,14 @@ #include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui::dom { +namespace ftxui { class BgColor : public NodeDecorator { public: BgColor(Children children, Color color) : NodeDecorator(std::move(children)), color_(color) {} - void Render(screen::Screen& screen) override { + void Render(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_; @@ -26,7 +26,7 @@ class FgColor : public NodeDecorator { : NodeDecorator(std::move(children)), color_(color) {} ~FgColor() override {} - void Render(screen::Screen& screen) override { + void Render(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_; @@ -58,4 +58,4 @@ Decorator bgcolor(Color c) { }; } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/composite_decorator.cpp b/ftxui/src/ftxui/dom/composite_decorator.cpp index 6cb81bd..c144544 100644 --- a/ftxui/src/ftxui/dom/composite_decorator.cpp +++ b/ftxui/src/ftxui/dom/composite_decorator.cpp @@ -1,7 +1,7 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui::dom { +namespace ftxui { std::unique_ptr hcenter(Element child) { return hbox(filler(), std::move(child), filler()); @@ -19,4 +19,4 @@ std::unique_ptr align_right(Element child) { return hbox(filler(), std::move(child)); } -} // namespace ftxui::dom +} // namespace ftxui diff --git a/ftxui/src/ftxui/dom/dbox.cpp b/ftxui/src/ftxui/dom/dbox.cpp index 9639da4..fdbe652 100644 --- a/ftxui/src/ftxui/dom/dbox.cpp +++ b/ftxui/src/ftxui/dom/dbox.cpp @@ -1,7 +1,7 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui::dom { +namespace ftxui { class DBox : public Node { public: @@ -32,4 +32,4 @@ std::unique_ptr dbox(Children children) { return std::make_unique(std::move(children)); } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/dim.cpp b/ftxui/src/ftxui/dom/dim.cpp index e72b9d6..bf3aff2 100644 --- a/ftxui/src/ftxui/dom/dim.cpp +++ b/ftxui/src/ftxui/dom/dim.cpp @@ -1,9 +1,9 @@ #include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui::dom { +namespace ftxui { -using ftxui::screen::Screen; +using ftxui::Screen; class Dim : public NodeDecorator { public: @@ -24,4 +24,4 @@ std::unique_ptr dim(Child child) { return std::make_unique(unpack(std::move(child))); } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/flex.cpp b/ftxui/src/ftxui/dom/flex.cpp index fbd79ba..f4945b9 100644 --- a/ftxui/src/ftxui/dom/flex.cpp +++ b/ftxui/src/ftxui/dom/flex.cpp @@ -1,7 +1,7 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui::dom { +namespace ftxui { class Flex : public Node { public: @@ -34,4 +34,4 @@ std::unique_ptr flex(Element child) { return std::make_unique(std::move(child)); } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/frame.cpp b/ftxui/src/ftxui/dom/frame.cpp index 41fcedb..7053c98 100644 --- a/ftxui/src/ftxui/dom/frame.cpp +++ b/ftxui/src/ftxui/dom/frame.cpp @@ -1,9 +1,9 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui::dom { +namespace ftxui { -using namespace ftxui::screen; +using namespace ftxui; static wchar_t charset[] = L"┌┐└┘─│┬┴┤├"; @@ -95,4 +95,4 @@ Decorator boxed() { }; } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/gauge.cpp b/ftxui/src/ftxui/dom/gauge.cpp index c6ccebe..60cf50a 100644 --- a/ftxui/src/ftxui/dom/gauge.cpp +++ b/ftxui/src/ftxui/dom/gauge.cpp @@ -1,9 +1,9 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui::dom { +namespace ftxui { -using namespace ftxui::screen; +using namespace ftxui; static wchar_t charset[] = L" ▏▎▍▌▋▊▉█"; @@ -36,4 +36,4 @@ std::unique_ptr gauge(float progress) { return std::make_unique(progress); } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/gauge_test.cpp b/ftxui/src/ftxui/dom/gauge_test.cpp index 9b7b2b8..6e3db32 100644 --- a/ftxui/src/ftxui/dom/gauge_test.cpp +++ b/ftxui/src/ftxui/dom/gauge_test.cpp @@ -2,8 +2,8 @@ #include "ftxui/screen/screen.hpp" #include "gtest/gtest.h" -using namespace ftxui::screen; -using namespace ftxui::dom; +using namespace ftxui; +using namespace ftxui; TEST(GaugeTest, zero) { auto root = gauge(0); diff --git a/ftxui/src/ftxui/dom/hbox.cpp b/ftxui/src/ftxui/dom/hbox.cpp index 6cbc202..9fbef95 100644 --- a/ftxui/src/ftxui/dom/hbox.cpp +++ b/ftxui/src/ftxui/dom/hbox.cpp @@ -1,7 +1,7 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui::dom { +namespace ftxui { class HBox : public Node { public: @@ -63,4 +63,4 @@ std::unique_ptr hbox(Children children) { return std::make_unique(std::move(children)); } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/hbox_test.cpp b/ftxui/src/ftxui/dom/hbox_test.cpp index a81723f..4985cf5 100644 --- a/ftxui/src/ftxui/dom/hbox_test.cpp +++ b/ftxui/src/ftxui/dom/hbox_test.cpp @@ -2,8 +2,8 @@ #include "ftxui/screen/screen.hpp" #include "gtest/gtest.h" -using namespace ftxui::screen; -using namespace ftxui::dom; +using namespace ftxui; +using namespace ftxui; TEST(HBoxTest, ScreenSmaller1) { auto root = hbox( diff --git a/ftxui/src/ftxui/dom/inverted.cpp b/ftxui/src/ftxui/dom/inverted.cpp index b1b3e92..095aba2 100644 --- a/ftxui/src/ftxui/dom/inverted.cpp +++ b/ftxui/src/ftxui/dom/inverted.cpp @@ -1,9 +1,9 @@ #include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui::dom { +namespace ftxui { -using ftxui::screen::Screen; +using ftxui::Screen; class Inverted : public NodeDecorator { public: @@ -24,4 +24,4 @@ std::unique_ptr inverted(Child child) { return std::make_unique(unpack(std::move(child))); } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/node.cpp b/ftxui/src/ftxui/dom/node.cpp index 5e01589..1a7245f 100644 --- a/ftxui/src/ftxui/dom/node.cpp +++ b/ftxui/src/ftxui/dom/node.cpp @@ -1,8 +1,8 @@ #include "ftxui/dom/node.hpp" -namespace ftxui::dom { +namespace ftxui { -using ftxui::screen::Screen; +using ftxui::Screen; Node::Node() {} Node::Node(std::vector> children) @@ -40,4 +40,4 @@ void Render(Screen& screen, Node* node) { node->Render(screen); } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/node_decorator.cpp b/ftxui/src/ftxui/dom/node_decorator.cpp index ec21706..73061f9 100644 --- a/ftxui/src/ftxui/dom/node_decorator.cpp +++ b/ftxui/src/ftxui/dom/node_decorator.cpp @@ -1,6 +1,6 @@ #include "ftxui/dom/node_decorator.hpp" -namespace ftxui::dom { +namespace ftxui { void NodeDecorator::ComputeRequirement() { Node::ComputeRequirement(); @@ -12,4 +12,4 @@ void NodeDecorator::SetBox(Box box) { children[0]->SetBox(box); } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/node_decorator.hpp b/ftxui/src/ftxui/dom/node_decorator.hpp index 23e6a34..4b2b5c9 100644 --- a/ftxui/src/ftxui/dom/node_decorator.hpp +++ b/ftxui/src/ftxui/dom/node_decorator.hpp @@ -4,7 +4,7 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui::dom { +namespace ftxui { // Helper class. class NodeDecorator : public Node { @@ -15,6 +15,6 @@ class NodeDecorator : public Node { void SetBox(Box box) override; }; -}; // namespace ftxui::dom +}; // namespace ftxui #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 fcbfb5b..093ac79 100644 --- a/ftxui/src/ftxui/dom/separator.cpp +++ b/ftxui/src/ftxui/dom/separator.cpp @@ -1,8 +1,8 @@ #include "ftxui/dom/node.hpp" -namespace ftxui::dom { +namespace ftxui { -using ftxui::screen::Screen; +using ftxui::Screen; class Separator : public Node { public: @@ -35,4 +35,4 @@ std::unique_ptr separator() { return std::make_unique(); } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/size.cpp b/ftxui/src/ftxui/dom/size.cpp index 68d0af5..5b54262 100644 --- a/ftxui/src/ftxui/dom/size.cpp +++ b/ftxui/src/ftxui/dom/size.cpp @@ -1,7 +1,7 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui::dom { +namespace ftxui { class Size : public Node { public: @@ -32,4 +32,4 @@ Decorator size(size_t width, size_t height) { }; } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/spinner.cpp b/ftxui/src/ftxui/dom/spinner.cpp index f4e1679..9bf5fad 100644 --- a/ftxui/src/ftxui/dom/spinner.cpp +++ b/ftxui/src/ftxui/dom/spinner.cpp @@ -1,9 +1,9 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui::dom { +namespace ftxui { -using namespace ftxui::screen; +using namespace ftxui; static const std::vector>> elements = { { @@ -276,4 +276,4 @@ std::unique_ptr spinner(int c, size_t index) { return vbox(std::move(lines)); } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/text.cpp b/ftxui/src/ftxui/dom/text.cpp index 6b38093..62bbbeb 100644 --- a/ftxui/src/ftxui/dom/text.cpp +++ b/ftxui/src/ftxui/dom/text.cpp @@ -1,8 +1,8 @@ #include "ftxui/dom/node.hpp" -namespace ftxui::dom { +namespace ftxui { -using ftxui::screen::Screen; +using ftxui::Screen; class Text : public Node { public: @@ -34,4 +34,4 @@ std::unique_ptr text(std::wstring text) { return std::make_unique(text); } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/text_test.cpp b/ftxui/src/ftxui/dom/text_test.cpp index 4765496..42c5682 100644 --- a/ftxui/src/ftxui/dom/text_test.cpp +++ b/ftxui/src/ftxui/dom/text_test.cpp @@ -2,8 +2,8 @@ #include "ftxui/screen/screen.hpp" #include "gtest/gtest.h" -using namespace ftxui::screen; -using namespace ftxui::dom; +using namespace ftxui; +using namespace ftxui; TEST(TextTest, ScreenHeightSmaller) { auto element = text(L"test"); diff --git a/ftxui/src/ftxui/dom/underlined.cpp b/ftxui/src/ftxui/dom/underlined.cpp index 32fe3ca..9b6e9bb 100644 --- a/ftxui/src/ftxui/dom/underlined.cpp +++ b/ftxui/src/ftxui/dom/underlined.cpp @@ -1,9 +1,9 @@ #include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui::dom { +namespace ftxui { -using ftxui::screen::Screen; +using ftxui::Screen; class Underlined : public NodeDecorator { public: @@ -24,4 +24,4 @@ std::unique_ptr underlined(Child child) { return std::make_unique(unpack(std::move(child))); } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/util.cpp b/ftxui/src/ftxui/dom/util.cpp index 3ca4b78..cd0fed9 100644 --- a/ftxui/src/ftxui/dom/util.cpp +++ b/ftxui/src/ftxui/dom/util.cpp @@ -1,6 +1,6 @@ #include "ftxui/dom/elements.hpp" -namespace ftxui::dom { +namespace ftxui { Element nothing(Element element) { return std::move(element); @@ -23,4 +23,4 @@ Element operator|(Element e, Decorator d) { return d(std::move(e)); } -} // namespace ftxui::dom +} // namespace ftxui diff --git a/ftxui/src/ftxui/dom/vbox.cpp b/ftxui/src/ftxui/dom/vbox.cpp index ab2e2b7..ad8a129 100644 --- a/ftxui/src/ftxui/dom/vbox.cpp +++ b/ftxui/src/ftxui/dom/vbox.cpp @@ -1,7 +1,7 @@ #include "ftxui/dom/node.hpp" #include "ftxui/dom/elements.hpp" -namespace ftxui::dom { +namespace ftxui { class VBox : public Node { public: @@ -63,4 +63,4 @@ std::unique_ptr vbox(Children children) { return std::make_unique(std::move(children)); } -}; // namespace ftxui::dom +}; // namespace ftxui diff --git a/ftxui/src/ftxui/dom/vbox_test.cpp b/ftxui/src/ftxui/dom/vbox_test.cpp index aabaaa6..a09d89d 100644 --- a/ftxui/src/ftxui/dom/vbox_test.cpp +++ b/ftxui/src/ftxui/dom/vbox_test.cpp @@ -2,8 +2,8 @@ #include "ftxui/screen/screen.hpp" #include "gtest/gtest.h" -using namespace ftxui::screen; -using namespace ftxui::dom; +using namespace ftxui; +using namespace ftxui; TEST(VBoxTest, ScreenSmaller1) { auto root = vbox(text(L"text_1"), text(L"text_2")); diff --git a/ftxui/src/ftxui/screen/screen.cpp b/ftxui/src/ftxui/screen/screen.cpp index da8c68a..98af945 100644 --- a/ftxui/src/ftxui/screen/screen.cpp +++ b/ftxui/src/ftxui/screen/screen.cpp @@ -1,11 +1,11 @@ -#include "ftxui/screen/screen.hpp" #include "ftxui/dom/node.hpp" -#include "ftxui/terminal.hpp" -#include "ftxui/util/string.hpp" +#include "ftxui/screen/screen.hpp" +#include "ftxui/screen/string.hpp" +#include "ftxui/screen/terminal.hpp" #include -namespace ftxui::screen { +namespace ftxui { static const wchar_t* BOLD_SET = L"\e[1m"; static const wchar_t* BOLD_RESET = L"\e[22m"; // Can't use 21 here. @@ -86,7 +86,7 @@ Screen Screen::TerminalFullscreen() { } // static -Screen Screen::TerminalOutput(std::unique_ptr& element) { +Screen Screen::TerminalOutput(std::unique_ptr& element) { element->ComputeRequirement(); Terminal::Dimensions size = Terminal::Size(); return Screen(size.dimx, element->requirement().min.y); @@ -106,4 +106,4 @@ void Screen::Clear() { std::vector(dimx_, Pixel())); } -}; // namespace ftxui::screen +}; // namespace ftxui diff --git a/ftxui/src/ftxui/util/string.cpp b/ftxui/src/ftxui/screen/string.cpp similarity index 100% rename from ftxui/src/ftxui/util/string.cpp rename to ftxui/src/ftxui/screen/string.cpp diff --git a/ftxui/src/ftxui/terminal.cpp b/ftxui/src/ftxui/screen/terminal.cpp similarity index 86% rename from ftxui/src/ftxui/terminal.cpp rename to ftxui/src/ftxui/screen/terminal.cpp index b8e1347..bfc92cf 100644 --- a/ftxui/src/ftxui/terminal.cpp +++ b/ftxui/src/ftxui/screen/terminal.cpp @@ -2,7 +2,7 @@ #include #include -#include "ftxui/terminal.hpp" +#include "ftxui/screen/terminal.hpp" namespace ftxui { diff --git a/ftxui/src/ftxui/terminal.hpp b/ftxui/src/ftxui/screen/terminal.hpp similarity index 100% rename from ftxui/src/ftxui/terminal.hpp rename to ftxui/src/ftxui/screen/terminal.hpp