diff --git a/examples/component/button_style.cpp b/examples/component/button_style.cpp index bf898de..204237a 100644 --- a/examples/component/button_style.cpp +++ b/examples/component/button_style.cpp @@ -1,4 +1,3 @@ -#include // for shared_ptr #include // for operator+, to_string #include "ftxui/component/captured_mouse.hpp" // for ftxui @@ -6,7 +5,7 @@ #include "ftxui/component/component_base.hpp" // for Component #include "ftxui/component/component_options.hpp" // for ButtonOption #include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive -#include "ftxui/dom/elements.hpp" // for separator, Element, text, border +#include "ftxui/dom/elements.hpp" // for Element, separator, text, border #include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Green, Color::Red using namespace ftxui; diff --git a/examples/component/custom_loop.cpp b/examples/component/custom_loop.cpp index 50702d0..05d7f99 100644 --- a/examples/component/custom_loop.cpp +++ b/examples/component/custom_loop.cpp @@ -1,12 +1,12 @@ #include // for EXIT_SUCCESS #include // for milliseconds #include // for Event +#include // for ftxui #include // for text, separator, Element, operator|, vbox, border -#include // for shared_ptr -#include // for operator+, to_string, allocator +#include // for allocator, shared_ptr +#include // for operator+, to_string #include // for sleep_for -#include "ftxui/component/captured_mouse.hpp" // for ftxui #include "ftxui/component/component.hpp" // for CatchEvent, Renderer, operator|= #include "ftxui/component/loop.hpp" // for Loop #include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive diff --git a/examples/component/focus_cursor.cpp b/examples/component/focus_cursor.cpp index 4bc6a1e..3f3a25e 100644 --- a/examples/component/focus_cursor.cpp +++ b/examples/component/focus_cursor.cpp @@ -1,10 +1,9 @@ -#include // for allocator, shared_ptr, __shared_ptr_access -#include // for operator+, char_traits, to_string, string -#include // for vector +#include // for ftxui +#include // for allocator, operator+, char_traits, string -#include "ftxui/component/component.hpp" // for Slider, Renderer, Vertical -#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive -#include "ftxui/dom/elements.hpp" // for Elements, Element, operator|, separator, text, focusPositionRelative, size, border, flex, frame, bgcolor, gridbox, vbox, EQUAL, center, HEIGHT, WIDTH +#include "ftxui/component/component.hpp" // for Renderer, Vertical +#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive, Component +#include "ftxui/dom/elements.hpp" // for text, Decorator, focus, focusCursorBar, focusCursorBarBlinking, focusCursorBlock, focusCursorBlockBlinking, focusCursorUnderline, focusCursorUnderlineBlinking, hbox, Element using namespace ftxui; diff --git a/examples/component/homescreen.cpp b/examples/component/homescreen.cpp index 2f5370a..a947d69 100644 --- a/examples/component/homescreen.cpp +++ b/examples/component/homescreen.cpp @@ -5,14 +5,14 @@ #include // for sin #include // for ref, reference_wrapper, function #include // for allocator, shared_ptr, __shared_ptr_access -#include // for string, basic_string, operator+, to_string, char_traits +#include // for string, basic_string, char_traits, operator+, to_string #include // for sleep_for, thread #include // for move #include // for vector #include "../dom/color_info_sorted_2d.ipp" // for ColorInfoSorted2D #include "ftxui/component/component.hpp" // for Checkbox, Renderer, Horizontal, Vertical, Input, Menu, Radiobox, ResizableSplitLeft, Tab -#include "ftxui/component/component_base.hpp" // for ComponentBase +#include "ftxui/component/component_base.hpp" // for ComponentBase, Component #include "ftxui/component/component_options.hpp" // for MenuOption, InputOption #include "ftxui/component/event.hpp" // for Event, Event::Custom #include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive diff --git a/examples/component/maybe.cpp b/examples/component/maybe.cpp index ad0af17..b6930e1 100644 --- a/examples/component/maybe.cpp +++ b/examples/component/maybe.cpp @@ -1,12 +1,11 @@ -#include // for shared_ptr -#include // for string, basic_string, allocator +#include // for string, allocator, basic_string #include // for vector #include "ftxui/component/captured_mouse.hpp" // for ftxui #include "ftxui/component/component.hpp" // for operator|, Maybe, Checkbox, Radiobox, Renderer, Vertical #include "ftxui/component/component_base.hpp" // for Component #include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive -#include "ftxui/dom/elements.hpp" // for border, color, operator|, text, Element +#include "ftxui/dom/elements.hpp" // for Element, border, color, operator|, text #include "ftxui/screen/color.hpp" // for Color, Color::Red using namespace ftxui; diff --git a/examples/component/menu_style.cpp b/examples/component/menu_style.cpp index 3d0ecf3..b7d41fb 100644 --- a/examples/component/menu_style.cpp +++ b/examples/component/menu_style.cpp @@ -1,14 +1,14 @@ #include // for array #include // for milliseconds #include // for function -#include // for shared_ptr, __shared_ptr_access, allocator -#include // for string, char_traits, basic_string, operator+ +#include // for __shared_ptr_access, shared_ptr, allocator +#include // for string, char_traits, operator+, basic_string #include // for vector #include "ftxui/component/animation.hpp" // for ElasticOut, Linear #include "ftxui/component/component.hpp" // for Menu, Horizontal, Renderer, Vertical #include "ftxui/component/component_base.hpp" // for ComponentBase -#include "ftxui/component/component_options.hpp" // for MenuOption, MenuEntryOption, AnimatedColorOption, AnimatedColorsOption, UnderlineOption +#include "ftxui/component/component_options.hpp" // for MenuOption, EntryState, MenuEntryOption, AnimatedColorOption, AnimatedColorsOption, UnderlineOption #include "ftxui/component/mouse.hpp" // for ftxui #include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive #include "ftxui/dom/elements.hpp" // for separator, operator|, Element, text, bgcolor, hbox, bold, color, filler, border, vbox, borderDouble, dim, flex, hcenter diff --git a/examples/component/menu_underline_animated_gallery.cpp b/examples/component/menu_underline_animated_gallery.cpp index e143b8f..46dbe89 100644 --- a/examples/component/menu_underline_animated_gallery.cpp +++ b/examples/component/menu_underline_animated_gallery.cpp @@ -1,6 +1,6 @@ #include // for operator""ms, literals -#include // for shared_ptr, __shared_ptr_access, allocator -#include // for string, basic_string, operator+, to_string +#include // for allocator, shared_ptr, __shared_ptr_access +#include // for string, operator+, to_string, basic_string #include // for vector #include "ftxui/component/animation.hpp" // for BackOut, Duration diff --git a/examples/dom/gauge.cpp b/examples/dom/gauge.cpp index e8761a4..397dd5a 100644 --- a/examples/dom/gauge.cpp +++ b/examples/dom/gauge.cpp @@ -2,7 +2,7 @@ #include // for text, gauge, operator|, flex, hbox, Element #include // for Screen #include // for cout, endl, ostream -#include // for allocator, operator+, char_traits, operator<<, string, to_string, basic_string +#include // for allocator, char_traits, operator+, operator<<, string, to_string, basic_string #include // for sleep_for #include "ftxui/dom/node.hpp" // for Render diff --git a/examples/dom/gauge_direction.cpp b/examples/dom/gauge_direction.cpp index 5998447..d26eecf 100644 --- a/examples/dom/gauge_direction.cpp +++ b/examples/dom/gauge_direction.cpp @@ -1,8 +1,8 @@ #include // for operator""s, chrono_literals -#include // for text, gauge, operator|, flex, hbox, Element +#include // for filler, operator|, separator, text, border, Element, vbox, vtext, hbox, center, gaugeDown, gaugeLeft, gaugeRight, gaugeUp #include // for Screen #include // for cout, endl, ostream -#include // for allocator, operator+, char_traits, operator<<, string, to_string, basic_string +#include // for allocator, operator+, operator<<, string, to_string #include // for sleep_for #include "ftxui/dom/node.hpp" // for Render diff --git a/examples/dom/hflow.cpp b/examples/dom/hflow.cpp index d1d82f7..d010861 100644 --- a/examples/dom/hflow.cpp +++ b/examples/dom/hflow.cpp @@ -1,8 +1,7 @@ #include // for getchar #include // for operator|, size, Element, text, hcenter, Decorator, Fit, WIDTH, hflow, window, EQUAL, GREATER_THAN, HEIGHT, bold, border, dim, LESS_THAN #include // for Full, Screen -#include // for shared_ptr -#include // for allocator, operator+, to_string, char_traits, string +#include // for allocator, char_traits, operator+, to_string, string #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/color.hpp" // for ftxui diff --git a/examples/dom/html_like.cpp b/examples/dom/html_like.cpp index dc1f9fe..adab1b8 100644 --- a/examples/dom/html_like.cpp +++ b/examples/dom/html_like.cpp @@ -1,7 +1,6 @@ #include // for operator""s, chrono_literals #include // for Screen #include // for cout, ostream -#include // for shared_ptr #include // for allocator, operator<<, string #include // for sleep_for diff --git a/examples/dom/package_manager.cpp b/examples/dom/package_manager.cpp index 20f4605..5f48f93 100644 --- a/examples/dom/package_manager.cpp +++ b/examples/dom/package_manager.cpp @@ -2,7 +2,7 @@ #include // for operator|, text, Element, hbox, bold, color, filler, separator, vbox, window, gauge, Fit, size, dim, EQUAL, WIDTH #include // for Full, Screen #include // for cout, endl, ostream -#include // for list, operator!=, _List_iterator, _List_iterator<>::_Self +#include // for list, operator==, _List_iterator, _List_iterator<>::_Self #include // for allocator, shared_ptr, allocator_traits<>::value_type #include // for string, operator<<, to_string #include // for sleep_for diff --git a/examples/dom/vflow.cpp b/examples/dom/vflow.cpp index 92e0e8f..7a97e9a 100644 --- a/examples/dom/vflow.cpp +++ b/examples/dom/vflow.cpp @@ -1,8 +1,7 @@ #include // for getchar #include // for operator|, Element, size, text, hcenter, Fit, vflow, window, EQUAL, bold, border, dim, HEIGHT, WIDTH #include // for Full, Screen -#include // for shared_ptr -#include // for allocator, operator+, to_string, char_traits, string +#include // for allocator, char_traits, operator+, to_string, string #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/color.hpp" // for ftxui diff --git a/include/ftxui/component/event.hpp b/include/ftxui/component/event.hpp index 6de33b4..44f7f0c 100644 --- a/include/ftxui/component/event.hpp +++ b/include/ftxui/component/event.hpp @@ -66,9 +66,7 @@ struct Event { std::string character() const { return input_; } bool is_mouse() const { return type_ == Type::Mouse; } - struct Mouse& mouse() { - return mouse_; - } + struct Mouse& mouse() { return mouse_; } bool is_cursor_reporting() const { return type_ == Type::CursorReporting; } int cursor_x() const { return cursor_.x; } diff --git a/iwyu.imp b/iwyu.imp index e637ddb..83d8d42 100644 --- a/iwyu.imp +++ b/iwyu.imp @@ -1,4 +1,6 @@ [ + { include: ["", "private", "", "public"]}, + { include: ["", "private", "", "public"]}, { include: ["", "private", "", "public"]}, { include: ["", "private", "", "public"]}, { include: ["", "private", "", "public"]}, diff --git a/src/ftxui/component/animation.cpp b/src/ftxui/component/animation.cpp index bba5783..6938602 100644 --- a/src/ftxui/component/animation.cpp +++ b/src/ftxui/component/animation.cpp @@ -58,7 +58,7 @@ float CubicIn(float p) { // Modeled after the cubic y = (x - 1)^3 + 1 float CubicOut(float p) { - float f = (p - 1); + const float f = (p - 1); return f * f * f + 1; } @@ -69,7 +69,7 @@ float CubicInOut(float p) { if (p < 0.5F) { // NOLINT return 4 * p * p * p; } else { - float f = ((2 * p) - 2); + const float f = ((2 * p) - 2); return 0.5F * f * f * f + 1; // NOLINT } } @@ -81,7 +81,7 @@ float QuarticIn(float p) { // Modeled after the quartic y = 1 - (x - 1)^4 float QuarticOut(float p) { - float f = (p - 1); + const float f = (p - 1); return f * f * f * (1 - p) + 1; } @@ -92,7 +92,7 @@ float QuarticInOut(float p) { if (p < 0.5F) { // NOLINT return 8 * p * p * p * p; // NOLINT } else { - float f = (p - 1); + const float f = (p - 1); return -8 * f * f * f * f + 1; // NOLINT } } @@ -104,7 +104,7 @@ float QuinticIn(float p) { // Modeled after the quintic y = (x - 1)^5 + 1 float QuinticOut(float p) { - float f = (p - 1); + const float f = (p - 1); return f * f * f * f * f + 1; } @@ -214,7 +214,7 @@ float BackIn(float p) { // Modeled after overshooting cubic y = 1-((1-x)^3-(1-x)*sin((1-x)*pi)) float BackOut(float p) { - float f = (1 - p); + const float f = (1 - p); return 1 - (f * f * f - f * std::sin(f * kPi)); } @@ -223,7 +223,7 @@ float BackOut(float p) { // y = (1/2)*(1-((1-x)^3-(1-x)*sin((1-x)*pi))+1) ; [0.5, 1] float BackInOut(float p) { if (p < 0.5F) { // NOLINT - float f = 2 * p; + const float f = 2 * p; return 0.5F * (f * f * f - f * std::sin(f * kPi)); // NOLINT } else { float f = (1 - (2 * p - 1)); // NOLINT diff --git a/src/ftxui/component/button.cpp b/src/ftxui/component/button.cpp index 2fcd191..085272a 100644 --- a/src/ftxui/component/button.cpp +++ b/src/ftxui/component/button.cpp @@ -80,7 +80,7 @@ Component Button(ConstStringRef label, } auto focus_management = focused ? focus : active ? select : nothing; - EntryState state = { + const EntryState state = { *label_, false, active, diff --git a/src/ftxui/component/button_test.cpp b/src/ftxui/component/button_test.cpp index df04031..8f7add6 100644 --- a/src/ftxui/component/button_test.cpp +++ b/src/ftxui/component/button_test.cpp @@ -1,7 +1,7 @@ -#include -#include // for operator""s, chrono_literals -#include // for __shared_ptr_access, shared_ptr, allocator -#include // for string +#include // for AssertionResult, Message, TestPartResult, EXPECT_EQ, Test, EXPECT_FALSE, EXPECT_TRUE, TestInfo (ptr only), TEST +#include // for operator""s, chrono_literals +#include // for __shared_ptr_access, shared_ptr, allocator +#include // for string #include "ftxui/component/animation.hpp" // for Duration, Params #include "ftxui/component/component.hpp" // for Button, Horizontal diff --git a/src/ftxui/component/catch_event.cpp b/src/ftxui/component/catch_event.cpp index 8a83f47..d05eb3e 100644 --- a/src/ftxui/component/catch_event.cpp +++ b/src/ftxui/component/catch_event.cpp @@ -1,9 +1,10 @@ #include // for function #include // for __shared_ptr_access, __shared_ptr_access<>::element_type, shared_ptr -#include // for move +#include // for remove_reference, remove_reference<>::type +#include // for move -#include "ftxui/component/component.hpp" // for Component, Make, CatchEvent -#include "ftxui/component/component_base.hpp" // for ComponentBase +#include "ftxui/component/component.hpp" // for Make, CatchEvent, ComponentDecorator +#include "ftxui/component/component_base.hpp" // for Component, ComponentBase #include "ftxui/component/event.hpp" // for Event namespace ftxui { diff --git a/src/ftxui/component/checkbox.cpp b/src/ftxui/component/checkbox.cpp index 39a2366..14a05ff 100644 --- a/src/ftxui/component/checkbox.cpp +++ b/src/ftxui/component/checkbox.cpp @@ -22,8 +22,8 @@ class CheckboxBase : public ComponentBase { private: // Component implementation. Element Render() override { - bool is_focused = Focused(); - bool is_active = Active(); + const bool is_focused = Focused(); + const bool is_active = Active(); auto focus_management = is_focused ? focus : is_active ? select : nothing; auto state = EntryState{ *label_, diff --git a/src/ftxui/component/collapsible.cpp b/src/ftxui/component/collapsible.cpp index 884b2c4..0355d3d 100644 --- a/src/ftxui/component/collapsible.cpp +++ b/src/ftxui/component/collapsible.cpp @@ -26,7 +26,7 @@ namespace ftxui { /// /// ▼ Show details ///
-/// ``` +///  ``` Component Collapsible(ConstStringRef label, Component child, Ref show) { class Impl : public ComponentBase { public: diff --git a/src/ftxui/component/component.cpp b/src/ftxui/component/component.cpp index ba2cf6e..db83009 100644 --- a/src/ftxui/component/component.cpp +++ b/src/ftxui/component/component.cpp @@ -114,7 +114,7 @@ bool ComponentBase::OnEvent(Event event) { // NOLINT /// The default implementation dispatch the event to every child. /// @ingroup component void ComponentBase::OnAnimation(animation::Params& params) { - for (Component& child : children_) { + for (const Component& child : children_) { child->OnAnimation(params); } } diff --git a/src/ftxui/component/component_options.cpp b/src/ftxui/component/component_options.cpp index 83e8714..4c955e5 100644 --- a/src/ftxui/component/component_options.cpp +++ b/src/ftxui/component/component_options.cpp @@ -123,8 +123,8 @@ MenuOption MenuOption::Toggle() { ButtonOption ButtonOption::Ascii() { ButtonOption option; option.transform = [](const EntryState& s) { - std::string label = s.focused ? "[" + s.label + "]" // - : " " + s.label + " "; + const std::string label = s.focused ? "[" + s.label + "]" // + : " " + s.label + " "; return text(label); }; return option; diff --git a/src/ftxui/component/container.cpp b/src/ftxui/component/container.cpp index 51224e3..52efe7a 100644 --- a/src/ftxui/component/container.cpp +++ b/src/ftxui/component/container.cpp @@ -82,8 +82,8 @@ class ContainerBase : public ComponentBase { return; } for (size_t offset = 1; offset < children_.size(); ++offset) { - size_t i = ((size_t(*selector_ + offset * dir + children_.size())) % - children_.size()); + const size_t i = ((size_t(*selector_ + offset * dir + children_.size())) % + children_.size()); if (children_[i]->Focusable()) { *selector_ = (int)i; return; @@ -108,7 +108,7 @@ class VerticalContainer : public ContainerBase { } bool EventHandler(Event event) override { - int old_selected = *selector_; + const int old_selected = *selector_; if (event == Event::ArrowUp || event == Event::Character('k')) { MoveSelector(-1); } @@ -190,7 +190,7 @@ class HorizontalContainer : public ContainerBase { } bool EventHandler(Event event) override { - int old_selected = *selector_; + const int old_selected = *selector_; if (event == Event::ArrowLeft || event == Event::Character('h')) { MoveSelector(-1); } @@ -214,7 +214,7 @@ class TabContainer : public ContainerBase { using ContainerBase::ContainerBase; Element Render() override { - Component active_child = ActiveChild(); + const Component active_child = ActiveChild(); if (active_child) { return active_child->Render(); } diff --git a/src/ftxui/component/hoverable.cpp b/src/ftxui/component/hoverable.cpp index e56bb1c..9360b9f 100644 --- a/src/ftxui/component/hoverable.cpp +++ b/src/ftxui/component/hoverable.cpp @@ -1,15 +1,14 @@ -#include // for shared_ptr -#include // for move +#include // for CapturedMouse +#include // for function +#include // for move -#include "ftxui/component/component.hpp" // for Make, Button +#include "ftxui/component/component.hpp" // for ComponentDecorator, Hoverable, Make #include "ftxui/component/component_base.hpp" // for ComponentBase -#include "ftxui/component/event.hpp" // for Event, Event::Return -#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Pressed -#include "ftxui/component/screen_interactive.hpp" // for Component -#include "ftxui/dom/elements.hpp" // for operator|, Decorator, Element, operator|=, bgcolor, color, reflect, text, bold, border, inverted, nothing +#include "ftxui/component/event.hpp" // for Event +#include "ftxui/component/mouse.hpp" // for Mouse +#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive +#include "ftxui/dom/elements.hpp" // for operator|, reflect, Element #include "ftxui/screen/box.hpp" // for Box -#include "ftxui/screen/color.hpp" // for Color -#include "ftxui/util/ref.hpp" // for Ref, ConstStringRef namespace ftxui { @@ -23,7 +22,7 @@ void Post(std::function f) { f(); } -} // namespace +} // namespace /// @brief Wrap a component. Gives the ability to know if it is hovered by the /// mouse. @@ -38,11 +37,12 @@ void Post(std::function f) { /// bool hover = false; /// auto button_hover = Hoverable(button, &hover); /// ``` +// NOLINTNEXTLINE Component Hoverable(Component component, bool* hover) { class Impl : public ComponentBase { public: Impl(Component component, bool* hover) - : component_(component), hover_(hover) { + : component_(std::move(component)), hover_(hover) { Add(component_); } @@ -102,8 +102,8 @@ Component Hoverable(Component component, bool OnEvent(Event event) override { if (event.is_mouse()) { - bool hover = box_.Contain(event.mouse().x, event.mouse().y) && - CaptureMouse(event); + const bool hover = box_.Contain(event.mouse().x, event.mouse().y) && + CaptureMouse(event); if (hover != hover_) { Post(hover ? on_enter_ : on_leave_); } @@ -120,7 +120,8 @@ Component Hoverable(Component component, std::function on_leave_; }; - return Make(component, on_enter, on_leave); + return Make(std::move(component), std::move(on_enter), + std::move(on_leave)); } /// @brief Wrap a component. Gives the ability to know if it is hovered by the @@ -136,7 +137,9 @@ Component Hoverable(Component component, /// button |= Hoverable(&hover); /// ``` ComponentDecorator Hoverable(bool* hover) { - return [hover](Component component) { return Hoverable(component, hover); }; + return [hover](Component component) { + return Hoverable(std::move(component), hover); + }; } /// @brief Wrap a component. Gives the ability to know if it is hovered by the @@ -152,14 +155,16 @@ ComponentDecorator Hoverable(bool* hover) { /// int on_enter_cnt = 0; /// int on_leave_cnt = 0; /// button |= Hoverable( -/// [&]{ on_enter_cnt++; }, +/// [&]{ on_enter_cnt++; }, /// [&]{ on_leave_cnt++; } // ); /// ``` +// NOLINTNEXTLINE ComponentDecorator Hoverable(std::function on_enter, + // NOLINTNEXTLINE std::function on_leave) { return [on_enter, on_leave](Component component) { - return Hoverable(component, on_enter, on_leave); + return Hoverable(std::move(component), on_enter, on_leave); }; } @@ -177,9 +182,10 @@ ComponentDecorator Hoverable(std::function on_enter, /// auto button_hoverable = Hoverable(button, // [&](bool hover) { hovered = hover;}); /// ``` +// NOLINTNEXTLINE Component Hoverable(Component component, std::function on_change) { return Hoverable( - component, // + std::move(component), // [on_change] { on_change(true); }, // [on_change] { on_change(false); } // ); @@ -197,9 +203,10 @@ Component Hoverable(Component component, std::function on_change) { /// bool hovered = false; /// button |= Hoverable([&](bool hover) { hovered = hover;}); /// ``` +// NOLINTNEXTLINE ComponentDecorator Hoverable(std::function on_change) { return [on_change](Component component) { - return Hoverable(component, on_change); + return Hoverable(std::move(component), on_change); }; } diff --git a/src/ftxui/component/hoverable_test.cpp b/src/ftxui/component/hoverable_test.cpp index ea04a77..4e657cc 100644 --- a/src/ftxui/component/hoverable_test.cpp +++ b/src/ftxui/component/hoverable_test.cpp @@ -1,13 +1,13 @@ -#include -#include // for __shared_ptr_access, shared_ptr, allocator -#include // for string +#include // for AssertionResult, Message, TestPartResult, EXPECT_FALSE, EXPECT_EQ, Test, EXPECT_TRUE, TestInfo (ptr only), TEST +#include // for Element, text +#include // for shared_ptr, __shared_ptr_access, allocator -#include "ftxui/component/component.hpp" // for Input +#include "ftxui/component/component.hpp" // for Hoverable, Horizontal, operator|=, Renderer #include "ftxui/component/component_base.hpp" // for ComponentBase, Component -#include "ftxui/component/event.hpp" // for Event, Event::ArrowLeft, Event::ArrowRight, Event::Backspace, Event::Delete, Event::End, Event::Home -#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Button, Mouse::Left, Mouse::Motion, Mouse::Pressed -#include "ftxui/dom/node.hpp" // for Render -#include "ftxui/screen/screen.hpp" // for Screen +#include "ftxui/component/event.hpp" // for Event +#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Released +#include "ftxui/dom/node.hpp" // for Render +#include "ftxui/screen/screen.hpp" // for Screen namespace ftxui { diff --git a/src/ftxui/component/input.cpp b/src/ftxui/component/input.cpp index 66a4245..5abdaeb 100644 --- a/src/ftxui/component/input.cpp +++ b/src/ftxui/component/input.cpp @@ -1,6 +1,7 @@ #include // for max, min #include // for size_t #include // for function +#include // for shared_ptr #include // for string, allocator #include // for move #include // for vector @@ -9,14 +10,14 @@ #include "ftxui/component/component.hpp" // for Make, Input #include "ftxui/component/component_base.hpp" // for ComponentBase #include "ftxui/component/component_options.hpp" // for InputOption -#include "ftxui/component/event.hpp" // for Event, Event::ArrowLeft, Event::ArrowRight, Event::Backspace, Event::Custom, Event::Delete, Event::End, Event::Home, Event::Return +#include "ftxui/component/event.hpp" // for Event, Event::ArrowLeft, Event::ArrowLeftCtrl, Event::ArrowRight, Event::ArrowRightCtrl, Event::Backspace, Event::Custom, Event::Delete, Event::End, Event::Home, Event::Return #include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Pressed #include "ftxui/component/screen_interactive.hpp" // for Component -#include "ftxui/dom/elements.hpp" // for operator|, text, Element, reflect, inverted, Decorator, flex, focus, hbox, size, bold, dim, frame, select, EQUAL, HEIGHT +#include "ftxui/dom/elements.hpp" // for operator|, text, Element, reflect, operator|=, flex, inverted, hbox, size, bold, dim, focus, focusCursorBarBlinking, frame, select, Decorator, EQUAL, HEIGHT #include "ftxui/screen/box.hpp" // for Box -#include "ftxui/screen/string.hpp" // for GlyphPosition, GlyphCount, CellToGlyphIndex -#include "ftxui/screen/util.hpp" // for clamp -#include "ftxui/util/ref.hpp" // for StringRef, Ref, ConstStringRef +#include "ftxui/screen/string.hpp" // for GlyphPosition, WordBreakProperty, GlyphCount, Utf8ToWordBreakProperty, CellToGlyphIndex, WordBreakProperty::ALetter, WordBreakProperty::CR, WordBreakProperty::Double_Quote, WordBreakProperty::Extend, WordBreakProperty::ExtendNumLet, WordBreakProperty::Format, WordBreakProperty::Hebrew_Letter, WordBreakProperty::Katakana, WordBreakProperty::LF, WordBreakProperty::MidLetter, WordBreakProperty::MidNum, WordBreakProperty::MidNumLet, WordBreakProperty::Newline, WordBreakProperty::Numeric, WordBreakProperty::Regional_Indicator, WordBreakProperty::Single_Quote, WordBreakProperty::WSegSpace, WordBreakProperty::ZWJ +#include "ftxui/screen/util.hpp" // for clamp +#include "ftxui/util/ref.hpp" // for StringRef, Ref, ConstStringRef namespace ftxui { @@ -49,7 +50,7 @@ bool IsWordCharacter(WordBreakProperty property) { case WordBreakProperty::ZWJ: return false; } - return true; // NOT_REACHED(); + return true; // NOT_REACHED(); } std::string PasswordField(size_t size) { @@ -86,13 +87,14 @@ class InputBase : public ComponentBase { if (option_->password()) { password_content = PasswordField(content_->size()); } - std::string& content = option_->password() ? password_content : *content_; + const std::string& content = + option_->password() ? password_content : *content_; - int size = GlyphCount(content); + const int size = GlyphCount(content); cursor_position() = std::max(0, std::min(size, cursor_position())); auto main_decorator = flex | ftxui::size(HEIGHT, EQUAL, 1); - bool is_focused = Focused(); + const bool is_focused = Focused(); // placeholder. if (size == 0) { @@ -100,7 +102,7 @@ class InputBase : public ComponentBase { if (is_focused) { element |= focus; } - if (hovered_|| is_focused) { + if (hovered_ || is_focused) { element |= inverted; } return element; @@ -111,19 +113,21 @@ class InputBase : public ComponentBase { auto element = text(content) | main_decorator | reflect(box_); if (hovered_) { element |= inverted; - } + } return element; } - int index_before_cursor = GlyphPosition(content, cursor_position()); - int index_after_cursor = GlyphPosition(content, 1, index_before_cursor); - std::string part_before_cursor = content.substr(0, index_before_cursor); + const int index_before_cursor = GlyphPosition(content, cursor_position()); + const int index_after_cursor = + GlyphPosition(content, 1, index_before_cursor); + const std::string part_before_cursor = + content.substr(0, index_before_cursor); std::string part_at_cursor = " "; if (cursor_position() < size) { part_at_cursor = content.substr(index_before_cursor, index_after_cursor - index_before_cursor); } - std::string part_after_cursor = content.substr(index_after_cursor); + const std::string part_after_cursor = content.substr(index_after_cursor); auto focused = (is_focused || hovered_) ? focusCursorBarBlinking : select; return hbox({ text(part_before_cursor), @@ -140,15 +144,14 @@ class InputBase : public ComponentBase { if (event.is_mouse()) { return OnMouseEvent(event); } - std::string c; // Backspace. if (event == Event::Backspace) { if (cursor_position() == 0) { return false; } - size_t start = GlyphPosition(*content_, cursor_position() - 1); - size_t end = GlyphPosition(*content_, cursor_position()); + const size_t start = GlyphPosition(*content_, cursor_position() - 1); + const size_t end = GlyphPosition(*content_, cursor_position()); content_->erase(start, end - start); cursor_position()--; option_->on_change(); @@ -160,8 +163,8 @@ class InputBase : public ComponentBase { if (cursor_position() == int(content_->size())) { return false; } - size_t start = GlyphPosition(*content_, cursor_position()); - size_t end = GlyphPosition(*content_, cursor_position() + 1); + const size_t start = GlyphPosition(*content_, cursor_position()); + const size_t end = GlyphPosition(*content_, cursor_position() + 1); content_->erase(start, end - start); option_->on_change(); return true; @@ -211,7 +214,7 @@ class InputBase : public ComponentBase { // Content if (event.is_character()) { - size_t start = GlyphPosition(*content_, cursor_position()); + const size_t start = GlyphPosition(*content_, cursor_position()); content_->insert(start, event.character()); cursor_position()++; option_->on_change(); @@ -239,7 +242,7 @@ class InputBase : public ComponentBase { void HandleRightCtrl() { auto properties = Utf8ToWordBreakProperty(*content_); - int max = (int)properties.size(); + const int max = (int)properties.size(); // Move right, as long as right is not a word character. while (cursor_position() < max && @@ -284,7 +287,8 @@ class InputBase : public ComponentBase { if (mapping[original_cell] != original_glyph) { original_cell = mapping.size(); } - int target_cell = int(original_cell) + event.mouse().x - cursor_box_.x_min; + const int target_cell = + int(original_cell) + event.mouse().x - cursor_box_.x_min; int target_glyph = target_cell < (int)mapping.size() ? mapping[target_cell] : (int)mapping.size(); target_glyph = util::clamp(target_glyph, 0, GlyphCount(*content_)); diff --git a/src/ftxui/component/loop.cpp b/src/ftxui/component/loop.cpp index 8da8094..6578309 100644 --- a/src/ftxui/component/loop.cpp +++ b/src/ftxui/component/loop.cpp @@ -1,5 +1,8 @@ #include "ftxui/component/loop.hpp" -#include "ftxui/component/screen_interactive.hpp" + +#include // for move + +#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive, Component namespace ftxui { diff --git a/src/ftxui/component/maybe.cpp b/src/ftxui/component/maybe.cpp index ac7dc6e..dcb1629 100644 --- a/src/ftxui/component/maybe.cpp +++ b/src/ftxui/component/maybe.cpp @@ -1,6 +1,7 @@ #include // for function #include // for make_unique, __shared_ptr_access, __shared_ptr_access<>::element_type, shared_ptr -#include // for move +#include // for remove_reference, remove_reference<>::type +#include // for move #include "ftxui/component/component.hpp" // for ComponentDecorator, Maybe, Make #include "ftxui/component/component_base.hpp" // for Component, ComponentBase diff --git a/src/ftxui/component/menu.cpp b/src/ftxui/component/menu.cpp index 62cea4f..b1a2332 100644 --- a/src/ftxui/component/menu.cpp +++ b/src/ftxui/component/menu.cpp @@ -1,16 +1,16 @@ -#include // for max, reverse +#include // for max, fill_n, reverse #include // for milliseconds #include // for function -#include // for allocator, shared_ptr, allocator_traits<>::value_type, swap -#include // for char_traits, operator+, string, basic_string -#include // for move -#include // for vector, __alloc_traits<>::value_type +#include // for allocator_traits<>::value_type, swap +#include // for operator+, string +#include // for move +#include // for vector, __alloc_traits<>::value_type -#include "ftxui/component/animation.hpp" // for Animator, Linear, Params (ptr only) +#include "ftxui/component/animation.hpp" // for Animator, Linear #include "ftxui/component/captured_mouse.hpp" // for CapturedMouse #include "ftxui/component/component.hpp" // for Make, Menu, MenuEntry, Toggle #include "ftxui/component/component_base.hpp" // for ComponentBase -#include "ftxui/component/component_options.hpp" // for MenuOption, MenuEntryOption, MenuOption::Direction, UnderlineOption, AnimatedColorOption, AnimatedColorsOption, MenuOption::Down, MenuOption::Left, MenuOption::Right, MenuOption::Up +#include "ftxui/component/component_options.hpp" // for MenuOption, MenuEntryOption, MenuOption::Direction, UnderlineOption, AnimatedColorOption, AnimatedColorsOption, EntryState, MenuOption::Down, MenuOption::Left, MenuOption::Right, MenuOption::Up #include "ftxui/component/event.hpp" // for Event, Event::ArrowDown, Event::ArrowLeft, Event::ArrowRight, Event::ArrowUp, Event::End, Event::Home, Event::PageDown, Event::PageUp, Event::Return, Event::Tab, Event::TabReverse #include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Released, Mouse::WheelDown, Mouse::WheelUp, Mouse::None #include "ftxui/component/screen_interactive.hpp" // for Component @@ -109,7 +109,7 @@ class MenuBase : public ComponentBase { UpdateAnimationTarget(); Elements elements; - bool is_menu_focused = Focused(); + const bool is_menu_focused = Focused(); if (option_->elements_prefix) { elements.push_back(option_->elements_prefix()); } @@ -117,10 +117,10 @@ class MenuBase : public ComponentBase { if (i != 0 && option_->elements_infix) { elements.push_back(option_->elements_infix()); } - bool is_focused = (focused_entry() == i) && is_menu_focused; - bool is_selected = (*selected_ == i); + const bool is_focused = (focused_entry() == i) && is_menu_focused; + const bool is_selected = (*selected_ == i); - EntryState state = { + const EntryState state = { entries_[i], false, is_selected, @@ -130,7 +130,7 @@ class MenuBase : public ComponentBase { auto focus_management = is_menu_focused && (selected_focus_ == i) ? focus : nothing; - Element element = + const Element element = (option_->entries.transform ? option_->entries.transform : DefaultOptionTransform) // (state); @@ -145,7 +145,7 @@ class MenuBase : public ComponentBase { std::reverse(elements.begin(), elements.end()); } - Element bar = + const Element bar = IsHorizontal() ? hbox(std::move(elements)) : vbox(std::move(elements)); if (!option_->underline.enabled) { @@ -244,7 +244,7 @@ class MenuBase : public ComponentBase { } if (Focused()) { - int old_selected = *selected_; + const int old_selected = *selected_; if (event == Event::ArrowUp || event == Event::Character('k')) { OnUp(); } @@ -331,7 +331,7 @@ class MenuBase : public ComponentBase { if (!box_.Contain(event.mouse().x, event.mouse().y)) { return false; } - int old_selected = *selected_; + const int old_selected = *selected_; if (event.mouse().button == Mouse::WheelUp) { (*selected_)--; @@ -373,10 +373,10 @@ class MenuBase : public ComponentBase { } } - bool is_menu_focused = Focused(); + const bool is_menu_focused = Focused(); for (int i = 0; i < size(); ++i) { - bool is_focused = (focused_entry() == i) && is_menu_focused; - bool is_selected = (*selected_ == i); + const bool is_focused = (focused_entry() == i) && is_menu_focused; + const bool is_selected = (*selected_ == i); float target = is_selected ? 1.F : is_focused ? 0.5F : 0.F; // NOLINT if (animator_background_[i].to() != target) { animator_background_[i] = animation::Animator( @@ -447,16 +447,16 @@ class MenuBase : public ComponentBase { if (boxes_.empty()) { return 0.F; } - int value = IsHorizontal() ? boxes_[*selected_].x_min - box_.x_min - : boxes_[*selected_].y_min - box_.y_min; + const int value = IsHorizontal() ? boxes_[*selected_].x_min - box_.x_min + : boxes_[*selected_].y_min - box_.y_min; return float(value); } float SecondTarget() { if (boxes_.empty()) { return 0.F; } - int value = IsHorizontal() ? boxes_[*selected_].x_max - box_.x_min - : boxes_[*selected_].y_max - box_.y_min; + const int value = IsHorizontal() ? boxes_[*selected_].x_max - box_.x_min + : boxes_[*selected_].y_max - box_.y_min; return float(value); } @@ -557,17 +557,17 @@ Component MenuEntry(ConstStringRef label, Ref option) { private: Element Render() override { - bool focused = Focused(); + const bool focused = Focused(); UpdateAnimationTarget(); - EntryState state = { + const EntryState state = { *label_, false, hovered_, focused, }; - Element element = + const Element element = (option_->transform ? option_->transform : DefaultOptionTransform) // (state); @@ -576,7 +576,7 @@ Component MenuEntry(ConstStringRef label, Ref option) { } void UpdateAnimationTarget() { - bool focused = Focused(); + const bool focused = Focused(); float target = focused ? 1.F : hovered_ ? 0.5F : 0.F; // NOLINT if (target == animator_background_.to()) { return; diff --git a/src/ftxui/component/menu_test.cpp b/src/ftxui/component/menu_test.cpp index daf69d6..6634edf 100644 --- a/src/ftxui/component/menu_test.cpp +++ b/src/ftxui/component/menu_test.cpp @@ -1,7 +1,7 @@ -#include +#include // for Test, EXPECT_EQ, Message, TestPartResult, TestInfo (ptr only), TEST #include // for operator""s, chrono_literals #include // for __shared_ptr_access, shared_ptr, allocator -#include // for string +#include // for string, basic_string #include // for vector #include "ftxui/component/animation.hpp" // for Duration, Params diff --git a/src/ftxui/component/radiobox.cpp b/src/ftxui/component/radiobox.cpp index 72fcecb..94f8157 100644 --- a/src/ftxui/component/radiobox.cpp +++ b/src/ftxui/component/radiobox.cpp @@ -32,10 +32,10 @@ class RadioboxBase : public ComponentBase { Element Render() override { Clamp(); Elements elements; - bool is_menu_focused = Focused(); + const bool is_menu_focused = Focused(); for (int i = 0; i < size(); ++i) { - bool is_focused = (focused_entry() == i) && is_menu_focused; - bool is_selected = (hovered_ == i); + const bool is_focused = (focused_entry() == i) && is_menu_focused; + const bool is_selected = (hovered_ == i); auto focus_management = !is_selected ? nothing : is_menu_focused ? focus : select; @@ -66,7 +66,7 @@ class RadioboxBase : public ComponentBase { } if (Focused()) { - int old_hovered = hovered_; + const int old_hovered = hovered_; if (event == Event::ArrowUp || event == Event::Character('k')) { (hovered_)--; } @@ -141,7 +141,7 @@ class RadioboxBase : public ComponentBase { return false; } - int old_hovered = hovered_; + const int old_hovered = hovered_; if (event.mouse().button == Mouse::WheelUp) { (hovered_)--; diff --git a/src/ftxui/component/radiobox_test.cpp b/src/ftxui/component/radiobox_test.cpp index dfded22..df80eac 100644 --- a/src/ftxui/component/radiobox_test.cpp +++ b/src/ftxui/component/radiobox_test.cpp @@ -1,12 +1,15 @@ -#include +#include // for AssertionResult, Message, TestPartResult, EXPECT_EQ, EXPECT_TRUE, Test, TestInfo (ptr only), EXPECT_FALSE, TEST +#include // for yframe +#include // for Render +#include // for Screen #include // for __shared_ptr_access, shared_ptr, allocator -#include // for string +#include // for string, basic_string #include // for vector -#include "ftxui/component/component.hpp" // for Radiobox -#include "ftxui/component/component_base.hpp" // for ComponentBase +#include "ftxui/component/component.hpp" // for Radiobox, operator| +#include "ftxui/component/component_base.hpp" // for ComponentBase, Component #include "ftxui/component/component_options.hpp" // for RadioboxOption -#include "ftxui/component/event.hpp" // for Event, Event::Return, Event::ArrowDown, Event::ArrowUp, Event::Tab, Event::TabReverse +#include "ftxui/component/event.hpp" // for Event, Event::Return, Event::ArrowDown, Event::End, Event::Home, Event::Tab, Event::TabReverse, Event::PageDown, Event::PageUp, Event::ArrowUp #include "ftxui/util/ref.hpp" // for Ref namespace ftxui { diff --git a/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp index 4d0e193..4f3279e 100644 --- a/src/ftxui/component/screen_interactive.cpp +++ b/src/ftxui/component/screen_interactive.cpp @@ -1,19 +1,19 @@ #include // for copy, max, min #include // for array -#include // for operator-, milliseconds, duration, operator>=, time_point, common_type<>::type -#include // for signal, raise, SIGTSTP, SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM, SIGWINCH -#include // for fileno, size_t, stdin +#include // for operator-, milliseconds, operator>=, duration, common_type<>::type, time_point +#include // for signal, SIGTSTP, SIGABRT, SIGWINCH, raise, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM, __sighandler_t, size_t +#include // for fileno, stdin #include // for Task, Closure, AnimationTask -#include // for Pixel, Screen::Cursor, Screen -#include // for function -#include // for initializer_list -#include // for cout, ostream, basic_ostream, operator<<, endl, flush +#include // for Pixel, Screen::Cursor, Screen, Screen::Cursor::Hidden +#include // for function +#include // for initializer_list +#include // for cout, ostream, operator<<, basic_ostream, endl, flush #include // for stack #include // for thread, sleep_for -#include +#include // for _Swallow_assign, ignore #include // for decay_t #include // for move, swap -#include // for visit +#include // for visit, variant #include // for vector #include "ftxui/component/animation.hpp" // for TimePoint, Clock, Duration, Params, RequestAnimationFrame @@ -21,7 +21,7 @@ #include "ftxui/component/component_base.hpp" // for ComponentBase #include "ftxui/component/event.hpp" // for Event #include "ftxui/component/loop.hpp" // for Loop -#include "ftxui/component/receiver.hpp" // for Sender, ReceiverImpl, MakeReceiver, SenderImpl, Receiver +#include "ftxui/component/receiver.hpp" // for ReceiverImpl, Sender, MakeReceiver, SenderImpl, Receiver #include "ftxui/component/screen_interactive.hpp" #include "ftxui/component/terminal_input_parser.hpp" // for TerminalInputParser #include "ftxui/dom/node.hpp" // for Node, Render @@ -39,7 +39,7 @@ #error Must be compiled in UNICODE mode #endif #else -#include // for select, FD_ISSET, FD_SET, FD_ZERO, fd_set +#include // for select, FD_ISSET, FD_SET, FD_ZERO, fd_set, timeval #include // for tcsetattr, termios, tcgetattr, TCSANOW, cc_t, ECHO, ICANON, VMIN, VTIME #include // for STDIN_FILENO, read #endif @@ -150,8 +150,6 @@ void ftxui_on_resize(int columns, int rows) { #else // POSIX (Linux & Mac) -#include // for timeval - int CheckStdinReady(int usec_timeout) { timeval tv = {0, usec_timeout}; fd_set fds; @@ -189,10 +187,10 @@ void OnExit() { } } -std::atomic g_signal_exit_count = 0; +std::atomic g_signal_exit_count = 0; // NOLINT #if !defined(_WIN32) -std::atomic g_signal_stop_count = 0; -std::atomic g_signal_resize_count = 0; +std::atomic g_signal_stop_count = 0; // NOLINT +std::atomic g_signal_resize_count = 0; // NOLINT #endif // Async signal safe function @@ -276,7 +274,7 @@ enum class DSRMode { std::string Serialize(const std::vector& parameters) { bool first = true; std::string out; - for (DECMode parameter : parameters) { + for (const DECMode parameter : parameters) { if (!first) { out += ";"; } @@ -491,7 +489,7 @@ void ScreenInteractive::Install() { // Install signal handlers to restore the terminal state on exit. The default // signal handlers are restored on exit. - for (int signal : {SIGTERM, SIGSEGV, SIGINT, SIGILL, SIGABRT, SIGFPE}) { + for (const int signal : {SIGTERM, SIGSEGV, SIGINT, SIGILL, SIGABRT, SIGFPE}) { InstallSignalHandler(signal); } @@ -527,7 +525,7 @@ void ScreenInteractive::Install() { SetConsoleMode(stdin_handle, in_mode); SetConsoleMode(stdout_handle, out_mode); #else - for (int signal : {SIGWINCH, SIGTSTP}) { + for (const int signal : {SIGWINCH, SIGTSTP}) { InstallSignalHandler(signal); } @@ -653,8 +651,8 @@ void ScreenInteractive::HandleTask(Component component, Task& task) { } animation_requested_ = false; - animation::TimePoint now = animation::Clock::now(); - animation::Duration delta = now - previous_animation_time_; + const animation::TimePoint now = animation::Clock::now(); + const animation::Duration delta = now - previous_animation_time_; previous_animation_time_ = now; animation::Params params(delta); @@ -697,7 +695,7 @@ void ScreenInteractive::Draw(Component component) { break; } - bool resized = (dimx != dimx_) || (dimy != dimy_); + const bool resized = (dimx != dimx_) || (dimy != dimy_); ResetCursorPosition(); std::cout << ResetPosition(/*clear=*/resized); @@ -742,8 +740,8 @@ void ScreenInteractive::Draw(Component component) { reset_cursor_position = ""; { - int dx = dimx_ - 1 - cursor_.x; - int dy = dimy_ - 1 - cursor_.y; + const int dx = dimx_ - 1 - cursor_.x; + const int dy = dimy_ - 1 - cursor_.y; if (dy != 0) { set_cursor_position += "\x1B[" + std::to_string(dy) + "A"; diff --git a/src/ftxui/component/slider.cpp b/src/ftxui/component/slider.cpp index 2bb1a89..45d16e4 100644 --- a/src/ftxui/component/slider.cpp +++ b/src/ftxui/component/slider.cpp @@ -1,6 +1,7 @@ #include // for max, min #include // for SliderOption #include // for allocator +#include // for move #include "ftxui/component/captured_mouse.hpp" // for CapturedMouse #include "ftxui/component/component.hpp" // for Make, Slider @@ -12,7 +13,7 @@ #include "ftxui/screen/box.hpp" // for Box #include "ftxui/screen/color.hpp" // for Color, Color::GrayDark, Color::White #include "ftxui/screen/util.hpp" // for clamp -#include "ftxui/util/ref.hpp" // for ConstRef, ConstStringRef, Ref +#include "ftxui/util/ref.hpp" // for ConstRef, Ref, ConstStringRef namespace ftxui { @@ -43,7 +44,7 @@ class SliderBase : public ComponentBase { Element Render() override { auto gauge_color = Focused() ? color(options_->color_active) : color(options_->color_inactive); - float percent = float(value_() - min_()) / float(max_() - min_()); + const float percent = float(value_() - min_()) / float(max_() - min_()); return gaugeDirection(percent, options_->direction) | flexDirection(options_->direction) | reflect(gauge_box_) | gauge_color; diff --git a/src/ftxui/dom/box_helper.cpp b/src/ftxui/dom/box_helper.cpp index 32b8f2f..5694d5a 100644 --- a/src/ftxui/dom/box_helper.cpp +++ b/src/ftxui/dom/box_helper.cpp @@ -12,7 +12,7 @@ void ComputeGrow(std::vector* elements, int extra_space, int flex_grow_sum) { for (Element& element : *elements) { - int added_space = + const int added_space = extra_space * element.flex_grow / std::max(flex_grow_sum, 1); extra_space -= added_space; flex_grow_sum -= element.flex_grow; @@ -27,8 +27,8 @@ void ComputeShrinkEasy(std::vector* elements, int extra_space, int flex_shrink_sum) { for (Element& element : *elements) { - int added_space = extra_space * element.min_size * element.flex_shrink / - std::max(flex_shrink_sum, 1); + const int added_space = extra_space * element.min_size * + element.flex_shrink / std::max(flex_shrink_sum, 1); extra_space -= added_space; flex_shrink_sum -= element.flex_shrink * element.min_size; element.size = element.min_size + added_space; @@ -48,7 +48,7 @@ void ComputeShrinkHard(std::vector* elements, continue; } - int added_space = extra_space * element.min_size / std::max(1, size); + const int added_space = extra_space * element.min_size / std::max(1, size); extra_space -= added_space; size -= element.min_size; @@ -73,7 +73,7 @@ void Compute(std::vector* elements, int target_size) { size += element.min_size; } - int extra_space = target_size - size; + const int extra_space = target_size - size; if (extra_space >= 0) { ComputeGrow(elements, extra_space, flex_grow_sum); } else if (flex_shrink_size + extra_space >= 0) { diff --git a/src/ftxui/dom/canvas.cpp b/src/ftxui/dom/canvas.cpp index 74fdc4a..327b17e 100644 --- a/src/ftxui/dom/canvas.cpp +++ b/src/ftxui/dom/canvas.cpp @@ -1,6 +1,7 @@ #include "ftxui/dom/canvas.hpp" #include // for max, min +#include // for abs #include // for uint8_t #include // for abs #include // for Color @@ -469,7 +470,7 @@ void Canvas::DrawBlockOn(int x, int y) { cell.type = CellType::kBlock; } - uint8_t bit = (x % 2) * 2 + y % 2; + const uint8_t bit = (x % 2) * 2 + y % 2; uint8_t value = g_map_block_inversed.at(cell.content.character); value |= 1U << bit; cell.content.character = g_map_block[value]; @@ -489,7 +490,7 @@ void Canvas::DrawBlockOff(int x, int y) { } y /= 2; - uint8_t bit = (y % 2) * 2 + x % 2; + const uint8_t bit = (y % 2) * 2 + x % 2; uint8_t value = g_map_block_inversed.at(cell.content.character); value &= ~(1U << bit); cell.content.character = g_map_block[value]; @@ -510,7 +511,7 @@ void Canvas::DrawBlockToggle(int x, int y) { } y /= 2; - uint8_t bit = (y % 2) * 2 + x % 2; + const uint8_t bit = (y % 2) * 2 + x % 2; uint8_t value = g_map_block_inversed.at(cell.content.character); value ^= 1U << bit; cell.content.character = g_map_block[value]; @@ -829,8 +830,8 @@ class CanvasNodeBase : public Node { void Render(Screen& screen) override { const Canvas& c = canvas(); - int y_max = std::min(c.height() / 4, box_.y_max - box_.y_min + 1); - int x_max = std::min(c.width() / 2, box_.x_max - box_.x_min + 1); + const int y_max = std::min(c.height() / 4, box_.y_max - box_.y_min + 1); + const int x_max = std::min(c.width() / 2, box_.x_max - box_.x_min + 1); for (int y = 0; y < y_max; ++y) { for (int x = 0; x < x_max; ++x) { screen.PixelAt(box_.x_min + x, box_.y_min + y) = c.GetPixel(x, y); @@ -873,8 +874,8 @@ Element canvas(int width, int height, std::function fn) { } void Render(Screen& screen) final { - int width = (box_.x_max - box_.x_min + 1) * 2; - int height = (box_.y_max - box_.y_min + 1) * 4; + const int width = (box_.x_max - box_.x_min + 1) * 2; + const int height = (box_.y_max - box_.y_min + 1) * 4; canvas_ = Canvas(width, height); fn_(canvas_); CanvasNodeBase::Render(screen); diff --git a/src/ftxui/dom/flexbox.cpp b/src/ftxui/dom/flexbox.cpp index b2ebb9b..9a27673 100644 --- a/src/ftxui/dom/flexbox.cpp +++ b/src/ftxui/dom/flexbox.cpp @@ -145,7 +145,7 @@ class Flexbox : public Node { void SetBox(Box box) override { Node::SetBox(box); - int asked_previous = asked_; + const int asked_previous = asked_; asked_ = std::min(asked_, IsColumnOriented() ? box.y_max - box.y_min + 1 : box.x_max - box.x_min + 1); need_iteration_ = (asked_ != asked_previous); @@ -166,7 +166,7 @@ class Flexbox : public Node { children_box.x_max = box.x_min + b.x + b.dim_x - 1; children_box.y_max = box.y_min + b.y + b.dim_y - 1; - Box intersection = Box::Intersection(children_box, box); + const Box intersection = Box::Intersection(children_box, box); child->SetBox(intersection); need_iteration_ |= (intersection != children_box); diff --git a/src/ftxui/dom/flexbox_helper.cpp b/src/ftxui/dom/flexbox_helper.cpp index db1daf4..f404f2c 100644 --- a/src/ftxui/dom/flexbox_helper.cpp +++ b/src/ftxui/dom/flexbox_helper.cpp @@ -162,9 +162,9 @@ void SetY(Global& g, std::vector lines) { case FlexboxConfig::AlignContent::Stretch: { for (int i = ys.size() - 1; i >= 0; --i) { // NOLINT - int shifted = remaining_space * (i + 0) / (i + 1); + const int shifted = remaining_space * (i + 0) / (i + 1); ys[i] += shifted; - int consumed = remaining_space - shifted; + const int consumed = remaining_space - shifted; elements[i].size += consumed; remaining_space -= consumed; } @@ -200,10 +200,10 @@ void SetY(Global& g, std::vector lines) { for (size_t i = 0; i < lines.size(); ++i) { auto& element = elements[i]; for (auto* block : lines[i].blocks) { - bool stretch = + const bool stretch = block->flex_grow_y != 0 || g.config.align_content == FlexboxConfig::AlignContent::Stretch; - int size = + const int size = stretch ? element.size : std::min(element.size, block->min_size_y); switch (g.config.align_items) { case FlexboxConfig::AlignItems::FlexStart: { diff --git a/src/ftxui/dom/frame.cpp b/src/ftxui/dom/frame.cpp index e57d83f..98f24a3 100644 --- a/src/ftxui/dom/frame.cpp +++ b/src/ftxui/dom/frame.cpp @@ -102,9 +102,9 @@ class Frame : public Node { Box children_box = box; if (x_frame_) { - int external_dimx = box.x_max - box.x_min; - int internal_dimx = std::max(requirement_.min_x, external_dimx); - int focused_dimx = selected_box.x_max - selected_box.x_min; + const int external_dimx = box.x_max - box.x_min; + const int internal_dimx = std::max(requirement_.min_x, external_dimx); + const int focused_dimx = selected_box.x_max - selected_box.x_min; int dx = selected_box.x_min - external_dimx / 2 + focused_dimx / 2; dx = std::max(0, std::min(internal_dimx - external_dimx - 1, dx)); children_box.x_min = box.x_min - dx; @@ -112,9 +112,9 @@ class Frame : public Node { } if (y_frame_) { - int external_dimy = box.y_max - box.y_min; - int internal_dimy = std::max(requirement_.min_y, external_dimy); - int focused_dimy = selected_box.y_max - selected_box.y_min; + const int external_dimy = box.y_max - box.y_min; + const int internal_dimy = std::max(requirement_.min_y, external_dimy); + const int focused_dimy = selected_box.y_max - selected_box.y_min; int dy = selected_box.y_min - external_dimy / 2 + focused_dimy / 2; dy = std::max(0, std::min(internal_dimy - external_dimy - 1, dy)); children_box.y_min = box.y_min - dy; @@ -125,8 +125,8 @@ class Frame : public Node { } void Render(Screen& screen) override { - AutoReset stencil(&screen.stencil, - Box::Intersection(box_, screen.stencil)); + const AutoReset stencil(&screen.stencil, + Box::Intersection(box_, screen.stencil)); children_[0]->Render(screen); } diff --git a/src/ftxui/dom/gauge.cpp b/src/ftxui/dom/gauge.cpp index 81cb82f..755a57f 100644 --- a/src/ftxui/dom/gauge.cpp +++ b/src/ftxui/dom/gauge.cpp @@ -90,17 +90,17 @@ class Gauge : public Node { } void RenderHorizontal(Screen& screen, bool invert) { - int y = box_.y_min; + const int y = box_.y_min; if (y > box_.y_max) { return; } // Draw the progress bar horizontally. { - float progress = invert ? 1.F - progress_ : progress_; - float limit = + const float progress = invert ? 1.F - progress_ : progress_; + const float limit = (float)box_.x_min + progress * (float)(box_.x_max - box_.x_min + 1); - int limit_int = (int)limit; + const int limit_int = (int)limit; int x = box_.x_min; while (x < limit_int) { screen.at(x++, y) = charset_horizontal[9]; // NOLINT @@ -120,17 +120,17 @@ class Gauge : public Node { } void RenderVertical(Screen& screen, bool invert) { - int x = box_.x_min; + const int x = box_.x_min; if (x > box_.x_max) { return; } // Draw the progress bar vertically: { - float progress = invert ? progress_ : 1.F - progress_; - float limit = + const float progress = invert ? progress_ : 1.F - progress_; + const float limit = (float)box_.y_min + progress * (float)(box_.y_max - box_.y_min + 1); - int limit_int = (int)limit; + const int limit_int = (int)limit; int y = box_.y_min; while (y < limit_int) { screen.at(x, y++) = charset_vertical[8]; // NOLINT diff --git a/src/ftxui/dom/graph.cpp b/src/ftxui/dom/graph.cpp index 015636b..1ab8f38 100644 --- a/src/ftxui/dom/graph.cpp +++ b/src/ftxui/dom/graph.cpp @@ -37,15 +37,15 @@ class Graph : public Node { } void Render(Screen& screen) override { - int width = (box_.x_max - box_.x_min + 1) * 2; - int height = (box_.y_max - box_.y_min + 1) * 2; + const int width = (box_.x_max - box_.x_min + 1) * 2; + const int height = (box_.y_max - box_.y_min + 1) * 2; auto data = graph_function_(width, height); int i = 0; for (int x = box_.x_min; x <= box_.x_max; ++x) { - int height_1 = 2 * box_.y_max - data[i++]; - int height_2 = 2 * box_.y_max - data[i++]; + const int height_1 = 2 * box_.y_max - data[i++]; + const int height_2 = 2 * box_.y_max - data[i++]; for (int y = box_.y_min; y <= box_.y_max; ++y) { - int yy = 2 * y; + const int yy = 2 * y; int i_1 = yy < height_1 ? 0 : yy == height_1 ? 3 : 6; // NOLINT int i_2 = yy < height_2 ? 0 : yy == height_2 ? 1 : 2; // NOLINT screen.at(x, y) = charset[i_1 + i_2]; // NOLINT diff --git a/src/ftxui/dom/gridbox.cpp b/src/ftxui/dom/gridbox.cpp index 66f69d5..6580110 100644 --- a/src/ftxui/dom/gridbox.cpp +++ b/src/ftxui/dom/gridbox.cpp @@ -22,7 +22,7 @@ namespace { int Integrate(std::vector& elements) { int accu = 0; for (auto& i : elements) { - int old_accu = accu; + const int old_accu = accu; accu += i; i = old_accu; } @@ -113,8 +113,8 @@ class GridBox : public Node { } } - int target_size_x = box.x_max - box.x_min + 1; - int target_size_y = box.y_max - box.y_min + 1; + const int target_size_x = box.x_max - box.x_min + 1; + const int target_size_y = box.y_max - box.y_min + 1; box_helper::Compute(&elements_x, target_size_x); box_helper::Compute(&elements_y, target_size_y); @@ -165,15 +165,15 @@ class GridBox : public Node { /// ``` /// Output: /// ``` -///╭──────────╮╭──────╮╭──────────╮ -///│north-west││north ││north-east│ -///╰──────────╯╰──────╯╰──────────╯ -///╭──────────╮╭──────╮╭──────────╮ -///│west ││center││east │ -///╰──────────╯╰──────╯╰──────────╯ -///╭──────────╮╭──────╮╭──────────╮ -///│south-west││south ││south-east│ -///╰──────────╯╰──────╯╰──────────╯ +/// ╭──────────╮╭──────╮╭──────────╮ +/// │north-west││north ││north-east│ +/// ╰──────────╯╰──────╯╰──────────╯ +/// ╭──────────╮╭──────╮╭──────────╮ +/// │west ││center││east │ +/// ╰──────────╯╰──────╯╰──────────╯ +/// ╭──────────╮╭──────╮╭──────────╮ +/// │south-west││south ││south-east│ +/// ╰──────────╯╰──────╯╰──────────╯ /// ``` Element gridbox(std::vector lines) { return std::make_shared(std::move(lines)); diff --git a/src/ftxui/dom/hbox.cpp b/src/ftxui/dom/hbox.cpp index d268439..ba06dad 100644 --- a/src/ftxui/dom/hbox.cpp +++ b/src/ftxui/dom/hbox.cpp @@ -49,7 +49,7 @@ class HBox : public Node { element.flex_grow = requirement.flex_grow_x; element.flex_shrink = requirement.flex_shrink_x; } - int target_size = box.x_max - box.x_min + 1; + const int target_size = box.x_max - box.x_min + 1; box_helper::Compute(&elements, target_size); int x = box.x_min; diff --git a/src/ftxui/dom/scroll_indicator.cpp b/src/ftxui/dom/scroll_indicator.cpp index 2f1cfe2..a7fd83e 100644 --- a/src/ftxui/dom/scroll_indicator.cpp +++ b/src/ftxui/dom/scroll_indicator.cpp @@ -39,11 +39,11 @@ Element vscroll_indicator(Element child) { const Box& stencil = screen.stencil; - int size_inner = box_.y_max - box_.y_min; + const int size_inner = box_.y_max - box_.y_min; if (size_inner <= 0) { return; } - int size_outter = stencil.y_max - stencil.y_min + 1; + const int size_outter = stencil.y_max - stencil.y_min + 1; if (size_outter >= size_inner) { return; } @@ -51,15 +51,16 @@ Element vscroll_indicator(Element child) { int size = 2 * size_outter * size_outter / size_inner; size = std::max(size, 1); - int start_y = 2 * stencil.y_min + // - 2 * (stencil.y_min - box_.y_min) * size_outter / size_inner; + const int start_y = + 2 * stencil.y_min + // + 2 * (stencil.y_min - box_.y_min) * size_outter / size_inner; const int x = stencil.x_max; for (int y = stencil.y_min; y <= stencil.y_max; ++y) { - int y_up = 2 * y + 0; - int y_down = 2 * y + 1; - bool up = (start_y <= y_up) && (y_up <= start_y + size); - bool down = (start_y <= y_down) && (y_down <= start_y + size); + const int y_up = 2 * y + 0; + const int y_down = 2 * y + 1; + const bool up = (start_y <= y_up) && (y_up <= start_y + size); + const bool down = (start_y <= y_down) && (y_down <= start_y + size); const char* c = up ? (down ? "┃" : "╹") : (down ? "╻" : " "); // NOLINT screen.PixelAt(x, y) = Pixel(); diff --git a/src/ftxui/dom/separator.cpp b/src/ftxui/dom/separator.cpp index 8655fb7..9130d64 100644 --- a/src/ftxui/dom/separator.cpp +++ b/src/ftxui/dom/separator.cpp @@ -58,8 +58,8 @@ class SeparatorAuto : public Node { } void Render(Screen& screen) override { - bool is_column = (box_.x_max == box_.x_min); - bool is_line = (box_.y_min == box_.y_max); + const bool is_column = (box_.x_max == box_.x_min); + const bool is_line = (box_.y_min == box_.y_max); const std::string c = charsets[style_][int(is_line && !is_column)]; @@ -414,14 +414,14 @@ Element separatorHSelector(float left, int demi_cell_left = int(left_ * 2.F - 1.F); // NOLINT int demi_cell_right = int(right_ * 2.F + 2.F); // NOLINT - int y = box_.y_min; + const int y = box_.y_min; for (int x = box_.x_min; x <= box_.x_max; ++x) { Pixel& pixel = screen.PixelAt(x, y); - int a = (x - box_.x_min) * 2; - int b = a + 1; - bool a_empty = demi_cell_left == a || demi_cell_right == a; - bool b_empty = demi_cell_left == b || demi_cell_right == b; + const int a = (x - box_.x_min) * 2; + const int b = a + 1; + const bool a_empty = demi_cell_left == a || demi_cell_right == a; + const bool b_empty = demi_cell_left == b || demi_cell_right == b; if (!a_empty && !b_empty) { pixel.character = "─"; @@ -481,17 +481,17 @@ Element separatorVSelector(float up, } // This are the two location with an empty demi-cell. - int demi_cell_up = int(up_ * 2 - 1); - int demi_cell_down = int(down_ * 2 + 2); + const int demi_cell_up = int(up_ * 2 - 1); + const int demi_cell_down = int(down_ * 2 + 2); - int x = box_.x_min; + const int x = box_.x_min; for (int y = box_.y_min; y <= box_.y_max; ++y) { Pixel& pixel = screen.PixelAt(x, y); - int a = (y - box_.y_min) * 2; - int b = a + 1; - bool a_empty = demi_cell_up == a || demi_cell_down == a; - bool b_empty = demi_cell_up == b || demi_cell_down == b; + const int a = (y - box_.y_min) * 2; + const int b = a + 1; + const bool a_empty = demi_cell_up == a || demi_cell_down == a; + const bool b_empty = demi_cell_up == b || demi_cell_down == b; if (!a_empty && !b_empty) { pixel.character = "│"; diff --git a/src/ftxui/dom/table_test.cpp b/src/ftxui/dom/table_test.cpp index 1e13776..e9f8260 100644 --- a/src/ftxui/dom/table_test.cpp +++ b/src/ftxui/dom/table_test.cpp @@ -720,14 +720,14 @@ TEST(TableTest, Merge) { Screen screen(7, 7); Render(screen, table.Render()); EXPECT_EQ( - "┌─┲━┱─┐\r\n" - "│a┃b┃c│\r\n" - "┢━╋━╋━┪\r\n" - "┃d┃e┃f┃\r\n" - "┡━╋━╋━┩\r\n" - "│g┃h┃i│\r\n" - "└─┺━┹─┘", - screen.ToString()); + "┌─┲━┱─┐\r\n" + "│a┃b┃c│\r\n" + "┢━╋━╋━┪\r\n" + "┃d┃e┃f┃\r\n" + "┡━╋━╋━┩\r\n" + "│g┃h┃i│\r\n" + "└─┺━┹─┘", + screen.ToString()); } } // namespace ftxui diff --git a/src/ftxui/dom/text.cpp b/src/ftxui/dom/text.cpp index fde601d..10017e9 100644 --- a/src/ftxui/dom/text.cpp +++ b/src/ftxui/dom/text.cpp @@ -27,7 +27,7 @@ class Text : public Node { void Render(Screen& screen) override { int x = box_.x_min; - int y = box_.y_min; + const int y = box_.y_min; if (y > box_.y_max) { return; } @@ -55,7 +55,7 @@ class VText : public Node { } void Render(Screen& screen) override { - int x = box_.x_min; + const int x = box_.x_min; int y = box_.y_min; if (x + width_ - 1 > box_.x_max) { return; diff --git a/src/ftxui/dom/util.cpp b/src/ftxui/dom/util.cpp index a08de18..90c311a 100644 --- a/src/ftxui/dom/util.cpp +++ b/src/ftxui/dom/util.cpp @@ -1,8 +1,9 @@ -#include // for min -#include // for function -#include // for __shared_ptr_access, make_unique -#include // for move -#include // for vector +#include // for min +#include // for function +#include // for __shared_ptr_access, make_unique +#include // for remove_reference, remove_reference<>::type +#include // for move +#include // for vector #include "ftxui/dom/elements.hpp" // for Element, Decorator, Elements, operator|, Fit, emptyElement, nothing, operator|= #include "ftxui/dom/node.hpp" // for Node, Node::Status @@ -88,7 +89,7 @@ Element& operator|=(Element& e, Decorator d) { /// @see Fixed /// @see Full Dimensions Dimension::Fit(Element& e) { - Dimensions fullsize = Dimension::Full(); + const Dimensions fullsize = Dimension::Full(); Box box; box.x_min = 0; box.y_min = 0; diff --git a/src/ftxui/dom/vbox.cpp b/src/ftxui/dom/vbox.cpp index 5b4c331..fa75373 100644 --- a/src/ftxui/dom/vbox.cpp +++ b/src/ftxui/dom/vbox.cpp @@ -49,7 +49,7 @@ class VBox : public Node { element.flex_grow = requirement.flex_grow_y; element.flex_shrink = requirement.flex_shrink_y; } - int target_size = box.y_max - box.y_min + 1; + const int target_size = box.y_max - box.y_min + 1; box_helper::Compute(&elements, target_size); int y = box.y_min; diff --git a/src/ftxui/screen/color.cpp b/src/ftxui/screen/color.cpp index 490246d..30caf2c 100644 --- a/src/ftxui/screen/color.cpp +++ b/src/ftxui/screen/color.cpp @@ -103,11 +103,11 @@ Color::Color(uint8_t red, uint8_t green, uint8_t blue) const int database_begin = 16; const int database_end = 256; for (int i = database_begin; i < database_end; ++i) { - ColorInfo color_info = GetColorInfo(Color::Palette256(i)); - int dr = color_info.red - red; - int dg = color_info.green - green; - int db = color_info.blue - blue; - int dist = dr * dr + dg * dg + db * db; + const ColorInfo color_info = GetColorInfo(Color::Palette256(i)); + const int dr = color_info.red - red; + const int dg = color_info.green - green; + const int db = color_info.blue - blue; + const int dist = dr * dr + dg * dg + db * db; if (closest > dist) { closest = dist; best = i; @@ -186,7 +186,7 @@ Color Color::Interpolate(float t, const Color& a, const Color& b) { } case ColorType::Palette16: { - ColorInfo info = GetColorInfo(Color::Palette16(color.red_)); + const ColorInfo info = GetColorInfo(Color::Palette16(color.red_)); *red = info.red; *green = info.green; *blue = info.blue; @@ -194,7 +194,7 @@ Color Color::Interpolate(float t, const Color& a, const Color& b) { } case ColorType::Palette256: { - ColorInfo info = GetColorInfo(Color::Palette256(color.red_)); + const ColorInfo info = GetColorInfo(Color::Palette256(color.red_)); *red = info.red; *green = info.green; *blue = info.blue; diff --git a/src/ftxui/screen/screen.cpp b/src/ftxui/screen/screen.cpp index 6d19f79..96cef9f 100644 --- a/src/ftxui/screen/screen.cpp +++ b/src/ftxui/screen/screen.cpp @@ -410,7 +410,7 @@ std::string Screen::ToString() { std::stringstream ss; Pixel previous_pixel; - Pixel final_pixel; + const Pixel final_pixel; for (int y = 0; y < dimy_; ++y) { if (y != 0) { diff --git a/src/ftxui/screen/string.cpp b/src/ftxui/screen/string.cpp index 318279a..ad52bb3 100644 --- a/src/ftxui/screen/string.cpp +++ b/src/ftxui/screen/string.cpp @@ -1,5 +1,6 @@ // Content of this file was created thanks to: -// - https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/WordBreakProperty.txt +// - +// https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/WordBreakProperty.txt // - Markus Kuhn -- 2007-05-26 (Unicode 5.0) // http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c // Thanks you! @@ -7,9 +8,11 @@ #include "ftxui/screen/string.hpp" #include // for array -#include // for uint32_t, uint8_t +#include // for uint32_t, uint8_t, uint16_t, int32_t #include // for string, basic_string, wstring -#include // for std::ignore +#include // for _Swallow_assign, ignore + +#include "ftxui/screen/deprecated.hpp" // for wchar_width, wstring_width namespace { @@ -1485,7 +1488,7 @@ bool Bisearch(uint32_t ucs, const std::array table) { int min = 0; int max = N - 1; while (max >= min) { - int mid = (min + max) / 2; + const int mid = (min + max) / 2; if (ucs > table[mid].last) { // NOLINT min = mid + 1; } else if (ucs < table[mid].first) { // NOLINT @@ -1508,7 +1511,7 @@ bool Bisearch(uint32_t ucs, const std::array table, C* out) { int min = 0; int max = N - 1; while (max >= min) { - int mid = (min + max) / 2; + const int mid = (min + max) / 2; if (ucs > table[mid].last) { // NOLINT min = mid + 1; } else if (ucs < table[mid].first) { // NOLINT @@ -1574,7 +1577,7 @@ bool EatCodePoint(const std::string& input, *end = start + 1; return false; } - uint8_t C0 = input[start]; + const uint8_t C0 = input[start]; // 1 byte string. if ((C0 & 0b1000'0000) == 0b0000'0000) { // NOLINT @@ -1586,7 +1589,7 @@ bool EatCodePoint(const std::string& input, // 2 byte string. if ((C0 & 0b1110'0000) == 0b1100'0000 && // NOLINT start + 1 < input.size()) { - uint8_t C1 = input[start + 1]; + const uint8_t C1 = input[start + 1]; *ucs = 0; *ucs += C0 & 0b0001'1111; // NOLINT *ucs <<= 6; // NOLINT @@ -1598,8 +1601,8 @@ bool EatCodePoint(const std::string& input, // 3 byte string. if ((C0 & 0b1111'0000) == 0b1110'0000 && // NOLINT start + 2 < input.size()) { - uint8_t C1 = input[start + 1]; - uint8_t C2 = input[start + 2]; + const uint8_t C1 = input[start + 1]; + const uint8_t C2 = input[start + 2]; *ucs = 0; *ucs += C0 & 0b0000'1111; // NOLINT *ucs <<= 6; // NOLINT @@ -1613,9 +1616,9 @@ bool EatCodePoint(const std::string& input, // 4 byte string. if ((C0 & 0b1111'1000) == 0b1111'0000 && // NOLINT start + 3 < input.size()) { - uint8_t C1 = input[start + 1]; - uint8_t C2 = input[start + 2]; - uint8_t C3 = input[start + 3]; + const uint8_t C1 = input[start + 1]; + const uint8_t C2 = input[start + 2]; + const uint8_t C3 = input[start + 3]; *ucs = 0; *ucs += C0 & 0b0000'0111; // NOLINT *ucs <<= 6; // NOLINT @@ -1645,10 +1648,9 @@ bool EatCodePoint(const std::wstring& input, return false; } - // On linux wstring uses the UTF32 encoding: if constexpr (sizeof(wchar_t) == 4) { - *ucs = input[start]; // NOLINT + *ucs = input[start]; // NOLINT *end = start + 1; return true; } @@ -1686,7 +1688,7 @@ int wstring_width(const std::wstring& text) { int width = 0; for (const wchar_t& it : text) { - int w = wchar_width(it); + const int w = wchar_width(it); if (w < 0) { return -1; } @@ -1724,7 +1726,7 @@ int string_width(const std::string& input) { std::vector Utf8ToGlyphs(const std::string& input) { std::vector out; - std::string current; + const std::string current; out.reserve(input.size()); size_t start = 0; size_t end = 0; @@ -1735,7 +1737,7 @@ std::vector Utf8ToGlyphs(const std::string& input) { continue; } - std::string append = input.substr(start, end - start); + const std::string append = input.substr(start, end - start); start = end; // Ignore control characters. @@ -1772,7 +1774,7 @@ int GlyphPosition(const std::string& input, size_t glyph_index, size_t start) { size_t end = 0; while (start < input.size()) { uint32_t codepoint = 0; - bool eaten = EatCodePoint(input, start, &end, &codepoint); + const bool eaten = EatCodePoint(input, start, &end, &codepoint); // Ignore invalid, control characters and combining characters. if (!eaten || IsControl(codepoint) || IsCombining(codepoint)) { @@ -1801,7 +1803,7 @@ std::vector CellToGlyphIndex(const std::string& input) { size_t end = 0; while (start < input.size()) { uint32_t codepoint = 0; - bool eaten = EatCodePoint(input, start, &end, &codepoint); + const bool eaten = EatCodePoint(input, start, &end, &codepoint); start = end; // Ignore invalid / control characters. @@ -1840,7 +1842,7 @@ int GlyphCount(const std::string& input) { size_t end = 0; while (start < input.size()) { uint32_t codepoint = 0; - bool eaten = EatCodePoint(input, start, &end, &codepoint); + const bool eaten = EatCodePoint(input, start, &end, &codepoint); start = end; // Ignore invalid characters: @@ -1916,7 +1918,7 @@ std::string to_string(const std::wstring& s) { // 1 byte UTF8 if (codepoint <= 0b000'0000'0111'1111) { // NOLINT - uint8_t p1 = codepoint; + const uint8_t p1 = codepoint; out.push_back(p1); // NOLINT continue; } diff --git a/src/ftxui/screen/string_test.cpp b/src/ftxui/screen/string_test.cpp index d75af1d..57a220d 100644 --- a/src/ftxui/screen/string_test.cpp +++ b/src/ftxui/screen/string_test.cpp @@ -134,8 +134,8 @@ TEST(StringTest, Utf8ToWordBreakProperty) { EXPECT_EQ(Utf8ToWordBreakProperty("'"), T({P::Single_Quote})); EXPECT_EQ(Utf8ToWordBreakProperty(":"), T({P::MidLetter})); EXPECT_EQ(Utf8ToWordBreakProperty("."), T({P::MidNumLet})); - EXPECT_EQ(Utf8ToWordBreakProperty("\r"), T({})); // FIXME - EXPECT_EQ(Utf8ToWordBreakProperty("\n"), T({})); // FIXME + EXPECT_EQ(Utf8ToWordBreakProperty("\r"), T({})); // FIXME + EXPECT_EQ(Utf8ToWordBreakProperty("\n"), T({})); // FIXME } TEST(StringTest, to_string) { diff --git a/tools/iwyu.sh b/tools/iwyu.sh index 88da55e..50011e2 100755 --- a/tools/iwyu.sh +++ b/tools/iwyu.sh @@ -8,6 +8,6 @@ rm * -rf echo $CMAKE_CXX_INCLUDE_WHAT_YOU_USE cmake .. -DFTXUI_BUILD_TESTS=ON -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-Xiwyu;--cxx17ns;-Xiwyu;--mapping_file=${mapping_dir}/iwyu.imp;-Xiwyu;--verbose=3" make -j 2>out -fix_includes.py --comments < out +fix_include --comments < out ../tools/format.sh