From eed7e2ea7046fcef2de15e18a24735d8adc46c4a Mon Sep 17 00:00:00 2001 From: Marc <12819635+LostInCompilation@users.noreply.github.com> Date: Sun, 26 Mar 2023 20:20:02 +0200 Subject: [PATCH] Multiple fixes: signed/unsigned, etc... (#600) Co-authored-by: ArthurSonzogni --- .clang-tidy | 13 ++- include/ftxui/component/event.hpp | 17 ++-- include/ftxui/component/mouse.hpp | 14 +-- include/ftxui/util/ref.hpp | 2 +- src/ftxui/component/animation.cpp | 91 +++++++++---------- src/ftxui/component/animation_test.cpp | 4 +- src/ftxui/component/button.cpp | 2 +- src/ftxui/component/button_test.cpp | 2 + src/ftxui/component/collapsible_test.cpp | 2 + src/ftxui/component/container.cpp | 10 +- src/ftxui/component/dropdown.cpp | 9 +- src/ftxui/component/event.cpp | 5 +- src/ftxui/component/hoverable_test.cpp | 2 + src/ftxui/component/input_test.cpp | 2 + src/ftxui/component/menu_test.cpp | 2 + src/ftxui/component/modal_test.cpp | 2 + src/ftxui/component/radiobox_test.cpp | 2 + src/ftxui/component/receiver_test.cpp | 2 + src/ftxui/component/resizable_split.cpp | 2 +- src/ftxui/component/resizable_split_test.cpp | 2 + .../component/screen_interactive_test.cpp | 5 +- src/ftxui/component/slider_test.cpp | 4 +- .../component/terminal_input_parser_test.cpp | 2 + src/ftxui/component/toggle_test.cpp | 21 +++-- src/ftxui/dom/benchmark_test.cpp | 8 +- src/ftxui/dom/blink_test.cpp | 2 + src/ftxui/dom/bold_test.cpp | 2 + src/ftxui/dom/border_test.cpp | 2 + src/ftxui/dom/canvas_test.cpp | 6 +- src/ftxui/dom/color_test.cpp | 2 + src/ftxui/dom/dbox_test.cpp | 2 + src/ftxui/dom/dim_test.cpp | 2 + src/ftxui/dom/flexbox_helper_test.cpp | 2 + src/ftxui/dom/flexbox_test.cpp | 2 + src/ftxui/dom/gauge_test.cpp | 2 + src/ftxui/dom/gridbox_test.cpp | 4 +- src/ftxui/dom/hbox_test.cpp | 18 ++-- src/ftxui/dom/linear_gradient.cpp | 39 ++++---- src/ftxui/dom/linear_gradient_test.cpp | 6 +- src/ftxui/dom/scroll_indicator_test.cpp | 2 + src/ftxui/dom/separator_test.cpp | 2 + src/ftxui/dom/spinner.cpp | 2 +- src/ftxui/dom/spinner_test.cpp | 2 + src/ftxui/dom/table_test.cpp | 2 + src/ftxui/dom/text_test.cpp | 2 + src/ftxui/dom/underlined_test.cpp | 2 + src/ftxui/dom/vbox_test.cpp | 4 +- src/ftxui/screen/color.cpp | 23 ++--- 48 files changed, 215 insertions(+), 144 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 494b17a..13847e6 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -3,21 +3,24 @@ Checks: "*, -abseil-*, -altera-*, -android-*, - -fuchsia-*, - -google-*, - -llvm*, - -modernize-use-trailing-return-type, - -zircon-*, -bugprone-easily-swappable-parameters, -cppcoreguidelines-non-private-member-variables-in-classes, + -fuchsia-*, + -google-*, + -hicpp-uppercase-literal-suffix, + -llvm*, -misc-no-recursion, -misc-non-private-member-variables-in-classes, -modernize-use-nodiscard, + -modernize-use-trailing-return-type, -readability-avoid-const-params-in-decls, -readability-else-after-return, -readability-identifier-length, -readability-implicit-bool-conversion, + -readability-non-const-parameter, -readability-static-accessed-through-instance, + -readability-uppercase-literal-suffix, + -zircon-*, " WarningsAsErrors: '' HeaderFilterRegex: '' diff --git a/include/ftxui/component/event.hpp b/include/ftxui/component/event.hpp index 44f7f0c..a10e256 100644 --- a/include/ftxui/component/event.hpp +++ b/include/ftxui/component/event.hpp @@ -66,11 +66,11 @@ 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 data_.mouse; } bool is_cursor_reporting() const { return type_ == Type::CursorReporting; } - int cursor_x() const { return cursor_.x; } - int cursor_y() const { return cursor_.y; } + int cursor_x() const { return data_.cursor.x; } + int cursor_y() const { return data_.cursor.y; } const std::string& input() const { return input_; } @@ -92,14 +92,15 @@ struct Event { Type type_ = Type::Unknown; struct Cursor { - int x; - int y; + int x = 0; + int y = 0; }; union { - struct Mouse mouse_; - struct Cursor cursor_; - }; + struct Mouse mouse; + struct Cursor cursor; + } data_ = {}; + std::string input_; }; diff --git a/include/ftxui/component/mouse.hpp b/include/ftxui/component/mouse.hpp index aeeb490..d1c4c9c 100644 --- a/include/ftxui/component/mouse.hpp +++ b/include/ftxui/component/mouse.hpp @@ -21,19 +21,19 @@ struct Mouse { }; // Button - Button button; + Button button = Button::None; // Motion - Motion motion; + Motion motion = Motion::Pressed; // Modifiers: - bool shift; - bool meta; - bool control; + bool shift = false; + bool meta = false; + bool control = false; // Coordinates: - int x; - int y; + int x = 0; + int y = 0; }; } // namespace ftxui diff --git a/include/ftxui/util/ref.hpp b/include/ftxui/util/ref.hpp index 4381065..ac20b4f 100644 --- a/include/ftxui/util/ref.hpp +++ b/include/ftxui/util/ref.hpp @@ -29,7 +29,7 @@ class Ref { Ref() {} Ref(const T& t) : owned_(t) {} Ref(T&& t) : owned_(std::forward(t)) {} - Ref(T* t) : address_(t) {} + Ref(T* t) : owned_(), address_(t) {} T& operator*() { return address_ ? *address_ : owned_; } T& operator()() { return address_ ? *address_ : owned_; } T* operator->() { return address_ ? address_ : &owned_; } diff --git a/src/ftxui/component/animation.cpp b/src/ftxui/component/animation.cpp index 18c502a..a07c372 100644 --- a/src/ftxui/component/animation.cpp +++ b/src/ftxui/component/animation.cpp @@ -4,6 +4,7 @@ #include "ftxui/component/animation.hpp" +// NOLINTBEGIN(*-magic-numbers) namespace ftxui::animation { namespace easing { @@ -44,9 +45,7 @@ float QuadraticOut(float p) { // y = (1/2)((2x)^2) ; [0, 0.5) // y = -(1/2)((2x-1)*(2x-3) - 1) ; [0.5, 1] float QuadraticInOut(float p) { - return p < 0.5f // NOLINT - ? 2.f * p * p // NOLINT - : (-2.f * p * p) + (4.f * p) - 1.f; // NOLINT + return p < 0.5f ? 2.f * p * p : (-2.f * p * p) + (4.f * p) - 1.f; } // Modeled after the cubic y = x^3 @@ -64,11 +63,11 @@ float CubicOut(float p) { // y = (1/2)((2x)^3) ; [0, 0.5) // y = (1/2)((2x-2)^3 + 2) ; [0.5, 1] float CubicInOut(float p) { - if (p < 0.5f) { // NOLINT + if (p < 0.5f) { return 4.f * p * p * p; } const float f = ((2.f * p) - 2.f); - return 0.5f * f * f * f + 1.f; // NOLINT + return 0.5f * f * f * f + 1.f; } // Modeled after the quartic x^4 @@ -86,11 +85,11 @@ float QuarticOut(float p) { // y = (1/2)((2x)^4) ; [0, 0.5) // y = -(1/2)((2x-2)^4 - 2) ; [0.5, 1] float QuarticInOut(float p) { - if (p < 0.5f) { // NOLINT - return 8.f * p * p * p * p; // NOLINT + if (p < 0.5f) { + return 8.f * p * p * p * p; } const float f = (p - 1.f); - return -8.f * f * f * f * f + 1.f; // NOLINT + return -8.f * f * f * f * f + 1.f; } // Modeled after the quintic y = x^5 @@ -108,11 +107,11 @@ float QuinticOut(float p) { // y = (1/2)((2x)^5) ; [0, 0.5) // y = (1/2)((2x-2)^5 + 2) ; [0.5, 1] float QuinticInOut(float p) { - if (p < 0.5f) { // NOLINT - return 16.f * p * p * p * p * p; // NOLINT + if (p < 0.5f) { + return 16.f * p * p * p * p * p; } - float f = ((2.f * p) - 2.f); // NOLINT - return 0.5f * f * f * f * f * f + 1.f; // NOLINT + const float f = ((2.f * p) - 2.f); + return 0.5f * f * f * f * f * f + 1.f; } // Modeled after quarter-cycle of sine wave @@ -127,7 +126,7 @@ float SineOut(float p) { // Modeled after half sine wave float SineInOut(float p) { - return 0.5f * (1.f - std::cos(p * kPi)); // NOLINT + return 0.5f * (1.f - std::cos(p * kPi)); } // Modeled after shifted quadrant IV of unit circle @@ -144,21 +143,20 @@ float CircularOut(float p) { // y = (1/2)(1 - sqrt(1 - 4x^2)) ; [0, 0.5) // y = (1/2)(sqrt(-(2x - 3)*(2x - 1)) + 1) ; [0.5, 1] float CircularInOut(float p) { - if (p < 0.5f) { // NOLINT - return 0.5f * (1.f - std::sqrt(1.f - 4.f * (p * p))); // NOLINT + if (p < 0.5f) { + return 0.5f * (1.f - std::sqrt(1.f - 4.f * (p * p))); } - // NOLINTNEXTLINE return 0.5f * (std::sqrt(-((2.f * p) - 3.f) * ((2.f * p) - 1.f)) + 1.f); } // Modeled after the exponential function y = 2^(10(x - 1)) float ExponentialIn(float p) { - return (p == 0.f) ? p : std::pow(2.f, 10.f * (p - 1.f)); // NOLINT + return (p == 0.f) ? p : std::pow(2.f, 10.f * (p - 1.f)); } // Modeled after the exponential function y = -2^(-10x) + 1 float ExponentialOut(float p) { - return (p == 1.f) ? p : 1.f - std::pow(2.f, -10.f * p); // NOLINT + return (p == 1.f) ? p : 1.f - std::pow(2.f, -10.f * p); } // Modeled after the piecewise exponential @@ -169,21 +167,20 @@ float ExponentialInOut(float p) { return p; } - if (p < 0.5f) { // NOLINT - return 0.5f * std::pow(2.f, (20.f * p) - 10.f); // NOLINT + if (p < 0.5f) { + return 0.5f * std::pow(2.f, (20.f * p) - 10.f); } - return -0.5f * std::pow(2.f, (-20.f * p) + 10.f) + 1.f; // NOLINT + return -0.5f * std::pow(2.f, (-20.f * p) + 10.f) + 1.f; } // Modeled after the damped sine wave y = sin(13pi/2*x)*pow(2, 10 * (x - 1)) float ElasticIn(float p) { - return std::sin(13.f * kPi2 * p) * std::pow(2.f, 10.f * (p - 1.f)); // NOLINT + return std::sin(13.f * kPi2 * p) * std::pow(2.f, 10.f * (p - 1.f)); } // Modeled after the damped sine wave y = sin(-13pi/2*(x + 1))*pow(2, -10x) + // 1 float ElasticOut(float p) { - // NOLINTNEXTLINE return std::sin(-13.f * kPi2 * (p + 1.f)) * std::pow(2.f, -10.f * p) + 1.f; } @@ -191,13 +188,13 @@ float ElasticOut(float p) { // y = (1/2)*sin(13pi/2*(2*x))*pow(2, 10 * ((2*x) - 1)) ; [0,0.5) // y = (1/2)*(sin(-13pi/2*((2x-1)+1))*pow(2,-10(2*x-1)) + 2) ; [0.5, 1] float ElasticInOut(float p) { - if (p < 0.5f) { // NOLINT - return 0.5f * std::sin(13.f * kPi2 * (2.f * p)) * // NOLINT - std::pow(2.f, 10.f * ((2.f * p) - 1.f)); // NOLINT + if (p < 0.5f) { + return 0.5f * std::sin(13.f * kPi2 * (2.f * p)) * + std::pow(2.f, 10.f * ((2.f * p) - 1.f)); } - return 0.5f * (std::sin(-13.f * kPi2 * ((2.f * p - 1.f) + 1.f)) * // NOLINT - std::pow(2.f, -10.f * (2.f * p - 1.f)) + // NOLINT - 2.f); // NOLINT + return 0.5f * (std::sin(-13.f * kPi2 * ((2.f * p - 1.f) + 1.f)) * + std::pow(2.f, -10.f * (2.f * p - 1.f)) + + 2.f); } // Modeled after the overshooting cubic y = x^3-x*sin(x*pi) @@ -215,12 +212,12 @@ float BackOut(float p) { // y = (1/2)*((2x)^3-(2x)*sin(2*x*pi)) ; [0, 0.5) // 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 + if (p < 0.5f) { const float f = 2.f * p; - return 0.5f * (f * f * f - f * std::sin(f * kPi)); // NOLINT + return 0.5f * (f * f * f - f * std::sin(f * kPi)); } - const float f = (1.f - (2.f * p - 1.f)); // NOLINT - return 0.5f * (1.f - (f * f * f - f * std::sin(f * kPi))) + 0.5f; // NOLINT + const float f = (1.f - (2.f * p - 1.f)); + return 0.5f * (1.f - (f * f * f - f * std::sin(f * kPi))) + 0.5f; } float BounceIn(float p) { @@ -228,27 +225,26 @@ float BounceIn(float p) { } float BounceOut(float p) { - if (p < 4.f / 11.f) { // NOLINT - return (121.f * p * p) / 16.f; // NOLINT + if (p < 4.f / 11.f) { + return (121.f * p * p) / 16.f; } - if (p < 8.f / 11.f) { // NOLINT - return (363.f / 40.f * p * p) - (99.f / 10.f * p) + 17.f / 5.f; // NOLINT + if (p < 8.f / 11.f) { + return (363.f / 40.f * p * p) - (99.f / 10.f * p) + 17.f / 5.f; } - if (p < 9.f / 10.f) { // NOLINT - return (4356.f / 361.f * p * p) - (35442.f / 1805.f * p) + // NOLINT - 16061.f / 1805.f; // NOLINT + if (p < 9.f / 10.f) { + return (4356.f / 361.f * p * p) - (35442.f / 1805.f * p) + 16061.f / 1805.f; } - return (54.f / 5.f * p * p) - (513 / 25.f * p) + 268 / 25.f; // NOLINT + return (54.f / 5.f * p * p) - (513 / 25.f * p) + 268 / 25.f; } -float BounceInOut(float p) { // NOLINT - if (p < 0.5f) { // NOLINT - return 0.5f * BounceIn(p * 2.f); // NOLINT +float BounceInOut(float p) { + if (p < 0.5f) { + return 0.5f * BounceIn(p * 2.f); } - return 0.5f * BounceOut(p * 2.f - 1.f) + 0.5f; // NOLINT + return 0.5f * BounceOut(p * 2.f - 1.f) + 0.5f; } } // namespace easing @@ -278,11 +274,12 @@ void Animator::OnAnimation(Params& params) { if (current_ <= Duration()) { *value_ = from_; } else { - *value_ = from_ + - (to_ - from_) * easing_function_(current_ / duration_); // NOLINT + *value_ = from_ + (to_ - from_) * easing_function_(current_ / duration_); } RequestAnimationFrame(); } } // namespace ftxui::animation + +// NOLINTEND(*-magic-numbers) diff --git a/src/ftxui/component/animation_test.cpp b/src/ftxui/component/animation_test.cpp index 0f9c83a..152bfc0 100644 --- a/src/ftxui/component/animation_test.cpp +++ b/src/ftxui/component/animation_test.cpp @@ -7,7 +7,7 @@ namespace ftxui { TEST(AnimationTest, StartAndEnd) { - std::vector functions = { + const std::vector functions = { animation::easing::Linear, animation::easing::QuadraticIn, animation::easing::QuadraticOut, animation::easing::QuadraticInOut, animation::easing::CubicIn, animation::easing::CubicOut, @@ -25,7 +25,7 @@ TEST(AnimationTest, StartAndEnd) { animation::easing::BounceIn, animation::easing::BounceOut, animation::easing::BounceInOut, }; - for (auto& it : functions) { + for (const auto& it : functions) { EXPECT_NEAR(0.F, it(0.F), 1.0e-4); EXPECT_NEAR(1.F, it(1.F), 1.0e-4); } diff --git a/src/ftxui/component/button.cpp b/src/ftxui/component/button.cpp index 085272a..1c05d83 100644 --- a/src/ftxui/component/button.cpp +++ b/src/ftxui/component/button.cpp @@ -74,7 +74,7 @@ Component Button(ConstStringRef label, const bool focused = Focused(); const bool focused_or_hover = focused || mouse_hover_; - float target = focused_or_hover ? 1.F : 0.F; // NOLINT + float target = focused_or_hover ? 1.f : 0.f; // NOLINT if (target != animator_background_.to()) { SetAnimationTarget(target); } diff --git a/src/ftxui/component/button_test.cpp b/src/ftxui/component/button_test.cpp index 44c44aa..4099b96 100644 --- a/src/ftxui/component/button_test.cpp +++ b/src/ftxui/component/button_test.cpp @@ -13,6 +13,7 @@ #include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/terminal.hpp" // for SetColorSupport, Color, TrueColor +// NOLINTBEGIN namespace ftxui { namespace { @@ -189,6 +190,7 @@ TEST(ButtonTest, Animation) { } } // namespace ftxui +// NOLINTEND // Copyright 2022 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/component/collapsible_test.cpp b/src/ftxui/component/collapsible_test.cpp index bd1a970..4492fe6 100644 --- a/src/ftxui/component/collapsible_test.cpp +++ b/src/ftxui/component/collapsible_test.cpp @@ -8,6 +8,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen +// NOLINTBEGIN namespace ftxui { TEST(CollapsibleTest, Basic) { @@ -47,6 +48,7 @@ TEST(CollapsibleTest, Basic) { } } // namespace ftxui +// NOLINTEND // Copyright 2022 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/component/container.cpp b/src/ftxui/component/container.cpp index 0c9135e..3bd72c8 100644 --- a/src/ftxui/component/container.cpp +++ b/src/ftxui/component/container.cpp @@ -44,13 +44,13 @@ class ContainerBase : public ComponentBase { return nullptr; } - return children_[*selector_ % children_.size()]; + return children_[static_cast(*selector_) % children_.size()]; } void SetActiveChild(ComponentBase* child) override { for (size_t i = 0; i < children_.size(); ++i) { if (children_[i].get() == child) { - *selector_ = (int)i; + *selector_ = static_cast(i); return; } } @@ -68,7 +68,7 @@ class ContainerBase : public ComponentBase { int* selector_ = nullptr; void MoveSelector(int dir) { - for (int i = *selector_ + dir; i >= 0 && i < (int)children_.size(); + for (int i = *selector_ + dir; i >= 0 && i < int(children_.size()); i += dir) { if (children_[i]->Focusable()) { *selector_ = i; @@ -85,7 +85,7 @@ class ContainerBase : public ComponentBase { const size_t i = ((size_t(*selector_ + offset * dir + children_.size())) % children_.size()); if (children_[i]->Focusable()) { - *selector_ = (int)i; + *selector_ = int(i); return; } } @@ -225,7 +225,7 @@ class TabContainer : public ContainerBase { if (children_.empty()) { return false; } - return children_[*selector_ % children_.size()]->Focusable(); + return children_[size_t(*selector_) % children_.size()]->Focusable(); } bool OnMouseEvent(Event event) override { diff --git a/src/ftxui/component/dropdown.cpp b/src/ftxui/component/dropdown.cpp index 96e94f5..7f830d3 100644 --- a/src/ftxui/component/dropdown.cpp +++ b/src/ftxui/component/dropdown.cpp @@ -1,12 +1,13 @@ -#include // for max, min +#include // for size_t #include // for function -#include // for __shared_ptr_access, shared_ptr, allocator +#include // for __shared_ptr_access, allocator, shared_ptr #include // for string #include "ftxui/component/component.hpp" // for Maybe, Checkbox, Make, Radiobox, Vertical, Dropdown #include "ftxui/component/component_base.hpp" // for Component, ComponentBase #include "ftxui/component/component_options.hpp" // for CheckboxOption, EntryState #include "ftxui/dom/elements.hpp" // for operator|, Element, border, filler, operator|=, separator, size, text, vbox, frame, vscroll_indicator, hbox, HEIGHT, LESS_THAN, bold, inverted +#include "ftxui/screen/util.hpp" // for clamp #include "ftxui/util/ref.hpp" // for ConstStringListRef namespace ftxui { @@ -38,8 +39,8 @@ Component Dropdown(ConstStringListRef entries, int* selected) { } Element Render() override { - *selected_ = std::min((int)entries_.size() - 1, std::max(0, *selected_)); - title_ = entries_[*selected_]; + *selected_ = util::clamp(*selected_, 0, (int)entries_.size() - 1); + title_ = entries_[static_cast(*selected_)]; if (show_) { const int max_height = 12; return vbox({ diff --git a/src/ftxui/component/event.cpp b/src/ftxui/component/event.cpp index 1cd95ed..64a18b7 100644 --- a/src/ftxui/component/event.cpp +++ b/src/ftxui/component/event.cpp @@ -29,7 +29,7 @@ Event Event::Mouse(std::string input, struct Mouse mouse) { Event event; event.input_ = std::move(input); event.type_ = Type::Mouse; - event.mouse_ = mouse; // NOLINT + event.data_.mouse = mouse; // NOLINT return event; } @@ -45,8 +45,7 @@ Event Event::CursorReporting(std::string input, int x, int y) { Event event; event.input_ = std::move(input); event.type_ = Type::CursorReporting; - event.cursor_.x = x; // NOLINT - event.cursor_.y = y; // NOLINT + event.data_.cursor = {x, y}; // NOLINT return event; } diff --git a/src/ftxui/component/hoverable_test.cpp b/src/ftxui/component/hoverable_test.cpp index 4e657cc..039d563 100644 --- a/src/ftxui/component/hoverable_test.cpp +++ b/src/ftxui/component/hoverable_test.cpp @@ -9,6 +9,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen +// NOLINTBEGIN namespace ftxui { namespace { @@ -186,6 +187,7 @@ TEST(HoverableTest, Coverage) { } // namespace } // namespace ftxui +// NOLINTEND // Copyright 2021 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/component/input_test.cpp b/src/ftxui/component/input_test.cpp index 1ccc3d5..f187e82 100644 --- a/src/ftxui/component/input_test.cpp +++ b/src/ftxui/component/input_test.cpp @@ -12,6 +12,7 @@ #include "ftxui/screen/screen.hpp" // for Fixed, Screen, Pixel #include "ftxui/util/ref.hpp" // for Ref +// NOLINTBEGIN namespace ftxui { TEST(InputTest, Init) { @@ -488,6 +489,7 @@ TEST(InputTest, CtrlArrowRight2) { } } // namespace ftxui +// NOLINTEND // Copyright 2021 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/component/menu_test.cpp b/src/ftxui/component/menu_test.cpp index c3689dd..4eda990 100644 --- a/src/ftxui/component/menu_test.cpp +++ b/src/ftxui/component/menu_test.cpp @@ -14,6 +14,7 @@ #include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/util/ref.hpp" // for Ref +// NOLINTBEGIN namespace ftxui { using namespace std::chrono_literals; @@ -233,6 +234,7 @@ TEST(MenuTest, AnimationsVertical) { } } // namespace ftxui +// NOLINTEND // Copyright 2022 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/component/modal_test.cpp b/src/ftxui/component/modal_test.cpp index 26b9a6c..74bb951 100644 --- a/src/ftxui/component/modal_test.cpp +++ b/src/ftxui/component/modal_test.cpp @@ -7,6 +7,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen +// NOLINTBEGIN namespace ftxui { TEST(ModalTest, Basic) { @@ -39,6 +40,7 @@ TEST(ModalTest, Basic) { } } // namespace ftxui +// NOLINTEND // Copyright 2022 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/component/radiobox_test.cpp b/src/ftxui/component/radiobox_test.cpp index df80eac..c743a22 100644 --- a/src/ftxui/component/radiobox_test.cpp +++ b/src/ftxui/component/radiobox_test.cpp @@ -12,6 +12,7 @@ #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 +// NOLINTBEGIN namespace ftxui { TEST(RadioboxTest, NavigationArrow) { @@ -303,6 +304,7 @@ TEST(RadioboxTest, RemoveEntries) { } } // namespace ftxui +// NOLINTEND // Copyright 2020 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/component/receiver_test.cpp b/src/ftxui/component/receiver_test.cpp index 50fb07d..a45e9f3 100644 --- a/src/ftxui/component/receiver_test.cpp +++ b/src/ftxui/component/receiver_test.cpp @@ -4,6 +4,7 @@ #include "ftxui/component/receiver.hpp" +// NOLINTBEGIN namespace ftxui { TEST(Receiver, Basic) { @@ -74,6 +75,7 @@ TEST(Receiver, BasicWithThread) { } } // namespace ftxui +// NOLINTEND // Copyright 2020 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/component/resizable_split.cpp b/src/ftxui/component/resizable_split.cpp index 1f75fd7..3630d7c 100644 --- a/src/ftxui/component/resizable_split.cpp +++ b/src/ftxui/component/resizable_split.cpp @@ -18,7 +18,7 @@ namespace { class ResizableSplitBase : public ComponentBase { public: - ResizableSplitBase(ResizableSplitOption options) + explicit ResizableSplitBase(ResizableSplitOption options) : options_(std::move(options)) { Add(Container::Horizontal({ options_->main, diff --git a/src/ftxui/component/resizable_split_test.cpp b/src/ftxui/component/resizable_split_test.cpp index 347310a..627d412 100644 --- a/src/ftxui/component/resizable_split_test.cpp +++ b/src/ftxui/component/resizable_split_test.cpp @@ -10,6 +10,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen +// NOLINTBEGIN namespace ftxui { namespace { @@ -203,6 +204,7 @@ TEST(ResizableSplit, BasicBottomWithCustomSeparator) { } } // namespace ftxui +// NOLINTEND // Copyright 2022 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/component/screen_interactive_test.cpp b/src/ftxui/component/screen_interactive_test.cpp index 4dd6577..c2b9dd4 100644 --- a/src/ftxui/component/screen_interactive_test.cpp +++ b/src/ftxui/component/screen_interactive_test.cpp @@ -1,6 +1,7 @@ -#include +#include // for Test, TestInfo (ptr only), TEST, EXPECT_EQ, Message, TestPartResult #include // for raise, SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM #include // for Event, Event::Custom +#include // for _Swallow_assign, ignore #include "ftxui/component/component.hpp" // for Renderer #include "ftxui/component/screen_interactive.hpp" @@ -14,7 +15,7 @@ bool TestSignal(int signal) { // The tree of components. This defines how to navigate using the keyboard. auto component = Renderer([&] { called++; - std::raise(signal); + std::ignore = std::raise(signal); called++; return text(""); }); diff --git a/src/ftxui/component/slider_test.cpp b/src/ftxui/component/slider_test.cpp index b982513..c6159db 100644 --- a/src/ftxui/component/slider_test.cpp +++ b/src/ftxui/component/slider_test.cpp @@ -1,6 +1,6 @@ #include // for AssertionResult, Message, TestPartResult, Test, EXPECT_EQ, EXPECT_TRUE, TestInfo (ptr only), EXPECT_FALSE, TEST -#include // for size_t #include // for array +#include // for size_t #include // for Mouse, Mouse::Left, Mouse::Pressed, Mouse::Released #include // for Direction, Direction::Down, Direction::Left, Direction::Right, Direction::Up #include // for frame @@ -13,6 +13,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen +// NOLINTBEGIN namespace ftxui { namespace { @@ -187,6 +188,7 @@ TEST(SliderTest, Focus) { } } // namespace ftxui +// NOLINTEND // Copyright 2022 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/component/terminal_input_parser_test.cpp b/src/ftxui/component/terminal_input_parser_test.cpp index f0f8163..4acf84d 100644 --- a/src/ftxui/component/terminal_input_parser_test.cpp +++ b/src/ftxui/component/terminal_input_parser_test.cpp @@ -9,6 +9,7 @@ #include "ftxui/component/receiver.hpp" // for MakeReceiver, ReceiverImpl #include "ftxui/component/terminal_input_parser.hpp" +// NOLINTBEGIN namespace ftxui { // Test char |c| to are trivially converted into |Event::Character(c)|. @@ -384,6 +385,7 @@ TEST(Event, Special) { } } // namespace ftxui +// NOLINTEND // Copyright 2020 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/component/toggle_test.cpp b/src/ftxui/component/toggle_test.cpp index 5152189..7e61fd1 100644 --- a/src/ftxui/component/toggle_test.cpp +++ b/src/ftxui/component/toggle_test.cpp @@ -1,17 +1,17 @@ -#include -#include // for function -#include // for __shared_ptr_access, shared_ptr, allocator -#include // for string, basic_string -#include // for vector +#include // for AssertionResult, Message, TestPartResult, EXPECT_EQ, Test, EXPECT_TRUE, TestInfo (ptr only), EXPECT_FALSE, TEST +#include // for function +#include // for __shared_ptr_access, shared_ptr, allocator +#include // for string, basic_string +#include // for vector -#include "ftxui/component/captured_mouse.hpp" // for ftxui -#include "ftxui/component/component.hpp" // for Toggle +#include "ftxui/component/component.hpp" // for Menu, Toggle #include "ftxui/component/component_base.hpp" // for ComponentBase -#include "ftxui/component/component_options.hpp" // for ToggleOption +#include "ftxui/component/component_options.hpp" // for MenuOption #include "ftxui/component/event.hpp" // for Event, Event::ArrowLeft, Event::ArrowRight, Event::Return, Event::Tab, Event::TabReverse #include "ftxui/util/ref.hpp" // for Ref -using namespace ftxui; +// NOLINTBEGIN +namespace ftxui { TEST(ToggleTest, leftRightArrow) { std::vector entries = {"On", "Off"}; @@ -177,6 +177,9 @@ TEST(ToggleTest, RemoveEntries) { EXPECT_EQ(focused_entry, 1); } +} // namespace ftxui +// NOLINTEND + // Copyright 2020 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in // the LICENSE file. diff --git a/src/ftxui/dom/benchmark_test.cpp b/src/ftxui/dom/benchmark_test.cpp index 740e8f5..76d20c1 100644 --- a/src/ftxui/dom/benchmark_test.cpp +++ b/src/ftxui/dom/benchmark_test.cpp @@ -4,6 +4,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen +// NOLINTBEGIN namespace ftxui { static void BencharkBasic(benchmark::State& state) { @@ -12,11 +13,11 @@ static void BencharkBasic(benchmark::State& state) { text("Test"), separator(), hbox({ - gauge(0.9), + gauge(0.9f), separator() | blink, - gauge(0.5), + gauge(0.5f), separator() | inverted, - gauge(0.1), + gauge(0.1f), separator(), }), text("Test"), @@ -30,6 +31,7 @@ static void BencharkBasic(benchmark::State& state) { BENCHMARK(BencharkBasic)->DenseRange(0, 256, 16); } // namespace ftxui +// NOLINTEND // Copyright 2021 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/blink_test.cpp b/src/ftxui/dom/blink_test.cpp index 7b7207f..c0713c1 100644 --- a/src/ftxui/dom/blink_test.cpp +++ b/src/ftxui/dom/blink_test.cpp @@ -5,6 +5,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen, Pixel +// NOLINTBEGIN namespace ftxui { TEST(BlinkTest, Basic) { @@ -15,6 +16,7 @@ TEST(BlinkTest, Basic) { } } // namespace ftxui +// NOLINTEND // Copyright 2022 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/bold_test.cpp b/src/ftxui/dom/bold_test.cpp index 340ba49..c5ae167 100644 --- a/src/ftxui/dom/bold_test.cpp +++ b/src/ftxui/dom/bold_test.cpp @@ -5,6 +5,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen, Pixel +// NOLINTBEGIN namespace ftxui { TEST(BoldTest, Basic) { @@ -15,6 +16,7 @@ TEST(BoldTest, Basic) { } } // namespace ftxui +// NOLINTEND // Copyright 2022 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/border_test.cpp b/src/ftxui/dom/border_test.cpp index 0743572..fc2249d 100644 --- a/src/ftxui/dom/border_test.cpp +++ b/src/ftxui/dom/border_test.cpp @@ -5,6 +5,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen, Pixel +// NOLINTBEGIN namespace ftxui { TEST(BorderTest, Default) { @@ -100,6 +101,7 @@ TEST(BorderTest, Window) { } } // namespace ftxui +// NOLINTEND // Copyright 2022 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/canvas_test.cpp b/src/ftxui/dom/canvas_test.cpp index 1f8180c..194dd69 100644 --- a/src/ftxui/dom/canvas_test.cpp +++ b/src/ftxui/dom/canvas_test.cpp @@ -1,6 +1,6 @@ #include -#include // for uint32_t -#include // for allocator, string +#include // for uint32_t +#include // for allocator, string #include "ftxui/dom/canvas.hpp" // for Canvas #include "ftxui/dom/elements.hpp" // for canvas @@ -9,6 +9,7 @@ #include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/terminal.hpp" // for SetColorSupport, Color, TrueColor +// NOLINTBEGIN namespace ftxui { namespace { @@ -101,6 +102,7 @@ TEST(CanvasTest, GoldText) { } } // namespace ftxui +// NOLINTEND // Copyright 2022 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/color_test.cpp b/src/ftxui/dom/color_test.cpp index 3ff2d18..087327e 100644 --- a/src/ftxui/dom/color_test.cpp +++ b/src/ftxui/dom/color_test.cpp @@ -6,6 +6,7 @@ #include "ftxui/screen/color.hpp" // for Color, Color::Red, Color::RedLight #include "ftxui/screen/screen.hpp" // for Screen, Pixel +// NOLINTBEGIN namespace ftxui { TEST(ColorTest, Foreground) { @@ -25,6 +26,7 @@ TEST(ColorTest, Background) { } } // namespace ftxui +// NOLINTEND // Copyright 2022 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/dbox_test.cpp b/src/ftxui/dom/dbox_test.cpp index a12a625..9a420a9 100644 --- a/src/ftxui/dom/dbox_test.cpp +++ b/src/ftxui/dom/dbox_test.cpp @@ -5,6 +5,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen +// NOLINTBEGIN namespace ftxui { TEST(DBoxTest, Basic) { @@ -29,6 +30,7 @@ TEST(DBoxTest, Basic) { } } // namespace ftxui +// NOLINTEND // Copyright 2020 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/dim_test.cpp b/src/ftxui/dom/dim_test.cpp index 811fe3a..2073158 100644 --- a/src/ftxui/dom/dim_test.cpp +++ b/src/ftxui/dom/dim_test.cpp @@ -5,6 +5,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen, Pixel +// NOLINTBEGIN namespace ftxui { TEST(DimTest, Basic) { @@ -15,6 +16,7 @@ TEST(DimTest, Basic) { } } // namespace ftxui +// NOLINTEND // Copyright 2022 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/flexbox_helper_test.cpp b/src/ftxui/dom/flexbox_helper_test.cpp index ab3f550..0fbb5c0 100644 --- a/src/ftxui/dom/flexbox_helper_test.cpp +++ b/src/ftxui/dom/flexbox_helper_test.cpp @@ -4,6 +4,7 @@ #include "ftxui/dom/flexbox_helper.hpp" +// NOLINTBEGIN namespace ftxui { TEST(FlexboxHelperTest, BasicRow) { @@ -227,6 +228,7 @@ TEST(FlexboxHelperTest, BasicColumnInversed) { } } // namespace ftxui +// NOLINTEND // Copyright 2020 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/flexbox_test.cpp b/src/ftxui/dom/flexbox_test.cpp index 31535ac..cdfa15f 100644 --- a/src/ftxui/dom/flexbox_test.cpp +++ b/src/ftxui/dom/flexbox_test.cpp @@ -6,6 +6,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen +// NOLINTBEGIN namespace ftxui { TEST(FlexboxTest, BasicRow) { @@ -454,6 +455,7 @@ TEST(FlexboxTest, Focus) { } } // namespace ftxui +// NOLINTEND // Copyright 2021 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/gauge_test.cpp b/src/ftxui/dom/gauge_test.cpp index b240ae0..3e5a065 100644 --- a/src/ftxui/dom/gauge_test.cpp +++ b/src/ftxui/dom/gauge_test.cpp @@ -5,6 +5,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen +// NOLINTBEGIN namespace ftxui { TEST(GaugeTest, ZeroHorizontal) { @@ -96,6 +97,7 @@ TEST(GaugeTest, OneVertical) { } } // namespace ftxui +// NOLINTEND // Copyright 2020 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/gridbox_test.cpp b/src/ftxui/dom/gridbox_test.cpp index 17aad9b..998fa7f 100644 --- a/src/ftxui/dom/gridbox_test.cpp +++ b/src/ftxui/dom/gridbox_test.cpp @@ -1,6 +1,6 @@ #include -#include // for size_t #include // for remove +#include // for size_t #include // for shared_ptr #include // for allocator, basic_string, string #include // for vector @@ -9,6 +9,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen +// NOLINTBEGIN namespace ftxui { namespace { @@ -615,6 +616,7 @@ TEST(GridboxTest, Focus) { } } // namespace ftxui +// NOLINTEND // Copyright 2020 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/hbox_test.cpp b/src/ftxui/dom/hbox_test.cpp index 17dfd2d..662558f 100644 --- a/src/ftxui/dom/hbox_test.cpp +++ b/src/ftxui/dom/hbox_test.cpp @@ -1,15 +1,14 @@ -#include -#include // for size_t -#include // for string, allocator -#include // for vector +#include // for Test, TestInfo (ptr only), EXPECT_EQ, Message, TEST, TestPartResult +#include // for size_t +#include // for allocator, basic_string, string +#include // for vector -#include "ftxui/dom/elements.hpp" // for text, operator|, hbox, Element, flex_grow, flex_shrink +#include "ftxui/dom/elements.hpp" // for text, operator|, Element, flex_grow, flex_shrink, hbox #include "ftxui/dom/node.hpp" // for Render -#include "ftxui/screen/color.hpp" // for ftxui #include "ftxui/screen/screen.hpp" // for Screen -using namespace ftxui; -using namespace ftxui; +// NOLINTBEGIN +namespace ftxui { TEST(HBoxTest, NoFlex_NoFlex_NoFlex) { auto root = hbox({ @@ -356,6 +355,9 @@ TEST(HBoxTest, FlexGrow_NoFlex_FlewShrink) { } } +} // namespace ftxui +// NOLINTEND + // Copyright 2020 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in // the LICENSE file. diff --git a/src/ftxui/dom/linear_gradient.cpp b/src/ftxui/dom/linear_gradient.cpp index 39046a3..3bf0e56 100644 --- a/src/ftxui/dom/linear_gradient.cpp +++ b/src/ftxui/dom/linear_gradient.cpp @@ -1,6 +1,6 @@ -#include // for size_t #include // for max, min, sort, copy #include // for fmod, cos, sin +#include // for size_t #include // for LinearGradient::Stop, LinearGradient #include // for allocator_traits<>::value_type, make_shared #include // for optional, operator!=, operator< @@ -25,7 +25,7 @@ struct LinearGradientNormalized { // Convert a LinearGradient to a normalized version. LinearGradientNormalized Normalize(LinearGradient gradient) { // Handle gradient of size 0. - if (gradient.stops.size() == 0) { + if (gradient.stops.empty()) { return LinearGradientNormalized{ 0.f, {Color::Default, Color::Default}, {0.f, 1.f}}; } @@ -46,11 +46,13 @@ LinearGradientNormalized Normalize(LinearGradient gradient) { } if (i - last_checkpoint >= 2) { - const float min = gradient.stops[i].position.value(); - const float max = gradient.stops[last_checkpoint].position.value(); + const float min = gradient.stops[i].position.value(); // NOLINT + const float max = + gradient.stops[last_checkpoint].position.value(); // NOLINT for (size_t j = last_checkpoint + 1; j < i; ++j) { - gradient.stops[j].position = - min + (max - min) * (j - last_checkpoint) / (i - last_checkpoint); + gradient.stops[j].position = min + (max - min) * + float(j - last_checkpoint) / + float(i - last_checkpoint); } } @@ -74,10 +76,11 @@ LinearGradientNormalized Normalize(LinearGradient gradient) { // Normalize the angle. LinearGradientNormalized normalized; + // NOLINTNEXTLINE normalized.angle = std::fmod(std::fmod(gradient.angle, 360.f) + 360.f, 360.f); for (auto& stop : gradient.stops) { normalized.colors.push_back(stop.color); - normalized.positions.push_back(stop.position.value()); + normalized.positions.push_back(stop.position.value()); // NOLINT } return normalized; } @@ -87,6 +90,7 @@ Color Interpolate(const LinearGradientNormalized& gradient, float t) { size_t i = 1; while (true) { if (i > gradient.positions.size()) { + // NOLINTNEXTLINE return Color::Interpolate(0.5f, gradient.colors.back(), gradient.colors.back()); } @@ -123,10 +127,10 @@ class LinearGradientColor : public NodeDecorator { const float dy = std::sin(gradient_.angle * degtorad); // Project every corner to get the extent of the gradient. - const float p1 = box_.x_min * dx + box_.y_min * dy; - const float p2 = box_.x_min * dx + box_.y_max * dy; - const float p3 = box_.x_max * dx + box_.y_min * dy; - const float p4 = box_.x_max * dx + box_.y_max * dy; + const float p1 = float(box_.x_min) * dx + float(box_.y_min) * dy; + const float p2 = float(box_.x_min) * dx + float(box_.y_max) * dy; + const float p3 = float(box_.x_max) * dx + float(box_.y_min) * dy; + const float p4 = float(box_.x_max) * dx + float(box_.y_max) * dy; const float min = std::min({p1, p2, p3, p4}); const float max = std::max({p1, p2, p3, p4}); @@ -140,14 +144,14 @@ class LinearGradientColor : public NodeDecorator { if (background_color_) { for (int y = box_.y_min; y <= box_.y_max; ++y) { for (int x = box_.x_min; x <= box_.x_max; ++x) { - const float t = x * dX + y * dY + dZ; + const float t = float(x) * dX + float(y) * dY + dZ; screen.PixelAt(x, y).background_color = Interpolate(gradient_, t); } } } else { for (int y = box_.y_min; y <= box_.y_max; ++y) { for (int x = box_.x_min; x <= box_.x_max; ++x) { - const float t = x * dX + y * dY + dZ; + const float t = float(x) * dX + float(y) * dY + dZ; screen.PixelAt(x, y).foreground_color = Interpolate(gradient_, t); } } @@ -180,18 +184,15 @@ LinearGradient::LinearGradient() = default; /// @param begin The color at the beginning of the gradient. /// @param end The color at the end of the gradient. /// @ingroup dom -LinearGradient::LinearGradient(Color begin, Color end) { - stops.push_back({begin, {}}); - stops.push_back({end, {}}); -} +LinearGradient::LinearGradient(Color begin, Color end) + : LinearGradient(0, begin, end) {} /// @brief Build a gradient with two colors and an angle. /// @param a The angle of the gradient. /// @param begin The color at the beginning of the gradient. /// @param end The color at the end of the gradient. /// @ingroup dom -LinearGradient::LinearGradient(float a, Color begin, Color end) { - angle = a; +LinearGradient::LinearGradient(float a, Color begin, Color end) : angle(a) { stops.push_back({begin, {}}); stops.push_back({end, {}}); } diff --git a/src/ftxui/dom/linear_gradient_test.cpp b/src/ftxui/dom/linear_gradient_test.cpp index 4f3d102..704a63a 100644 --- a/src/ftxui/dom/linear_gradient_test.cpp +++ b/src/ftxui/dom/linear_gradient_test.cpp @@ -1,12 +1,13 @@ #include // for Test, EXPECT_EQ, Message, TestPartResult, TestInfo (ptr only), TEST #include // for LinearGradient::Stop, LinearGradient -#include // for allocator +#include // for allocator_traits<>::value_type #include "ftxui/dom/elements.hpp" // for operator|, text, bgcolor, color, Element #include "ftxui/dom/node.hpp" // for Render -#include "ftxui/screen/color.hpp" // for Color, Color::Red, Color::RedLight +#include "ftxui/screen/color.hpp" // for Color, Color::RedLight, Color::Red #include "ftxui/screen/screen.hpp" // for Screen, Pixel +// NOLINTBEGIN namespace ftxui { TEST(ColorTest, API_default) { @@ -84,6 +85,7 @@ TEST(ColorTest, GradientBackground) { } } // namespace ftxui +// NOLINTEND // Copyright 2023 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/scroll_indicator_test.cpp b/src/ftxui/dom/scroll_indicator_test.cpp index 4713772..426500c 100644 --- a/src/ftxui/dom/scroll_indicator_test.cpp +++ b/src/ftxui/dom/scroll_indicator_test.cpp @@ -7,6 +7,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen +// NOLINTBEGIN namespace ftxui { namespace { @@ -197,6 +198,7 @@ TEST(ScrollIndicator, HorizontalFlexbox) { } // namespace } // namespace ftxui +// NOLINTEND // Copyright 2022 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/separator_test.cpp b/src/ftxui/dom/separator_test.cpp index 1dbef62..af85938 100644 --- a/src/ftxui/dom/separator_test.cpp +++ b/src/ftxui/dom/separator_test.cpp @@ -5,6 +5,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen, Pixel +// NOLINTBEGIN namespace ftxui { TEST(SeparatorTest, Default) { @@ -122,6 +123,7 @@ TEST(SeparatorTest, WithPixel) { } } // namespace ftxui +// NOLINTEND // Copyright 2022 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/spinner.cpp b/src/ftxui/dom/spinner.cpp index da7860c..387a2ac 100644 --- a/src/ftxui/dom/spinner.cpp +++ b/src/ftxui/dom/spinner.cpp @@ -278,7 +278,7 @@ const std::vector>> elements = { /// every "step". /// @ingroup dom Element spinner(int charset_index, size_t image_index) { - if (charset_index == 0) { + if (charset_index <= 0) { const int progress_size = 40; image_index %= progress_size; if (image_index > progress_size / 2) { diff --git a/src/ftxui/dom/spinner_test.cpp b/src/ftxui/dom/spinner_test.cpp index d65c066..d0d5813 100644 --- a/src/ftxui/dom/spinner_test.cpp +++ b/src/ftxui/dom/spinner_test.cpp @@ -5,6 +5,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen +// NOLINTBEGIN namespace ftxui { TEST(SpinnerTest, Spinner1) { @@ -36,6 +37,7 @@ TEST(SpinnerTest, Spinner4) { } } // namespace ftxui +// NOLINTEND // Copyright 2022 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/table_test.cpp b/src/ftxui/dom/table_test.cpp index e9f8260..b1175aa 100644 --- a/src/ftxui/dom/table_test.cpp +++ b/src/ftxui/dom/table_test.cpp @@ -6,6 +6,7 @@ #include "ftxui/dom/table.hpp" #include "ftxui/screen/screen.hpp" // for Screen +// NOLINTBEGIN namespace ftxui { TEST(TableTest, Empty) { @@ -731,6 +732,7 @@ TEST(TableTest, Merge) { } } // namespace ftxui +// NOLINTEND // Copyright 2021 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/text_test.cpp b/src/ftxui/dom/text_test.cpp index 5105efc..fa89aba 100644 --- a/src/ftxui/dom/text_test.cpp +++ b/src/ftxui/dom/text_test.cpp @@ -5,6 +5,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen +// NOLINTBEGIN namespace ftxui { TEST(TextTest, ScreenHeightSmaller) { @@ -118,6 +119,7 @@ TEST(TextTest, CombiningCharactersWithSpace) { } } // namespace ftxui +// NOLINTEND // Copyright 2020 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/underlined_test.cpp b/src/ftxui/dom/underlined_test.cpp index 50b9309..ba30d1a 100644 --- a/src/ftxui/dom/underlined_test.cpp +++ b/src/ftxui/dom/underlined_test.cpp @@ -5,6 +5,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen, Pixel +// NOLINTBEGIN namespace ftxui { TEST(UnderlinedTest, Basic) { @@ -15,6 +16,7 @@ TEST(UnderlinedTest, Basic) { } } // namespace ftxui +// NOLINTEND // Copyright 2022 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/dom/vbox_test.cpp b/src/ftxui/dom/vbox_test.cpp index 09780d0..cad86e0 100644 --- a/src/ftxui/dom/vbox_test.cpp +++ b/src/ftxui/dom/vbox_test.cpp @@ -1,6 +1,6 @@ #include -#include // for size_t #include // for remove +#include // for size_t #include // for string, allocator, basic_string #include // for vector @@ -8,6 +8,7 @@ #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen +// NOLINTBEGIN namespace ftxui { namespace { @@ -365,6 +366,7 @@ TEST(VBoxText, FlexGrow_NoFlex_FlewShrink) { } } // namespace ftxui +// NOLINTEND // Copyright 2020 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in diff --git a/src/ftxui/screen/color.cpp b/src/ftxui/screen/color.cpp index f52180d..d346d77 100644 --- a/src/ftxui/screen/color.cpp +++ b/src/ftxui/screen/color.cpp @@ -212,21 +212,22 @@ Color Color::Interpolate(float t, const Color& a, const Color& b) { } }; - uint8_t red_a = 0; - uint8_t green_a = 0; - uint8_t blue_a = 0; - uint8_t red_b = 0; - uint8_t green_b = 0; - uint8_t blue_b = 0; - get_color(a, &red_a, &green_a, &blue_a); - get_color(b, &red_b, &green_b, &blue_b); + uint8_t a_r = 0; + uint8_t a_g = 0; + uint8_t a_b = 0; + uint8_t b_r = 0; + uint8_t b_g = 0; + uint8_t b_b = 0; + get_color(a, &a_r, &a_g, &a_b); + get_color(b, &b_r, &b_g, &b_b); // Gamma correction: // https://en.wikipedia.org/wiki/Gamma_correction + constexpr float gamma = 2.2f; return Color::RGB( - pow(pow(red_a, 2.2f) * (1 - t) + pow(red_b, 2.2f) * t, 1 / 2.2f), - pow(pow(green_a, 2.2f) * (1 - t) + pow(green_b, 2.2f) * t, 1 / 2.2f), - pow(pow(blue_a, 2.2f) * (1 - t) + pow(blue_b, 2.2f) * t, 1 / 2.2f)); + uint8_t(pow(pow(a_r, gamma) * (1 - t) + pow(b_r, gamma) * t, 1 / gamma)), + uint8_t(pow(pow(a_g, gamma) * (1 - t) + pow(b_g, gamma) * t, 1 / gamma)), + uint8_t(pow(pow(a_b, gamma) * (1 - t) + pow(b_b, gamma) * t, 1 / gamma))); } inline namespace literals {