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-*,
-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: ''

View File

@ -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_;
};

View File

@ -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

View File

@ -29,7 +29,7 @@ class Ref {
Ref() {}
Ref(const T& t) : owned_(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_; }

View File

@ -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)

View File

@ -7,7 +7,7 @@
namespace ftxui {
TEST(AnimationTest, StartAndEnd) {
std::vector<animation::easing::Function> functions = {
const std::vector<animation::easing::Function> 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);
}

View File

@ -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);
}

View File

@ -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

View File

@ -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

View File

@ -44,13 +44,13 @@ class ContainerBase : public ComponentBase {
return nullptr;
}
return children_[*selector_ % children_.size()];
return children_[static_cast<size_t>(*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<int>(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 {

View File

@ -1,12 +1,13 @@
#include <algorithm> // for max, min
#include <cstddef> // for size_t
#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 "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<size_t>(*selected_)];
if (show_) {
const int max_height = 12;
return vbox({

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

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/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

View File

@ -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

View File

@ -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,

View File

@ -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

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 <ftxui/component/event.hpp> // for Event, Event::Custom
#include <tuple> // 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("");
});

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 <stddef.h> // for size_t
#include <array> // for array
#include <cstddef> // for size_t
#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/elements.hpp> // 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

View File

@ -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

View File

@ -1,17 +1,17 @@
#include <gtest/gtest.h>
#include <functional> // for function
#include <memory> // for __shared_ptr_access, shared_ptr, allocator
#include <string> // for string, basic_string
#include <vector> // for vector
#include <gtest/gtest.h> // for AssertionResult, Message, TestPartResult, EXPECT_EQ, Test, EXPECT_TRUE, TestInfo (ptr only), EXPECT_FALSE, TEST
#include <functional> // for function
#include <memory> // for __shared_ptr_access, shared_ptr, allocator
#include <string> // for string, basic_string
#include <vector> // 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<std::string> 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.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include <stdint.h> // for uint32_t
#include <string> // for allocator, string
#include <cstdint> // for uint32_t
#include <string> // 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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include <stddef.h> // for size_t
#include <algorithm> // for remove
#include <cstddef> // for size_t
#include <memory> // for shared_ptr
#include <string> // for allocator, basic_string, string
#include <vector> // 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

View File

@ -1,15 +1,14 @@
#include <gtest/gtest.h>
#include <stddef.h> // for size_t
#include <string> // for string, allocator
#include <vector> // for vector
#include <gtest/gtest.h> // for Test, TestInfo (ptr only), EXPECT_EQ, Message, TEST, TestPartResult
#include <cstddef> // for size_t
#include <string> // for allocator, basic_string, string
#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/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.

View File

@ -1,6 +1,6 @@
#include <stddef.h> // for size_t
#include <algorithm> // for max, min, sort, copy
#include <cmath> // for fmod, cos, sin
#include <cstddef> // for size_t
#include <ftxui/dom/linear_gradient.hpp> // for LinearGradient::Stop, LinearGradient
#include <memory> // for allocator_traits<>::value_type, make_shared
#include <optional> // 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, {}});
}

View File

@ -1,12 +1,13 @@
#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 <string> // for allocator
#include <memory> // 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

View File

@ -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

View File

@ -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

View File

@ -278,7 +278,7 @@ const std::vector<std::vector<std::vector<std::string>>> 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) {

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include <stddef.h> // for size_t
#include <algorithm> // for remove
#include <cstddef> // for size_t
#include <string> // for string, allocator, basic_string
#include <vector> // 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

View File

@ -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 {