diff --git a/.clang-format b/.clang-format index 0f21d0b..2dc5fa5 100644 --- a/.clang-format +++ b/.clang-format @@ -2,3 +2,4 @@ # http://clang.llvm.org/docs/ClangFormatStyleOptions.html BasedOnStyle: Chromium Standard: Cpp11 +IndentPPDirectives: BeforeHash diff --git a/include/ftxui/component/checkbox.hpp b/include/ftxui/component/checkbox.hpp index ea69b08..7428e53 100644 --- a/include/ftxui/component/checkbox.hpp +++ b/include/ftxui/component/checkbox.hpp @@ -1,9 +1,10 @@ #ifndef FTXUI_COMPONENT_CHECKBOX_HPP #define FTXUI_COMPONENT_CHECKBOX_HPP -#include "ftxui/component/component.hpp" #include +#include "ftxui/component/component.hpp" + namespace ftxui { class CheckBox : public Component { @@ -15,8 +16,8 @@ class CheckBox : public Component { bool state = false; std::wstring label = L"label"; - //std::wstring checked = L"[X] "; - //std::wstring unchecked = L"[ ] "; + // std::wstring checked = L"[X] "; + // std::wstring unchecked = L"[ ] "; std::wstring checked = L"▣ "; std::wstring unchecked = L"☐ "; @@ -24,7 +25,7 @@ class CheckBox : public Component { Decorator unfocused_style = nothing; // State update callback. - std::function on_change = [](){}; + std::function on_change = []() {}; // Component implementation. Element Render() override; diff --git a/include/ftxui/component/component.hpp b/include/ftxui/component/component.hpp index 89846e7..c68ca66 100644 --- a/include/ftxui/component/component.hpp +++ b/include/ftxui/component/component.hpp @@ -11,7 +11,6 @@ class Focus; class Component { public: - // Constructor/Destructor. Component() = default; virtual ~Component(); diff --git a/include/ftxui/component/input.hpp b/include/ftxui/component/input.hpp index 7616ff1..f0c3245 100644 --- a/include/ftxui/component/input.hpp +++ b/include/ftxui/component/input.hpp @@ -1,9 +1,10 @@ #ifndef FTXUI_COMPONENT_INPUT_H_ #define FTXUI_COMPONENT_INPUT_H_ -#include "ftxui/component/component.hpp" #include +#include "ftxui/component/component.hpp" + namespace ftxui { class Input : public Component { @@ -17,8 +18,8 @@ class Input : public Component { std::wstring placeholder; // State update callback. - std::function on_change = [](){}; - std::function on_enter = [](){}; + std::function on_change = []() {}; + std::function on_enter = []() {}; // Component implementation. Element Render() override; diff --git a/include/ftxui/component/menu.hpp b/include/ftxui/component/menu.hpp index 166800f..ca38ffd 100644 --- a/include/ftxui/component/menu.hpp +++ b/include/ftxui/component/menu.hpp @@ -1,9 +1,10 @@ #ifndef FTXUI_COMPONENT_MENU #define FTXUI_COMPONENT_MENU +#include + #include "ftxui/component/component.hpp" #include "ftxui/dom/elements.hpp" -#include namespace ftxui { @@ -22,14 +23,14 @@ class Menu : public Component { Decorator normal_style = nothing; // State update callback. - std::function on_change = [](){}; - std::function on_enter = [](){}; + std::function on_change = []() {}; + std::function on_enter = []() {}; // Component implementation. Element Render() override; bool OnEvent(Event) override; }; -} // namespace ftxui::Component +} // namespace ftxui #endif /* end of include guard: FTXUI_COMPONENT_MENU */ diff --git a/include/ftxui/component/radiobox.hpp b/include/ftxui/component/radiobox.hpp index 8a7361e..1f15a7e 100644 --- a/include/ftxui/component/radiobox.hpp +++ b/include/ftxui/component/radiobox.hpp @@ -1,9 +1,10 @@ #ifndef FTXUI_COMPONENT_RADIOBOX_HPP #define FTXUI_COMPONENT_RADIOBOX_HPP -#include "ftxui/component/component.hpp" #include +#include "ftxui/component/component.hpp" + namespace ftxui { class RadioBox : public Component { @@ -23,7 +24,7 @@ class RadioBox : public Component { Decorator unfocused_style = nothing; // State update callback. - std::function on_change = [](){}; + std::function on_change = []() {}; // Component implementation. Element Render() override; diff --git a/include/ftxui/component/screen_interactive.hpp b/include/ftxui/component/screen_interactive.hpp index 99f5ea1..d335330 100644 --- a/include/ftxui/component/screen_interactive.hpp +++ b/include/ftxui/component/screen_interactive.hpp @@ -1,12 +1,12 @@ #ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP #define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP +#include #include #include #include #include #include -#include #include "ftxui/component/event.hpp" #include "ftxui/screen/screen.hpp" @@ -15,38 +15,38 @@ namespace ftxui { class Component; class ScreenInteractive : public Screen { - public: - static ScreenInteractive FixedSize(int dimx, int dimy); - static ScreenInteractive Fullscreen(); - static ScreenInteractive FitComponent(); - static ScreenInteractive TerminalOutput(); + public: + static ScreenInteractive FixedSize(int dimx, int dimy); + static ScreenInteractive Fullscreen(); + static ScreenInteractive FitComponent(); + static ScreenInteractive TerminalOutput(); - ~ScreenInteractive(); - void Loop(Component*); - std::function ExitLoopClosure(); + ~ScreenInteractive(); + void Loop(Component*); + std::function ExitLoopClosure(); - void PostEvent(Event event); + void PostEvent(Event event); - private: - void Draw(Component* component); - void EventLoop(Component* component); + private: + void Draw(Component* component); + void EventLoop(Component* component); - enum class Dimension { - FitComponent, - Fixed, - Fullscreen, - TerminalOutput, - }; - Dimension dimension_ = Dimension::Fixed; - ScreenInteractive(int dimx, int dimy, Dimension dimension); + enum class Dimension { + FitComponent, + Fixed, + Fullscreen, + TerminalOutput, + }; + Dimension dimension_ = Dimension::Fixed; + ScreenInteractive(int dimx, int dimy, Dimension dimension); - std::condition_variable events_queue_cv; - std::mutex events_queue_mutex; - std::queue events_queue; - std::atomic quit_ = false; + std::condition_variable events_queue_cv; + std::mutex events_queue_mutex; + std::queue events_queue; + std::atomic quit_ = false; - std::string set_cursor_position; - std::string reset_cursor_position; + std::string set_cursor_position; + std::string reset_cursor_position; }; } // namespace ftxui diff --git a/include/ftxui/component/toggle.hpp b/include/ftxui/component/toggle.hpp index 2c60a17..e93e4b3 100644 --- a/include/ftxui/component/toggle.hpp +++ b/include/ftxui/component/toggle.hpp @@ -1,10 +1,11 @@ #ifndef FTXUI_COMPONENT_TOGGLE_H_ #define FTXUI_COMPONENT_TOGGLE_H_ -#include "ftxui/component/component.hpp" #include #include +#include "ftxui/component/component.hpp" + namespace ftxui { class Toggle : public Component { @@ -21,13 +22,13 @@ class Toggle : public Component { Decorator normal_style = dim; // Callback. - std::function on_change = [](){}; + std::function on_change = []() {}; // Component implementation. Element Render() override; bool OnEvent(Event) override; }; -} // namespace ftxui::Component +} // namespace ftxui #endif /* end of include guard: FTXUI_COMPONENT_TOGGLE_H_ */ diff --git a/include/ftxui/dom/node.hpp b/include/ftxui/dom/node.hpp index 18b8405..f54e6de 100644 --- a/include/ftxui/dom/node.hpp +++ b/include/ftxui/dom/node.hpp @@ -29,7 +29,8 @@ class Node { // Step 3: Draw this element. virtual void Render(Screen& screen); - std::vector> children; + std::vector> children; + protected: Requirement requirement_; Box box_; diff --git a/include/ftxui/dom/requirement.hpp b/include/ftxui/dom/requirement.hpp index d3bda6a..f2f7412 100644 --- a/include/ftxui/dom/requirement.hpp +++ b/include/ftxui/dom/requirement.hpp @@ -7,10 +7,16 @@ namespace ftxui { struct Requirement { // The required size to fully draw the element. - struct { int x = 0; int y = 0; } min; + struct { + int x = 0; + int y = 0; + } min; // How much flexibility is given to the component. - struct { int x = 0; int y = 0; } flex; + struct { + int x = 0; + int y = 0; + } flex; // Frame. enum Selection { @@ -21,6 +27,6 @@ struct Requirement { Box selected_box; }; -} // namespace ftxui +} // namespace ftxui #endif /* end of include guard: FTXUI_REQUIREMENT_HPP */ diff --git a/include/ftxui/dom/take_any_args.hpp b/include/ftxui/dom/take_any_args.hpp index eb74613..e5db345 100644 --- a/include/ftxui/dom/take_any_args.hpp +++ b/include/ftxui/dom/take_any_args.hpp @@ -10,7 +10,7 @@ inline void Merge(Elements& container, Element element) { template <> inline void Merge(Elements& container, Elements elements) { - for(auto& element : elements) + for (auto& element : elements) container.push_back(std::move(element)); } @@ -23,8 +23,8 @@ Elements unpack(Args... args) { } // Make |container| able to take any number of argments. -#define TAKE_ANY_ARGS(container) \ -template \ -Element container(Args... children) { \ - return container(unpack(std::forward(children)...)); \ -} +#define TAKE_ANY_ARGS(container) \ + template \ + Element container(Args... children) { \ + return container(unpack(std::forward(children)...)); \ + } diff --git a/include/ftxui/screen/color.hpp b/include/ftxui/screen/color.hpp index 63eda3c..b895fa8 100644 --- a/include/ftxui/screen/color.hpp +++ b/include/ftxui/screen/color.hpp @@ -35,6 +35,6 @@ enum class Color : uint8_t { YellowLight = 93, }; -} // namespace ftxui +} // namespace ftxui #endif /* end of include guard: FTXUI_COLOR_H_ */ diff --git a/include/ftxui/screen/screen.hpp b/include/ftxui/screen/screen.hpp index 06c764a..b53956c 100644 --- a/include/ftxui/screen/screen.hpp +++ b/include/ftxui/screen/screen.hpp @@ -1,15 +1,15 @@ #ifndef FTXUI_SCREEN_SCREEN #define FTXUI_SCREEN_SCREEN +#include #include #include -#include -#include "ftxui/screen/color.hpp" #include "ftxui/screen/box.hpp" +#include "ftxui/screen/color.hpp" namespace ftxui { - class Node; +class Node; } namespace ftxui { @@ -49,8 +49,8 @@ class Screen { std::string ToString(); // Get screen dimensions. - int dimx() { return dimx_;} - int dimy() { return dimy_;} + int dimx() { return dimx_; } + int dimy() { return dimy_; } // Move the terminal cursor n-lines up with n = dimy(). std::string ResetPosition(); diff --git a/include/ftxui/screen/string.hpp b/include/ftxui/screen/string.hpp index 97ead84..1a1785a 100644 --- a/include/ftxui/screen/string.hpp +++ b/include/ftxui/screen/string.hpp @@ -6,7 +6,7 @@ std::string to_string(const std::wstring& s); std::wstring to_wstring(const std::string& s); -template +template std::wstring to_wstring(T s) { return to_wstring(std::to_string(s)); } diff --git a/include/ftxui/util/autoreset.hpp b/include/ftxui/util/autoreset.hpp index 412b62e..c371f03 100644 --- a/include/ftxui/util/autoreset.hpp +++ b/include/ftxui/util/autoreset.hpp @@ -3,20 +3,20 @@ namespace ftxui { -template +template class AutoReset { public: AutoReset(T* variable, T new_value) - : variable_(variable), - previous_value_(std::move(*variable)) { + : variable_(variable), previous_value_(std::move(*variable)) { *variable_ = std::move(new_value); } ~AutoReset() { *variable_ = std::move(previous_value_); } + private: T* variable_; T previous_value_; }; -} // namespace ftxui +} // namespace ftxui #endif /* end of include guard: FTXUI_UTIL_AUTORESET_HPP */ diff --git a/src/ftxui/component/input.cpp b/src/ftxui/component/input.cpp index 4cf4486..ac3baa4 100644 --- a/src/ftxui/component/input.cpp +++ b/src/ftxui/component/input.cpp @@ -1,7 +1,9 @@ #include "ftxui/component/input.hpp" -#include "ftxui/screen/string.hpp" + #include +#include "ftxui/screen/string.hpp" + namespace ftxui { // Component implementation. @@ -22,15 +24,14 @@ Element Input::Render() { if (!is_focused) return text(content) | main_decorator; - std::wstring part_before_cursor = content.substr(0,cursor_position); + std::wstring part_before_cursor = content.substr(0, cursor_position); std::wstring part_at_cursor = cursor_position < (int)content.size() ? content.substr(cursor_position, 1) : L" "; std::wstring part_after_cursor = cursor_position < (int)content.size() - 1 ? content.substr(cursor_position + 1) : L""; - auto focused = - is_focused ? focus : select; + auto focused = is_focused ? focus : select; // clang-format off return diff --git a/src/ftxui/component/menu.cpp b/src/ftxui/component/menu.cpp index dc96e88..e949552 100644 --- a/src/ftxui/component/menu.cpp +++ b/src/ftxui/component/menu.cpp @@ -1,7 +1,7 @@ #include "ftxui/component/menu.hpp" + #include #include -#include namespace ftxui { diff --git a/src/ftxui/component/radiobox.cpp b/src/ftxui/component/radiobox.cpp index ae5320b..d098210 100644 --- a/src/ftxui/component/radiobox.cpp +++ b/src/ftxui/component/radiobox.cpp @@ -1,6 +1,7 @@ #include "ftxui/component/radiobox.hpp" -#include + #include +#include namespace ftxui { @@ -41,7 +42,7 @@ bool RadioBox::OnEvent(Event event) { return true; } - if (event == Event::Character(' ') || event==Event::Return) { + if (event == Event::Character(' ') || event == Event::Return) { selected = focused; on_change(); } diff --git a/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp index 72cf665..b834667 100644 --- a/src/ftxui/component/screen_interactive.cpp +++ b/src/ftxui/component/screen_interactive.cpp @@ -3,18 +3,20 @@ #include #include #include + +#include #include #include #include #include + #include "ftxui/component/component.hpp" #include "ftxui/screen/string.hpp" #include "ftxui/screen/terminal.hpp" -#include -#if defined(__clang__) && defined (__APPLE__) - // Quick exit is missing in standard CLang headers - #define quick_exit(a) exit(a) +#if defined(__clang__) && defined(__APPLE__) + // Quick exit is missing in standard CLang headers + #define quick_exit(a) exit(a) #endif namespace ftxui { @@ -42,14 +44,12 @@ auto install_signal_handler = [](int sig, SignalHandler handler) { on_exit_functions.push([&]() { std::signal(sig, old_signal_handler); }); }; -std::function on_resize = []{}; +std::function on_resize = [] {}; void OnResize(int /* signal */) { on_resize(); } -ScreenInteractive::ScreenInteractive(int dimx, - int dimy, - Dimension dimension) +ScreenInteractive::ScreenInteractive(int dimx, int dimy, Dimension dimension) : Screen(dimx, dimy), dimension_(dimension) {} ScreenInteractive::~ScreenInteractive() {} @@ -176,8 +176,7 @@ void ScreenInteractive::Draw(Component* component) { if (dimx != dimx_ || dimy != dimy_) { dimx_ = dimx; dimy_ = dimy; - pixels_ = std::vector>( - dimy, std::vector(dimx)); + pixels_ = std::vector>(dimy, std::vector(dimx)); cursor_.x = dimx_ - 1; cursor_.y = dimy_ - 1; } @@ -196,7 +195,7 @@ void ScreenInteractive::Draw(Component* component) { reset_cursor_position += "\x1B[" + std::to_string(dx) + "C"; } if (dy != 0) { - set_cursor_position += "\x1B[" + std::to_string(dy) + "A"; + set_cursor_position += "\x1B[" + std::to_string(dy) + "A"; reset_cursor_position += "\x1B[" + std::to_string(dy) + "B"; } } diff --git a/src/ftxui/component/toggle.cpp b/src/ftxui/component/toggle.cpp index 21c1880..8586f70 100644 --- a/src/ftxui/component/toggle.cpp +++ b/src/ftxui/component/toggle.cpp @@ -1,4 +1,5 @@ #include "ftxui/component/toggle.hpp" + #include namespace ftxui { diff --git a/src/ftxui/dom/border.cpp b/src/ftxui/dom/border.cpp index 15e5750..c22e790 100644 --- a/src/ftxui/dom/border.cpp +++ b/src/ftxui/dom/border.cpp @@ -1,8 +1,8 @@ +#include + #include "ftxui/dom/elements.hpp" #include "ftxui/dom/node.hpp" -#include - namespace ftxui { using namespace ftxui; diff --git a/src/ftxui/dom/dbox.cpp b/src/ftxui/dom/dbox.cpp index 8a912a3..50b6641 100644 --- a/src/ftxui/dom/dbox.cpp +++ b/src/ftxui/dom/dbox.cpp @@ -1,8 +1,8 @@ +#include + #include "ftxui/dom/elements.hpp" #include "ftxui/dom/node.hpp" -#include - namespace ftxui { class DBox : public Node { diff --git a/src/ftxui/dom/frame.cpp b/src/ftxui/dom/frame.cpp index 6001bfc..7a96bad 100644 --- a/src/ftxui/dom/frame.cpp +++ b/src/ftxui/dom/frame.cpp @@ -4,8 +4,6 @@ #include "ftxui/dom/node.hpp" #include "ftxui/util/autoreset.hpp" -#include - namespace ftxui { using namespace ftxui; diff --git a/src/ftxui/dom/hbox.cpp b/src/ftxui/dom/hbox.cpp index f2fa40e..c97ab0e 100644 --- a/src/ftxui/dom/hbox.cpp +++ b/src/ftxui/dom/hbox.cpp @@ -3,8 +3,6 @@ #include "ftxui/dom/elements.hpp" #include "ftxui/dom/node.hpp" -#include - namespace ftxui { class HBox : public Node { diff --git a/src/ftxui/dom/hflow.cpp b/src/ftxui/dom/hflow.cpp index 63eedd8..3aacf62 100644 --- a/src/ftxui/dom/hflow.cpp +++ b/src/ftxui/dom/hflow.cpp @@ -1,8 +1,8 @@ +#include + #include "ftxui/dom/elements.hpp" #include "ftxui/dom/node.hpp" -#include - namespace ftxui { class HFlow : public Node { diff --git a/src/ftxui/dom/size.cpp b/src/ftxui/dom/size.cpp index f526648..d5a167a 100644 --- a/src/ftxui/dom/size.cpp +++ b/src/ftxui/dom/size.cpp @@ -3,8 +3,6 @@ #include "ftxui/dom/elements.hpp" #include "ftxui/dom/node.hpp" -#include - namespace ftxui { class Size : public Node { diff --git a/src/ftxui/dom/vbox.cpp b/src/ftxui/dom/vbox.cpp index 780787b..cc61866 100644 --- a/src/ftxui/dom/vbox.cpp +++ b/src/ftxui/dom/vbox.cpp @@ -3,8 +3,6 @@ #include "ftxui/dom/elements.hpp" #include "ftxui/dom/node.hpp" -#include - namespace ftxui { class VBox : public Node { diff --git a/src/ftxui/screen/screen.cpp b/src/ftxui/screen/screen.cpp index db49372..651b1c5 100644 --- a/src/ftxui/screen/screen.cpp +++ b/src/ftxui/screen/screen.cpp @@ -7,7 +7,6 @@ #include "ftxui/screen/string.hpp" #include "ftxui/screen/terminal.hpp" - namespace ftxui { namespace { diff --git a/src/ftxui/screen/terminal.cpp b/src/ftxui/screen/terminal.cpp index 1505710..d214f93 100644 --- a/src/ftxui/screen/terminal.cpp +++ b/src/ftxui/screen/terminal.cpp @@ -3,12 +3,12 @@ #include #ifdef WIN32 -#define WIN32_LEAN_AND_MEAN -#define NOMINMAX -#include + #define WIN32_LEAN_AND_MEAN + #define NOMINMAX + #include #else -#include -#include + #include + #include #endif #include diff --git a/src/ftxui/screen/wcwidth.cpp b/src/ftxui/screen/wcwidth.cpp index ba53765..b47edb1 100644 --- a/src/ftxui/screen/wcwidth.cpp +++ b/src/ftxui/screen/wcwidth.cpp @@ -59,9 +59,10 @@ * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c */ -#include "ftxui/screen/string.hpp" #include +#include "ftxui/screen/string.hpp" + namespace { struct interval { int first;