Multiple fixes: signed/unsigned, etc... (#600)

Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
Marc 2023-03-26 20:20:02 +02:00 committed by GitHub
parent e177409bd3
commit eed7e2ea70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 215 additions and 144 deletions

View File

@ -3,21 +3,24 @@ Checks: "*,
-abseil-*, -abseil-*,
-altera-*, -altera-*,
-android-*, -android-*,
-fuchsia-*,
-google-*,
-llvm*,
-modernize-use-trailing-return-type,
-zircon-*,
-bugprone-easily-swappable-parameters, -bugprone-easily-swappable-parameters,
-cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-non-private-member-variables-in-classes,
-fuchsia-*,
-google-*,
-hicpp-uppercase-literal-suffix,
-llvm*,
-misc-no-recursion, -misc-no-recursion,
-misc-non-private-member-variables-in-classes, -misc-non-private-member-variables-in-classes,
-modernize-use-nodiscard, -modernize-use-nodiscard,
-modernize-use-trailing-return-type,
-readability-avoid-const-params-in-decls, -readability-avoid-const-params-in-decls,
-readability-else-after-return, -readability-else-after-return,
-readability-identifier-length, -readability-identifier-length,
-readability-implicit-bool-conversion, -readability-implicit-bool-conversion,
-readability-non-const-parameter,
-readability-static-accessed-through-instance, -readability-static-accessed-through-instance,
-readability-uppercase-literal-suffix,
-zircon-*,
" "
WarningsAsErrors: '' WarningsAsErrors: ''
HeaderFilterRegex: '' HeaderFilterRegex: ''

View File

@ -66,11 +66,11 @@ struct Event {
std::string character() const { return input_; } std::string character() const { return input_; }
bool is_mouse() const { return type_ == Type::Mouse; } 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; } bool is_cursor_reporting() const { return type_ == Type::CursorReporting; }
int cursor_x() const { return cursor_.x; } int cursor_x() const { return data_.cursor.x; }
int cursor_y() const { return cursor_.y; } int cursor_y() const { return data_.cursor.y; }
const std::string& input() const { return input_; } const std::string& input() const { return input_; }
@ -92,14 +92,15 @@ struct Event {
Type type_ = Type::Unknown; Type type_ = Type::Unknown;
struct Cursor { struct Cursor {
int x; int x = 0;
int y; int y = 0;
}; };
union { union {
struct Mouse mouse_; struct Mouse mouse;
struct Cursor cursor_; struct Cursor cursor;
}; } data_ = {};
std::string input_; std::string input_;
}; };

View File

@ -21,19 +21,19 @@ struct Mouse {
}; };
// Button // Button
Button button; Button button = Button::None;
// Motion // Motion
Motion motion; Motion motion = Motion::Pressed;
// Modifiers: // Modifiers:
bool shift; bool shift = false;
bool meta; bool meta = false;
bool control; bool control = false;
// Coordinates: // Coordinates:
int x; int x = 0;
int y; int y = 0;
}; };
} // namespace ftxui } // namespace ftxui

View File

@ -29,7 +29,7 @@ class Ref {
Ref() {} Ref() {}
Ref(const T& t) : owned_(t) {} Ref(const T& t) : owned_(t) {}
Ref(T&& t) : owned_(std::forward<T>(t)) {} Ref(T&& t) : owned_(std::forward<T>(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_; } T& operator()() { return address_ ? *address_ : owned_; }
T* operator->() { return address_ ? address_ : &owned_; } T* operator->() { return address_ ? address_ : &owned_; }

View File

@ -4,6 +4,7 @@
#include "ftxui/component/animation.hpp" #include "ftxui/component/animation.hpp"
// NOLINTBEGIN(*-magic-numbers)
namespace ftxui::animation { namespace ftxui::animation {
namespace easing { namespace easing {
@ -44,9 +45,7 @@ float QuadraticOut(float p) {
// y = (1/2)((2x)^2) ; [0, 0.5) // y = (1/2)((2x)^2) ; [0, 0.5)
// y = -(1/2)((2x-1)*(2x-3) - 1) ; [0.5, 1] // y = -(1/2)((2x-1)*(2x-3) - 1) ; [0.5, 1]
float QuadraticInOut(float p) { float QuadraticInOut(float p) {
return p < 0.5f // NOLINT return p < 0.5f ? 2.f * p * p : (-2.f * p * p) + (4.f * p) - 1.f;
? 2.f * p * p // NOLINT
: (-2.f * p * p) + (4.f * p) - 1.f; // NOLINT
} }
// Modeled after the cubic y = x^3 // 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)^3) ; [0, 0.5)
// y = (1/2)((2x-2)^3 + 2) ; [0.5, 1] // y = (1/2)((2x-2)^3 + 2) ; [0.5, 1]
float CubicInOut(float p) { float CubicInOut(float p) {
if (p < 0.5f) { // NOLINT if (p < 0.5f) {
return 4.f * p * p * p; return 4.f * p * p * p;
} }
const float f = ((2.f * p) - 2.f); 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 // 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)^4) ; [0, 0.5)
// y = -(1/2)((2x-2)^4 - 2) ; [0.5, 1] // y = -(1/2)((2x-2)^4 - 2) ; [0.5, 1]
float QuarticInOut(float p) { float QuarticInOut(float p) {
if (p < 0.5f) { // NOLINT if (p < 0.5f) {
return 8.f * p * p * p * p; // NOLINT return 8.f * p * p * p * p;
} }
const float f = (p - 1.f); 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 // 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)^5) ; [0, 0.5)
// y = (1/2)((2x-2)^5 + 2) ; [0.5, 1] // y = (1/2)((2x-2)^5 + 2) ; [0.5, 1]
float QuinticInOut(float p) { float QuinticInOut(float p) {
if (p < 0.5f) { // NOLINT if (p < 0.5f) {
return 16.f * p * p * p * p * p; // NOLINT return 16.f * p * p * p * p * p;
} }
float f = ((2.f * p) - 2.f); // NOLINT const float f = ((2.f * p) - 2.f);
return 0.5f * f * f * f * f * f + 1.f; // NOLINT return 0.5f * f * f * f * f * f + 1.f;
} }
// Modeled after quarter-cycle of sine wave // Modeled after quarter-cycle of sine wave
@ -127,7 +126,7 @@ float SineOut(float p) {
// Modeled after half sine wave // Modeled after half sine wave
float SineInOut(float p) { 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 // 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)(1 - sqrt(1 - 4x^2)) ; [0, 0.5)
// y = (1/2)(sqrt(-(2x - 3)*(2x - 1)) + 1) ; [0.5, 1] // y = (1/2)(sqrt(-(2x - 3)*(2x - 1)) + 1) ; [0.5, 1]
float CircularInOut(float p) { float CircularInOut(float p) {
if (p < 0.5f) { // NOLINT if (p < 0.5f) {
return 0.5f * (1.f - std::sqrt(1.f - 4.f * (p * p))); // NOLINT 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); 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)) // Modeled after the exponential function y = 2^(10(x - 1))
float ExponentialIn(float p) { 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 // Modeled after the exponential function y = -2^(-10x) + 1
float ExponentialOut(float p) { 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 // Modeled after the piecewise exponential
@ -169,21 +167,20 @@ float ExponentialInOut(float p) {
return p; return p;
} }
if (p < 0.5f) { // NOLINT if (p < 0.5f) {
return 0.5f * std::pow(2.f, (20.f * p) - 10.f); // NOLINT 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)) // Modeled after the damped sine wave y = sin(13pi/2*x)*pow(2, 10 * (x - 1))
float ElasticIn(float p) { 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) + // Modeled after the damped sine wave y = sin(-13pi/2*(x + 1))*pow(2, -10x) +
// 1 // 1
float ElasticOut(float p) { float ElasticOut(float p) {
// NOLINTNEXTLINE
return std::sin(-13.f * kPi2 * (p + 1.f)) * std::pow(2.f, -10.f * p) + 1.f; 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*(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] // y = (1/2)*(sin(-13pi/2*((2x-1)+1))*pow(2,-10(2*x-1)) + 2) ; [0.5, 1]
float ElasticInOut(float p) { float ElasticInOut(float p) {
if (p < 0.5f) { // NOLINT if (p < 0.5f) {
return 0.5f * std::sin(13.f * kPi2 * (2.f * p)) * // NOLINT return 0.5f * std::sin(13.f * kPi2 * (2.f * p)) *
std::pow(2.f, 10.f * ((2.f * p) - 1.f)); // NOLINT 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 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)) + // NOLINT std::pow(2.f, -10.f * (2.f * p - 1.f)) +
2.f); // NOLINT 2.f);
} }
// Modeled after the overshooting cubic y = x^3-x*sin(x*pi) // 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)*((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] // y = (1/2)*(1-((1-x)^3-(1-x)*sin((1-x)*pi))+1) ; [0.5, 1]
float BackInOut(float p) { float BackInOut(float p) {
if (p < 0.5f) { // NOLINT if (p < 0.5f) {
const float f = 2.f * p; 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 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; // NOLINT return 0.5f * (1.f - (f * f * f - f * std::sin(f * kPi))) + 0.5f;
} }
float BounceIn(float p) { float BounceIn(float p) {
@ -228,27 +225,26 @@ float BounceIn(float p) {
} }
float BounceOut(float p) { float BounceOut(float p) {
if (p < 4.f / 11.f) { // NOLINT if (p < 4.f / 11.f) {
return (121.f * p * p) / 16.f; // NOLINT return (121.f * p * p) / 16.f;
} }
if (p < 8.f / 11.f) { // NOLINT if (p < 8.f / 11.f) {
return (363.f / 40.f * p * p) - (99.f / 10.f * p) + 17.f / 5.f; // NOLINT return (363.f / 40.f * p * p) - (99.f / 10.f * p) + 17.f / 5.f;
} }
if (p < 9.f / 10.f) { // NOLINT if (p < 9.f / 10.f) {
return (4356.f / 361.f * p * p) - (35442.f / 1805.f * p) + // NOLINT return (4356.f / 361.f * p * p) - (35442.f / 1805.f * p) + 16061.f / 1805.f;
16061.f / 1805.f; // NOLINT
} }
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 float BounceInOut(float p) {
if (p < 0.5f) { // NOLINT if (p < 0.5f) {
return 0.5f * BounceIn(p * 2.f); // NOLINT 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 } // namespace easing
@ -278,11 +274,12 @@ void Animator::OnAnimation(Params& params) {
if (current_ <= Duration()) { if (current_ <= Duration()) {
*value_ = from_; *value_ = from_;
} else { } else {
*value_ = from_ + *value_ = from_ + (to_ - from_) * easing_function_(current_ / duration_);
(to_ - from_) * easing_function_(current_ / duration_); // NOLINT
} }
RequestAnimationFrame(); RequestAnimationFrame();
} }
} // namespace ftxui::animation } // namespace ftxui::animation
// NOLINTEND(*-magic-numbers)

View File

@ -7,7 +7,7 @@
namespace ftxui { namespace ftxui {
TEST(AnimationTest, StartAndEnd) { TEST(AnimationTest, StartAndEnd) {
std::vector<animation::easing::Function> functions = { const std::vector<animation::easing::Function> functions = {
animation::easing::Linear, animation::easing::QuadraticIn, animation::easing::Linear, animation::easing::QuadraticIn,
animation::easing::QuadraticOut, animation::easing::QuadraticInOut, animation::easing::QuadraticOut, animation::easing::QuadraticInOut,
animation::easing::CubicIn, animation::easing::CubicOut, animation::easing::CubicIn, animation::easing::CubicOut,
@ -25,7 +25,7 @@ TEST(AnimationTest, StartAndEnd) {
animation::easing::BounceIn, animation::easing::BounceOut, animation::easing::BounceIn, animation::easing::BounceOut,
animation::easing::BounceInOut, animation::easing::BounceInOut,
}; };
for (auto& it : functions) { for (const auto& it : functions) {
EXPECT_NEAR(0.F, it(0.F), 1.0e-4); EXPECT_NEAR(0.F, it(0.F), 1.0e-4);
EXPECT_NEAR(1.F, it(1.F), 1.0e-4); EXPECT_NEAR(1.F, it(1.F), 1.0e-4);
} }

View File

@ -74,7 +74,7 @@ Component Button(ConstStringRef label,
const bool focused = Focused(); const bool focused = Focused();
const bool focused_or_hover = focused || mouse_hover_; 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()) { if (target != animator_background_.to()) {
SetAnimationTarget(target); SetAnimationTarget(target);
} }

View File

@ -13,6 +13,7 @@
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
#include "ftxui/screen/terminal.hpp" // for SetColorSupport, Color, TrueColor #include "ftxui/screen/terminal.hpp" // for SetColorSupport, Color, TrueColor
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
namespace { namespace {
@ -189,6 +190,7 @@ TEST(ButtonTest, Animation) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved. // Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -8,6 +8,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(CollapsibleTest, Basic) { TEST(CollapsibleTest, Basic) {
@ -47,6 +48,7 @@ TEST(CollapsibleTest, Basic) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved. // Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -44,13 +44,13 @@ class ContainerBase : public ComponentBase {
return nullptr; return nullptr;
} }
return children_[*selector_ % children_.size()]; return children_[static_cast<size_t>(*selector_) % children_.size()];
} }
void SetActiveChild(ComponentBase* child) override { void SetActiveChild(ComponentBase* child) override {
for (size_t i = 0; i < children_.size(); ++i) { for (size_t i = 0; i < children_.size(); ++i) {
if (children_[i].get() == child) { if (children_[i].get() == child) {
*selector_ = (int)i; *selector_ = static_cast<int>(i);
return; return;
} }
} }
@ -68,7 +68,7 @@ class ContainerBase : public ComponentBase {
int* selector_ = nullptr; int* selector_ = nullptr;
void MoveSelector(int dir) { 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) { i += dir) {
if (children_[i]->Focusable()) { if (children_[i]->Focusable()) {
*selector_ = i; *selector_ = i;
@ -85,7 +85,7 @@ class ContainerBase : public ComponentBase {
const size_t i = ((size_t(*selector_ + offset * dir + children_.size())) % const size_t i = ((size_t(*selector_ + offset * dir + children_.size())) %
children_.size()); children_.size());
if (children_[i]->Focusable()) { if (children_[i]->Focusable()) {
*selector_ = (int)i; *selector_ = int(i);
return; return;
} }
} }
@ -225,7 +225,7 @@ class TabContainer : public ContainerBase {
if (children_.empty()) { if (children_.empty()) {
return false; return false;
} }
return children_[*selector_ % children_.size()]->Focusable(); return children_[size_t(*selector_) % children_.size()]->Focusable();
} }
bool OnMouseEvent(Event event) override { bool OnMouseEvent(Event event) override {

View File

@ -1,12 +1,13 @@
#include <algorithm> // for max, min #include <cstddef> // for size_t
#include <functional> // for function #include <functional> // for function
#include <memory> // for __shared_ptr_access, shared_ptr, allocator #include <memory> // for __shared_ptr_access, allocator, shared_ptr
#include <string> // for string #include <string> // for string
#include "ftxui/component/component.hpp" // for Maybe, Checkbox, Make, Radiobox, Vertical, Dropdown #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_base.hpp" // for Component, ComponentBase
#include "ftxui/component/component_options.hpp" // for CheckboxOption, EntryState #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/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 #include "ftxui/util/ref.hpp" // for ConstStringListRef
namespace ftxui { namespace ftxui {
@ -38,8 +39,8 @@ Component Dropdown(ConstStringListRef entries, int* selected) {
} }
Element Render() override { Element Render() override {
*selected_ = std::min((int)entries_.size() - 1, std::max(0, *selected_)); *selected_ = util::clamp(*selected_, 0, (int)entries_.size() - 1);
title_ = entries_[*selected_]; title_ = entries_[static_cast<size_t>(*selected_)];
if (show_) { if (show_) {
const int max_height = 12; const int max_height = 12;
return vbox({ return vbox({

View File

@ -29,7 +29,7 @@ Event Event::Mouse(std::string input, struct Mouse mouse) {
Event event; Event event;
event.input_ = std::move(input); event.input_ = std::move(input);
event.type_ = Type::Mouse; event.type_ = Type::Mouse;
event.mouse_ = mouse; // NOLINT event.data_.mouse = mouse; // NOLINT
return event; return event;
} }
@ -45,8 +45,7 @@ Event Event::CursorReporting(std::string input, int x, int y) {
Event event; Event event;
event.input_ = std::move(input); event.input_ = std::move(input);
event.type_ = Type::CursorReporting; event.type_ = Type::CursorReporting;
event.cursor_.x = x; // NOLINT event.data_.cursor = {x, y}; // NOLINT
event.cursor_.y = y; // NOLINT
return event; return event;
} }

View File

@ -9,6 +9,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
namespace { namespace {
@ -186,6 +187,7 @@ TEST(HoverableTest, Coverage) {
} // namespace } // namespace
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2021 Arthur Sonzogni. All rights reserved. // Copyright 2021 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -12,6 +12,7 @@
#include "ftxui/screen/screen.hpp" // for Fixed, Screen, Pixel #include "ftxui/screen/screen.hpp" // for Fixed, Screen, Pixel
#include "ftxui/util/ref.hpp" // for Ref #include "ftxui/util/ref.hpp" // for Ref
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(InputTest, Init) { TEST(InputTest, Init) {
@ -488,6 +489,7 @@ TEST(InputTest, CtrlArrowRight2) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2021 Arthur Sonzogni. All rights reserved. // Copyright 2021 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -14,6 +14,7 @@
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
#include "ftxui/util/ref.hpp" // for Ref #include "ftxui/util/ref.hpp" // for Ref
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
using namespace std::chrono_literals; using namespace std::chrono_literals;
@ -233,6 +234,7 @@ TEST(MenuTest, AnimationsVertical) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved. // Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -7,6 +7,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(ModalTest, Basic) { TEST(ModalTest, Basic) {
@ -39,6 +40,7 @@ TEST(ModalTest, Basic) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved. // Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -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/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 #include "ftxui/util/ref.hpp" // for Ref
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(RadioboxTest, NavigationArrow) { TEST(RadioboxTest, NavigationArrow) {
@ -303,6 +304,7 @@ TEST(RadioboxTest, RemoveEntries) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved. // Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -4,6 +4,7 @@
#include "ftxui/component/receiver.hpp" #include "ftxui/component/receiver.hpp"
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(Receiver, Basic) { TEST(Receiver, Basic) {
@ -74,6 +75,7 @@ TEST(Receiver, BasicWithThread) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved. // Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -18,7 +18,7 @@ namespace {
class ResizableSplitBase : public ComponentBase { class ResizableSplitBase : public ComponentBase {
public: public:
ResizableSplitBase(ResizableSplitOption options) explicit ResizableSplitBase(ResizableSplitOption options)
: options_(std::move(options)) { : options_(std::move(options)) {
Add(Container::Horizontal({ Add(Container::Horizontal({
options_->main, options_->main,

View File

@ -10,6 +10,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
namespace { namespace {
@ -203,6 +204,7 @@ TEST(ResizableSplit, BasicBottomWithCustomSeparator) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved. // Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -1,6 +1,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h> // for Test, TestInfo (ptr only), TEST, EXPECT_EQ, Message, TestPartResult
#include <csignal> // for raise, SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM #include <csignal> // for raise, SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM
#include <ftxui/component/event.hpp> // for Event, Event::Custom #include <ftxui/component/event.hpp> // for Event, Event::Custom
#include <tuple> // for _Swallow_assign, ignore
#include "ftxui/component/component.hpp" // for Renderer #include "ftxui/component/component.hpp" // for Renderer
#include "ftxui/component/screen_interactive.hpp" #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. // The tree of components. This defines how to navigate using the keyboard.
auto component = Renderer([&] { auto component = Renderer([&] {
called++; called++;
std::raise(signal); std::ignore = std::raise(signal);
called++; called++;
return text(""); return text("");
}); });

View File

@ -1,6 +1,6 @@
#include <gtest/gtest.h> // for AssertionResult, Message, TestPartResult, Test, EXPECT_EQ, EXPECT_TRUE, TestInfo (ptr only), EXPECT_FALSE, TEST #include <gtest/gtest.h> // for AssertionResult, Message, TestPartResult, Test, EXPECT_EQ, EXPECT_TRUE, TestInfo (ptr only), EXPECT_FALSE, TEST
#include <stddef.h> // for size_t
#include <array> // for array #include <array> // for array
#include <cstddef> // for size_t
#include <ftxui/component/mouse.hpp> // for Mouse, Mouse::Left, Mouse::Pressed, Mouse::Released #include <ftxui/component/mouse.hpp> // for Mouse, Mouse::Left, Mouse::Pressed, Mouse::Released
#include <ftxui/dom/direction.hpp> // for Direction, Direction::Down, Direction::Left, Direction::Right, Direction::Up #include <ftxui/dom/direction.hpp> // for Direction, Direction::Down, Direction::Left, Direction::Right, Direction::Up
#include <ftxui/dom/elements.hpp> // for frame #include <ftxui/dom/elements.hpp> // for frame
@ -13,6 +13,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
namespace { namespace {
@ -187,6 +188,7 @@ TEST(SliderTest, Focus) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved. // Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -9,6 +9,7 @@
#include "ftxui/component/receiver.hpp" // for MakeReceiver, ReceiverImpl #include "ftxui/component/receiver.hpp" // for MakeReceiver, ReceiverImpl
#include "ftxui/component/terminal_input_parser.hpp" #include "ftxui/component/terminal_input_parser.hpp"
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
// Test char |c| to are trivially converted into |Event::Character(c)|. // Test char |c| to are trivially converted into |Event::Character(c)|.
@ -384,6 +385,7 @@ TEST(Event, Special) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved. // Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -1,17 +1,17 @@
#include <gtest/gtest.h> #include <gtest/gtest.h> // for AssertionResult, Message, TestPartResult, EXPECT_EQ, Test, EXPECT_TRUE, TestInfo (ptr only), EXPECT_FALSE, TEST
#include <functional> // for function #include <functional> // for function
#include <memory> // for __shared_ptr_access, shared_ptr, allocator #include <memory> // for __shared_ptr_access, shared_ptr, allocator
#include <string> // for string, basic_string #include <string> // for string, basic_string
#include <vector> // for vector #include <vector> // for vector
#include "ftxui/component/captured_mouse.hpp" // for ftxui #include "ftxui/component/component.hpp" // for Menu, Toggle
#include "ftxui/component/component.hpp" // for Toggle
#include "ftxui/component/component_base.hpp" // for ComponentBase #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/component/event.hpp" // for Event, Event::ArrowLeft, Event::ArrowRight, Event::Return, Event::Tab, Event::TabReverse
#include "ftxui/util/ref.hpp" // for Ref #include "ftxui/util/ref.hpp" // for Ref
using namespace ftxui; // NOLINTBEGIN
namespace ftxui {
TEST(ToggleTest, leftRightArrow) { TEST(ToggleTest, leftRightArrow) {
std::vector<std::string> entries = {"On", "Off"}; std::vector<std::string> entries = {"On", "Off"};
@ -177,6 +177,9 @@ TEST(ToggleTest, RemoveEntries) {
EXPECT_EQ(focused_entry, 1); EXPECT_EQ(focused_entry, 1);
} }
} // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved. // Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in
// the LICENSE file. // the LICENSE file.

View File

@ -4,6 +4,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
static void BencharkBasic(benchmark::State& state) { static void BencharkBasic(benchmark::State& state) {
@ -12,11 +13,11 @@ static void BencharkBasic(benchmark::State& state) {
text("Test"), text("Test"),
separator(), separator(),
hbox({ hbox({
gauge(0.9), gauge(0.9f),
separator() | blink, separator() | blink,
gauge(0.5), gauge(0.5f),
separator() | inverted, separator() | inverted,
gauge(0.1), gauge(0.1f),
separator(), separator(),
}), }),
text("Test"), text("Test"),
@ -30,6 +31,7 @@ static void BencharkBasic(benchmark::State& state) {
BENCHMARK(BencharkBasic)->DenseRange(0, 256, 16); BENCHMARK(BencharkBasic)->DenseRange(0, 256, 16);
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2021 Arthur Sonzogni. All rights reserved. // Copyright 2021 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen, Pixel #include "ftxui/screen/screen.hpp" // for Screen, Pixel
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(BlinkTest, Basic) { TEST(BlinkTest, Basic) {
@ -15,6 +16,7 @@ TEST(BlinkTest, Basic) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved. // Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen, Pixel #include "ftxui/screen/screen.hpp" // for Screen, Pixel
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(BoldTest, Basic) { TEST(BoldTest, Basic) {
@ -15,6 +16,7 @@ TEST(BoldTest, Basic) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved. // Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen, Pixel #include "ftxui/screen/screen.hpp" // for Screen, Pixel
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(BorderTest, Default) { TEST(BorderTest, Default) {
@ -100,6 +101,7 @@ TEST(BorderTest, Window) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved. // Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -1,6 +1,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <stdint.h> // for uint32_t #include <cstdint> // for uint32_t
#include <string> // for allocator, string #include <string> // for allocator, string
#include "ftxui/dom/canvas.hpp" // for Canvas #include "ftxui/dom/canvas.hpp" // for Canvas
#include "ftxui/dom/elements.hpp" // for canvas #include "ftxui/dom/elements.hpp" // for canvas
@ -9,6 +9,7 @@
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
#include "ftxui/screen/terminal.hpp" // for SetColorSupport, Color, TrueColor #include "ftxui/screen/terminal.hpp" // for SetColorSupport, Color, TrueColor
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
namespace { namespace {
@ -101,6 +102,7 @@ TEST(CanvasTest, GoldText) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved. // Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -6,6 +6,7 @@
#include "ftxui/screen/color.hpp" // for Color, Color::Red, Color::RedLight #include "ftxui/screen/color.hpp" // for Color, Color::Red, Color::RedLight
#include "ftxui/screen/screen.hpp" // for Screen, Pixel #include "ftxui/screen/screen.hpp" // for Screen, Pixel
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(ColorTest, Foreground) { TEST(ColorTest, Foreground) {
@ -25,6 +26,7 @@ TEST(ColorTest, Background) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved. // Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(DBoxTest, Basic) { TEST(DBoxTest, Basic) {
@ -29,6 +30,7 @@ TEST(DBoxTest, Basic) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved. // Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen, Pixel #include "ftxui/screen/screen.hpp" // for Screen, Pixel
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(DimTest, Basic) { TEST(DimTest, Basic) {
@ -15,6 +16,7 @@ TEST(DimTest, Basic) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved. // Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -4,6 +4,7 @@
#include "ftxui/dom/flexbox_helper.hpp" #include "ftxui/dom/flexbox_helper.hpp"
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(FlexboxHelperTest, BasicRow) { TEST(FlexboxHelperTest, BasicRow) {
@ -227,6 +228,7 @@ TEST(FlexboxHelperTest, BasicColumnInversed) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved. // Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -6,6 +6,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(FlexboxTest, BasicRow) { TEST(FlexboxTest, BasicRow) {
@ -454,6 +455,7 @@ TEST(FlexboxTest, Focus) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2021 Arthur Sonzogni. All rights reserved. // Copyright 2021 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(GaugeTest, ZeroHorizontal) { TEST(GaugeTest, ZeroHorizontal) {
@ -96,6 +97,7 @@ TEST(GaugeTest, OneVertical) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved. // Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -1,6 +1,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <stddef.h> // for size_t
#include <algorithm> // for remove #include <algorithm> // for remove
#include <cstddef> // for size_t
#include <memory> // for shared_ptr #include <memory> // for shared_ptr
#include <string> // for allocator, basic_string, string #include <string> // for allocator, basic_string, string
#include <vector> // for vector #include <vector> // for vector
@ -9,6 +9,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
namespace { namespace {
@ -615,6 +616,7 @@ TEST(GridboxTest, Focus) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved. // Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -1,15 +1,14 @@
#include <gtest/gtest.h> #include <gtest/gtest.h> // for Test, TestInfo (ptr only), EXPECT_EQ, Message, TEST, TestPartResult
#include <stddef.h> // for size_t #include <cstddef> // for size_t
#include <string> // for string, allocator #include <string> // for allocator, basic_string, string
#include <vector> // for vector #include <vector> // 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/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for ftxui
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
using namespace ftxui; // NOLINTBEGIN
using namespace ftxui; namespace ftxui {
TEST(HBoxTest, NoFlex_NoFlex_NoFlex) { TEST(HBoxTest, NoFlex_NoFlex_NoFlex) {
auto root = hbox({ auto root = hbox({
@ -356,6 +355,9 @@ TEST(HBoxTest, FlexGrow_NoFlex_FlewShrink) {
} }
} }
} // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved. // Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in
// the LICENSE file. // the LICENSE file.

View File

@ -1,6 +1,6 @@
#include <stddef.h> // for size_t
#include <algorithm> // for max, min, sort, copy #include <algorithm> // for max, min, sort, copy
#include <cmath> // for fmod, cos, sin #include <cmath> // for fmod, cos, sin
#include <cstddef> // for size_t
#include <ftxui/dom/linear_gradient.hpp> // for LinearGradient::Stop, LinearGradient #include <ftxui/dom/linear_gradient.hpp> // for LinearGradient::Stop, LinearGradient
#include <memory> // for allocator_traits<>::value_type, make_shared #include <memory> // for allocator_traits<>::value_type, make_shared
#include <optional> // for optional, operator!=, operator< #include <optional> // for optional, operator!=, operator<
@ -25,7 +25,7 @@ struct LinearGradientNormalized {
// Convert a LinearGradient to a normalized version. // Convert a LinearGradient to a normalized version.
LinearGradientNormalized Normalize(LinearGradient gradient) { LinearGradientNormalized Normalize(LinearGradient gradient) {
// Handle gradient of size 0. // Handle gradient of size 0.
if (gradient.stops.size() == 0) { if (gradient.stops.empty()) {
return LinearGradientNormalized{ return LinearGradientNormalized{
0.f, {Color::Default, Color::Default}, {0.f, 1.f}}; 0.f, {Color::Default, Color::Default}, {0.f, 1.f}};
} }
@ -46,11 +46,13 @@ LinearGradientNormalized Normalize(LinearGradient gradient) {
} }
if (i - last_checkpoint >= 2) { if (i - last_checkpoint >= 2) {
const float min = gradient.stops[i].position.value(); const float min = gradient.stops[i].position.value(); // NOLINT
const float max = gradient.stops[last_checkpoint].position.value(); const float max =
gradient.stops[last_checkpoint].position.value(); // NOLINT
for (size_t j = last_checkpoint + 1; j < i; ++j) { for (size_t j = last_checkpoint + 1; j < i; ++j) {
gradient.stops[j].position = gradient.stops[j].position = min + (max - min) *
min + (max - min) * (j - last_checkpoint) / (i - last_checkpoint); float(j - last_checkpoint) /
float(i - last_checkpoint);
} }
} }
@ -74,10 +76,11 @@ LinearGradientNormalized Normalize(LinearGradient gradient) {
// Normalize the angle. // Normalize the angle.
LinearGradientNormalized normalized; LinearGradientNormalized normalized;
// NOLINTNEXTLINE
normalized.angle = std::fmod(std::fmod(gradient.angle, 360.f) + 360.f, 360.f); normalized.angle = std::fmod(std::fmod(gradient.angle, 360.f) + 360.f, 360.f);
for (auto& stop : gradient.stops) { for (auto& stop : gradient.stops) {
normalized.colors.push_back(stop.color); normalized.colors.push_back(stop.color);
normalized.positions.push_back(stop.position.value()); normalized.positions.push_back(stop.position.value()); // NOLINT
} }
return normalized; return normalized;
} }
@ -87,6 +90,7 @@ Color Interpolate(const LinearGradientNormalized& gradient, float t) {
size_t i = 1; size_t i = 1;
while (true) { while (true) {
if (i > gradient.positions.size()) { if (i > gradient.positions.size()) {
// NOLINTNEXTLINE
return Color::Interpolate(0.5f, gradient.colors.back(), return Color::Interpolate(0.5f, gradient.colors.back(),
gradient.colors.back()); gradient.colors.back());
} }
@ -123,10 +127,10 @@ class LinearGradientColor : public NodeDecorator {
const float dy = std::sin(gradient_.angle * degtorad); const float dy = std::sin(gradient_.angle * degtorad);
// Project every corner to get the extent of the gradient. // Project every corner to get the extent of the gradient.
const float p1 = box_.x_min * dx + box_.y_min * dy; const float p1 = float(box_.x_min) * dx + float(box_.y_min) * dy;
const float p2 = box_.x_min * dx + box_.y_max * dy; const float p2 = float(box_.x_min) * dx + float(box_.y_max) * dy;
const float p3 = box_.x_max * dx + box_.y_min * dy; const float p3 = float(box_.x_max) * dx + float(box_.y_min) * dy;
const float p4 = box_.x_max * dx + box_.y_max * 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 min = std::min({p1, p2, p3, p4});
const float max = std::max({p1, p2, p3, p4}); const float max = std::max({p1, p2, p3, p4});
@ -140,14 +144,14 @@ class LinearGradientColor : public NodeDecorator {
if (background_color_) { if (background_color_) {
for (int y = box_.y_min; y <= box_.y_max; ++y) { for (int y = box_.y_min; y <= box_.y_max; ++y) {
for (int x = box_.x_min; x <= box_.x_max; ++x) { 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); screen.PixelAt(x, y).background_color = Interpolate(gradient_, t);
} }
} }
} else { } else {
for (int y = box_.y_min; y <= box_.y_max; ++y) { for (int y = box_.y_min; y <= box_.y_max; ++y) {
for (int x = box_.x_min; x <= box_.x_max; ++x) { 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); 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 begin The color at the beginning of the gradient.
/// @param end The color at the end of the gradient. /// @param end The color at the end of the gradient.
/// @ingroup dom /// @ingroup dom
LinearGradient::LinearGradient(Color begin, Color end) { LinearGradient::LinearGradient(Color begin, Color end)
stops.push_back({begin, {}}); : LinearGradient(0, begin, end) {}
stops.push_back({end, {}});
}
/// @brief Build a gradient with two colors and an angle. /// @brief Build a gradient with two colors and an angle.
/// @param a The angle of the gradient. /// @param a The angle of the gradient.
/// @param begin The color at the beginning of the gradient. /// @param begin The color at the beginning of the gradient.
/// @param end The color at the end of the gradient. /// @param end The color at the end of the gradient.
/// @ingroup dom /// @ingroup dom
LinearGradient::LinearGradient(float a, Color begin, Color end) { LinearGradient::LinearGradient(float a, Color begin, Color end) : angle(a) {
angle = a;
stops.push_back({begin, {}}); stops.push_back({begin, {}});
stops.push_back({end, {}}); stops.push_back({end, {}});
} }

View File

@ -1,12 +1,13 @@
#include <gtest/gtest.h> // for Test, EXPECT_EQ, Message, TestPartResult, TestInfo (ptr only), TEST #include <gtest/gtest.h> // for Test, EXPECT_EQ, Message, TestPartResult, TestInfo (ptr only), TEST
#include <ftxui/dom/linear_gradient.hpp> // for LinearGradient::Stop, LinearGradient #include <ftxui/dom/linear_gradient.hpp> // for LinearGradient::Stop, LinearGradient
#include <string> // for allocator #include <memory> // for allocator_traits<>::value_type
#include "ftxui/dom/elements.hpp" // for operator|, text, bgcolor, color, Element #include "ftxui/dom/elements.hpp" // for operator|, text, bgcolor, color, Element
#include "ftxui/dom/node.hpp" // for Render #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 #include "ftxui/screen/screen.hpp" // for Screen, Pixel
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(ColorTest, API_default) { TEST(ColorTest, API_default) {
@ -84,6 +85,7 @@ TEST(ColorTest, GradientBackground) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2023 Arthur Sonzogni. All rights reserved. // Copyright 2023 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -7,6 +7,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
namespace { namespace {
@ -197,6 +198,7 @@ TEST(ScrollIndicator, HorizontalFlexbox) {
} // namespace } // namespace
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved. // Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen, Pixel #include "ftxui/screen/screen.hpp" // for Screen, Pixel
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(SeparatorTest, Default) { TEST(SeparatorTest, Default) {
@ -122,6 +123,7 @@ TEST(SeparatorTest, WithPixel) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved. // Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -278,7 +278,7 @@ const std::vector<std::vector<std::vector<std::string>>> elements = {
/// every "step". /// every "step".
/// @ingroup dom /// @ingroup dom
Element spinner(int charset_index, size_t image_index) { Element spinner(int charset_index, size_t image_index) {
if (charset_index == 0) { if (charset_index <= 0) {
const int progress_size = 40; const int progress_size = 40;
image_index %= progress_size; image_index %= progress_size;
if (image_index > progress_size / 2) { if (image_index > progress_size / 2) {

View File

@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(SpinnerTest, Spinner1) { TEST(SpinnerTest, Spinner1) {
@ -36,6 +37,7 @@ TEST(SpinnerTest, Spinner4) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved. // Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -6,6 +6,7 @@
#include "ftxui/dom/table.hpp" #include "ftxui/dom/table.hpp"
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(TableTest, Empty) { TEST(TableTest, Empty) {
@ -731,6 +732,7 @@ TEST(TableTest, Merge) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2021 Arthur Sonzogni. All rights reserved. // Copyright 2021 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(TextTest, ScreenHeightSmaller) { TEST(TextTest, ScreenHeightSmaller) {
@ -118,6 +119,7 @@ TEST(TextTest, CombiningCharactersWithSpace) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved. // Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -5,6 +5,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen, Pixel #include "ftxui/screen/screen.hpp" // for Screen, Pixel
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
TEST(UnderlinedTest, Basic) { TEST(UnderlinedTest, Basic) {
@ -15,6 +16,7 @@ TEST(UnderlinedTest, Basic) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2022 Arthur Sonzogni. All rights reserved. // Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -1,6 +1,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <stddef.h> // for size_t
#include <algorithm> // for remove #include <algorithm> // for remove
#include <cstddef> // for size_t
#include <string> // for string, allocator, basic_string #include <string> // for string, allocator, basic_string
#include <vector> // for vector #include <vector> // for vector
@ -8,6 +8,7 @@
#include "ftxui/dom/node.hpp" // for Render #include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen #include "ftxui/screen/screen.hpp" // for Screen
// NOLINTBEGIN
namespace ftxui { namespace ftxui {
namespace { namespace {
@ -365,6 +366,7 @@ TEST(VBoxText, FlexGrow_NoFlex_FlewShrink) {
} }
} // namespace ftxui } // namespace ftxui
// NOLINTEND
// Copyright 2020 Arthur Sonzogni. All rights reserved. // Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in

View File

@ -212,21 +212,22 @@ Color Color::Interpolate(float t, const Color& a, const Color& b) {
} }
}; };
uint8_t red_a = 0; uint8_t a_r = 0;
uint8_t green_a = 0; uint8_t a_g = 0;
uint8_t blue_a = 0; uint8_t a_b = 0;
uint8_t red_b = 0; uint8_t b_r = 0;
uint8_t green_b = 0; uint8_t b_g = 0;
uint8_t blue_b = 0; uint8_t b_b = 0;
get_color(a, &red_a, &green_a, &blue_a); get_color(a, &a_r, &a_g, &a_b);
get_color(b, &red_b, &green_b, &blue_b); get_color(b, &b_r, &b_g, &b_b);
// Gamma correction: // Gamma correction:
// https://en.wikipedia.org/wiki/Gamma_correction // https://en.wikipedia.org/wiki/Gamma_correction
constexpr float gamma = 2.2f;
return Color::RGB( return Color::RGB(
pow(pow(red_a, 2.2f) * (1 - t) + pow(red_b, 2.2f) * t, 1 / 2.2f), uint8_t(pow(pow(a_r, gamma) * (1 - t) + pow(b_r, gamma) * t, 1 / gamma)),
pow(pow(green_a, 2.2f) * (1 - t) + pow(green_b, 2.2f) * t, 1 / 2.2f), uint8_t(pow(pow(a_g, gamma) * (1 - t) + pow(b_g, gamma) * t, 1 / gamma)),
pow(pow(blue_a, 2.2f) * (1 - t) + pow(blue_b, 2.2f) * t, 1 / 2.2f)); uint8_t(pow(pow(a_b, gamma) * (1 - t) + pow(b_b, gamma) * t, 1 / gamma)));
} }
inline namespace literals { inline namespace literals {