From 789a600f722206db7cd177867fb67f7089bf88a7 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Wed, 1 May 2024 11:37:21 +0200 Subject: [PATCH] Generate compile commands for clangd. Fix all the diagnostics reported. Bug: https://github.com/ArthurSonzogni/FTXUI/issues/828 --- CMakeLists.txt | 2 ++ include/ftxui/component/animation.hpp | 19 +++++----- include/ftxui/component/captured_mouse.hpp | 5 +++ include/ftxui/component/component.hpp | 6 ++-- include/ftxui/component/component_base.hpp | 10 +++--- include/ftxui/component/loop.hpp | 7 ++-- include/ftxui/component/receiver.hpp | 19 ++++++---- include/ftxui/dom/elements.hpp | 4 +-- include/ftxui/dom/node.hpp | 2 +- include/ftxui/dom/table.hpp | 4 +-- include/ftxui/dom/take_any_args.hpp | 4 ++- include/ftxui/screen/color.hpp | 2 ++ include/ftxui/screen/string.hpp | 8 ++--- include/ftxui/util/autoreset.hpp | 4 +++ include/ftxui/util/ref.hpp | 42 ++++++++++++++-------- src/ftxui/component/component_fuzzer.cpp | 3 +- src/ftxui/dom/box_helper.hpp | 6 ++-- src/ftxui/dom/flexbox_helper.hpp | 6 ++-- src/ftxui/dom/node_decorator.hpp | 2 +- src/ftxui/screen/string_internal.hpp | 2 ++ src/ftxui/screen/util.hpp | 6 ++-- 21 files changed, 98 insertions(+), 65 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65f41dbdb..bf4a9dac3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,8 @@ else() ${FTXUI_MICROSOFT_TERMINAL_FALLBACK_HELP_TEXT} OFF) endif() +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + include(cmake/ftxui_message.cmake) add_library(screen diff --git a/include/ftxui/component/animation.hpp b/include/ftxui/component/animation.hpp index c9f665ed6..42fd4ad05 100644 --- a/include/ftxui/component/animation.hpp +++ b/include/ftxui/component/animation.hpp @@ -9,9 +9,7 @@ #include "ftxui/component/event.hpp" -namespace ftxui { - -namespace animation { +namespace ftxui::animation { // Components who haven't completed their animation can call this function to // request a new frame to be drawn later. // @@ -26,7 +24,7 @@ using Duration = std::chrono::duration; // Parameter of Component::OnAnimation(param). class Params { public: - Params(Duration duration) : duration_(duration) {} + explicit Params(Duration duration) : duration_(duration) {} /// The duration this animation step represents. Duration duration() const { return duration_; } @@ -93,11 +91,11 @@ float BounceInOut(float p); class Animator { public: - Animator(float* from, - float to = 0.f, - Duration duration = std::chrono::milliseconds(250), - easing::Function easing_function = easing::Linear, - Duration delay = std::chrono::milliseconds(0)); + explicit Animator(float* from, + float to = 0.f, + Duration duration = std::chrono::milliseconds(250), + easing::Function easing_function = easing::Linear, + Duration delay = std::chrono::milliseconds(0)); void OnAnimation(Params&); @@ -112,7 +110,6 @@ class Animator { Duration current_; }; -} // namespace animation -} // namespace ftxui +} // namespace ftxui::animation #endif /* end of include guard: FTXUI_ANIMATION_HPP */ diff --git a/include/ftxui/component/captured_mouse.hpp b/include/ftxui/component/captured_mouse.hpp index 4ed6d75ae..234e12f6e 100644 --- a/include/ftxui/component/captured_mouse.hpp +++ b/include/ftxui/component/captured_mouse.hpp @@ -9,6 +9,11 @@ namespace ftxui { class CapturedMouseInterface { public: + CapturedMouseInterface() = default; + CapturedMouseInterface(const CapturedMouseInterface&) = default; + CapturedMouseInterface(CapturedMouseInterface&&) = delete; + CapturedMouseInterface& operator=(const CapturedMouseInterface&) = default; + CapturedMouseInterface& operator=(CapturedMouseInterface&&) = delete; virtual ~CapturedMouseInterface() = default; }; using CapturedMouse = std::unique_ptr; diff --git a/include/ftxui/component/component.hpp b/include/ftxui/component/component.hpp index d9b709987..0251803dc 100644 --- a/include/ftxui/component/component.hpp +++ b/include/ftxui/component/component.hpp @@ -96,9 +96,9 @@ Component Slider(ConstStringRef label, ConstRef increment = 5.f); Component Slider(ConstStringRef label, Ref value, - ConstRef min = 0l, - ConstRef max = 100l, - ConstRef increment = 5l); + ConstRef min = 0L, + ConstRef max = 100L, + ConstRef increment = 5L); Component ResizableSplit(ResizableSplitOption options); Component ResizableSplitLeft(Component main, Component back, int* main_size); diff --git a/include/ftxui/component/component_base.hpp b/include/ftxui/component/component_base.hpp index 1e3fa133f..622af0a1d 100644 --- a/include/ftxui/component/component_base.hpp +++ b/include/ftxui/component/component_base.hpp @@ -29,14 +29,16 @@ using Components = std::vector; /// @ingroup component class ComponentBase { public: - // virtual Destructor. + explicit ComponentBase(Components children) + : children_(std::move(children)) {} virtual ~ComponentBase(); - ComponentBase() = default; - // A component is not copiable. + // A component is not copyable/movable. ComponentBase(const ComponentBase&) = delete; - void operator=(const ComponentBase&) = delete; + ComponentBase(ComponentBase&&) = delete; + ComponentBase& operator=(const ComponentBase&) = delete; + ComponentBase& operator=(ComponentBase&&) = delete; // Component hierarchy: ComponentBase* Parent() const; diff --git a/include/ftxui/component/loop.hpp b/include/ftxui/component/loop.hpp index 41b340c7d..faef475c6 100644 --- a/include/ftxui/component/loop.hpp +++ b/include/ftxui/component/loop.hpp @@ -24,11 +24,14 @@ class Loop { void RunOnceBlocking(); void Run(); - private: - // This class is non copyable. + // This class is non copyable/movable. + Loop(const Loop&) = default; + Loop(Loop&&) = delete; + Loop& operator=(Loop&&) = delete; Loop(const ScreenInteractive&) = delete; Loop& operator=(const Loop&) = delete; + private: ScreenInteractive* screen_; Component component_; }; diff --git a/include/ftxui/component/receiver.hpp b/include/ftxui/component/receiver.hpp index 95f235397..1b2be684a 100644 --- a/include/ftxui/component/receiver.hpp +++ b/include/ftxui/component/receiver.hpp @@ -54,6 +54,10 @@ template Receiver MakeReceiver(); template class SenderImpl { public: + SenderImpl(const SenderImpl&) = delete; + SenderImpl(SenderImpl&&) = delete; + SenderImpl& operator=(const SenderImpl&) = delete; + SenderImpl& operator=(SenderImpl&&) = delete; void Send(T t) { receiver_->Receive(std::move(t)); } ~SenderImpl() { receiver_->ReleaseSender(); } @@ -61,7 +65,7 @@ class SenderImpl { private: friend class ReceiverImpl; - SenderImpl(ReceiverImpl* consumer) : receiver_(consumer) {} + explicit SenderImpl(ReceiverImpl* consumer) : receiver_(consumer) {} ReceiverImpl* receiver_; }; @@ -73,15 +77,17 @@ class ReceiverImpl { senders_++; return std::unique_ptr>(new SenderImpl(this)); } - ReceiverImpl() { senders_ = 0; } + ReceiverImpl() = default; bool Receive(T* t) { while (senders_ || !queue_.empty()) { std::unique_lock lock(mutex_); - if (queue_.empty()) + if (queue_.empty()) { notifier_.wait(lock); - if (queue_.empty()) + } + if (queue_.empty()) { continue; + } *t = std::move(queue_.front()); queue_.pop(); return true; @@ -91,8 +97,9 @@ class ReceiverImpl { bool ReceiveNonBlocking(T* t) { std::unique_lock lock(mutex_); - if (queue_.empty()) + if (queue_.empty()) { return false; + } *t = queue_.front(); queue_.pop(); return true; @@ -127,7 +134,7 @@ class ReceiverImpl { std::mutex mutex_; std::queue queue_; std::condition_variable notifier_; - std::atomic senders_; + std::atomic senders_{0}; }; template diff --git a/include/ftxui/dom/elements.hpp b/include/ftxui/dom/elements.hpp index b2d1b8b7e..566d76892 100644 --- a/include/ftxui/dom/elements.hpp +++ b/include/ftxui/dom/elements.hpp @@ -80,9 +80,7 @@ Decorator borderStyled(BorderStyle); Decorator borderStyled(BorderStyle, Color); Decorator borderStyled(Color); Decorator borderWith(const Pixel&); -Element window(Element title, - Element content, - BorderStyle border = ROUNDED); +Element window(Element title, Element content, BorderStyle border = ROUNDED); Element spinner(int charset_index, size_t image_index); Element paragraph(const std::string& text); Element paragraphAlignLeft(const std::string& text); diff --git a/include/ftxui/dom/node.hpp b/include/ftxui/dom/node.hpp index a462b0a06..f43157a9d 100644 --- a/include/ftxui/dom/node.hpp +++ b/include/ftxui/dom/node.hpp @@ -22,7 +22,7 @@ using Elements = std::vector; class Node { public: Node(); - Node(Elements children); + explicit Node(Elements children); Node(const Node&) = delete; Node(const Node&&) = delete; Node& operator=(const Node&) = delete; diff --git a/include/ftxui/dom/table.hpp b/include/ftxui/dom/table.hpp index 5b7fd3486..4103665f9 100644 --- a/include/ftxui/dom/table.hpp +++ b/include/ftxui/dom/table.hpp @@ -37,8 +37,8 @@ class TableSelection; class Table { public: Table(); - Table(std::vector>); - Table(std::vector>); + explicit Table(std::vector>); + explicit Table(std::vector>); TableSelection SelectAll(); TableSelection SelectCell(int column, int row); TableSelection SelectRow(int row_index); diff --git a/include/ftxui/dom/take_any_args.hpp b/include/ftxui/dom/take_any_args.hpp index 79491efe6..6de9e8abd 100644 --- a/include/ftxui/dom/take_any_args.hpp +++ b/include/ftxui/dom/take_any_args.hpp @@ -5,6 +5,7 @@ #define FTXUI_DOM_TAKE_ANY_ARGS_HPP // IWYU pragma: private, include "ftxui/dom/elements.hpp" +#include #include namespace ftxui { @@ -19,8 +20,9 @@ inline void Merge(Elements& container, Element element) { template <> inline void Merge(Elements& container, Elements elements) { - for (auto& element : elements) + for (auto& element : elements) { container.push_back(std::move(element)); + } } // Turn a set of arguments into a vector. diff --git a/include/ftxui/screen/color.hpp b/include/ftxui/screen/color.hpp index 8939e5091..7efa0b8dc 100644 --- a/include/ftxui/screen/color.hpp +++ b/include/ftxui/screen/color.hpp @@ -24,10 +24,12 @@ class Color { enum Palette16 : uint8_t; enum Palette256 : uint8_t; + // NOLINTBEGIN Color(); // Transparent. Color(Palette1 index); // Transparent. Color(Palette16 index); // Implicit conversion from index to Color. Color(Palette256 index); // Implicit conversion from index to Color. + // NOLINTEND Color(uint8_t red, uint8_t green, uint8_t blue); static Color RGB(uint8_t red, uint8_t green, uint8_t blue); static Color HSV(uint8_t hue, uint8_t saturation, uint8_t value); diff --git a/include/ftxui/screen/string.hpp b/include/ftxui/screen/string.hpp index 70e761c9c..ddc27029d 100644 --- a/include/ftxui/screen/string.hpp +++ b/include/ftxui/screen/string.hpp @@ -4,10 +4,10 @@ #ifndef FTXUI_SCREEN_STRING_HPP #define FTXUI_SCREEN_STRING_HPP -#include // for size_t -#include // for uint8_t -#include // for string, wstring, to_string -#include // for vector +#include // for size_t +#include // for uint8_t +#include // for string, wstring, to_string +#include // for vector namespace ftxui { std::string to_string(const std::wstring& s); diff --git a/include/ftxui/util/autoreset.hpp b/include/ftxui/util/autoreset.hpp index 2c8bf4ef6..ab33293d1 100644 --- a/include/ftxui/util/autoreset.hpp +++ b/include/ftxui/util/autoreset.hpp @@ -16,6 +16,10 @@ class AutoReset { : variable_(variable), previous_value_(std::move(*variable)) { *variable_ = std::move(new_value); } + AutoReset(const AutoReset&) = delete; + AutoReset(AutoReset&&) = delete; + AutoReset& operator=(const AutoReset&) = delete; + AutoReset& operator=(AutoReset&&) = delete; ~AutoReset() { *variable_ = std::move(previous_value_); } private: diff --git a/include/ftxui/util/ref.hpp b/include/ftxui/util/ref.hpp index 1128b9152..15e03cf74 100644 --- a/include/ftxui/util/ref.hpp +++ b/include/ftxui/util/ref.hpp @@ -15,10 +15,12 @@ template class ConstRef { public: ConstRef() = default; + ConstRef(T t) : variant_(std::move(t)) {} // NOLINT + ConstRef(const T* t) : variant_(t) {} // NOLINT + ConstRef& operator=(ConstRef&&) noexcept = default; ConstRef(const ConstRef&) = default; - ConstRef(ConstRef&&) = default; - ConstRef(T t) : variant_(std::move(t)) {} - ConstRef(const T* t) : variant_(t) {} + ConstRef(ConstRef&&) noexcept = default; + ~ConstRef() = default; // Make a "reseatable" reference ConstRef& operator=(const ConstRef&) = default; @@ -42,10 +44,12 @@ template class Ref { public: Ref() = default; + Ref(T t) : variant_(std::move(t)) {} // NOLINT + Ref(T* t) : variant_(t) {} // NOLINT + ~Ref() = default; + Ref& operator=(Ref&&) noexcept = default; Ref(const Ref&) = default; - Ref(Ref&&) = default; - Ref(T t) : variant_(std::move(t)) {} - Ref(T* t) : variant_(t) {} + Ref(Ref&&) noexcept = default; // Make a "reseatable" reference. Ref& operator=(const Ref&) = default; @@ -77,8 +81,10 @@ class StringRef : public Ref { public: using Ref::Ref; - StringRef(const wchar_t* ref) : StringRef(to_string(std::wstring(ref))) {} - StringRef(const char* ref) : StringRef(std::string(ref)) {} + StringRef(const wchar_t* ref) // NOLINT + : StringRef(to_string(std::wstring(ref))) {} + StringRef(const char* ref) // NOLINT + : StringRef(std::string(ref)) {} }; /// @brief An adapter. Own or reference a constant string. For convenience, this @@ -87,19 +93,27 @@ class ConstStringRef : public ConstRef { public: using ConstRef::ConstRef; - ConstStringRef(const std::wstring* ref) : ConstStringRef(to_string(*ref)) {} - ConstStringRef(const std::wstring ref) : ConstStringRef(to_string(ref)) {} - ConstStringRef(const wchar_t* ref) + ConstStringRef(const std::wstring* ref) // NOLINT + : ConstStringRef(to_string(*ref)) {} + ConstStringRef(const std::wstring ref) // NOLINT + : ConstStringRef(to_string(ref)) {} + ConstStringRef(const wchar_t* ref) // NOLINT : ConstStringRef(to_string(std::wstring(ref))) {} - ConstStringRef(const char* ref) : ConstStringRef(std::string(ref)) {} + ConstStringRef(const char* ref) // NOLINT + : ConstStringRef(std::string(ref)) {} }; /// @brief An adapter. Reference a list of strings. class ConstStringListRef { public: ConstStringListRef() = default; - ConstStringListRef(const std::vector* ref) : ref_(ref) {} - ConstStringListRef(const std::vector* ref) : ref_wide_(ref) {} + ~ConstStringListRef() = default; + ConstStringListRef(ConstStringListRef&&) = delete; + ConstStringListRef& operator=(ConstStringListRef&&) = delete; + ConstStringListRef(const std::vector* ref) // NOLINT + : ref_(ref) {} + ConstStringListRef(const std::vector* ref) // NOLINT + : ref_wide_(ref) {} ConstStringListRef(const ConstStringListRef& other) = default; ConstStringListRef& operator=(const ConstStringListRef& other) = default; diff --git a/src/ftxui/component/component_fuzzer.cpp b/src/ftxui/component/component_fuzzer.cpp index ee41536ea..81501c7d8 100644 --- a/src/ftxui/component/component_fuzzer.cpp +++ b/src/ftxui/component/component_fuzzer.cpp @@ -11,8 +11,9 @@ using namespace ftxui; namespace { bool GeneratorBool(const char*& data, size_t& size) { - if (size == 0) + if (size == 0) { return false; + } auto out = bool(data[0] % 2); data++; diff --git a/src/ftxui/dom/box_helper.hpp b/src/ftxui/dom/box_helper.hpp index 00b5586bb..fbc85bd00 100644 --- a/src/ftxui/dom/box_helper.hpp +++ b/src/ftxui/dom/box_helper.hpp @@ -6,8 +6,7 @@ #include -namespace ftxui { -namespace box_helper { +namespace ftxui::box_helper { struct Element { // Input: @@ -21,7 +20,6 @@ struct Element { void Compute(std::vector* elements, int target_size); -} // namespace box_helper -} // namespace ftxui +} // namespace ftxui::box_helper #endif /* end of include guard: FTXUI_DOM_BOX_HELPER_HPP */ diff --git a/src/ftxui/dom/flexbox_helper.hpp b/src/ftxui/dom/flexbox_helper.hpp index 73d2cf4a4..6b9265d59 100644 --- a/src/ftxui/dom/flexbox_helper.hpp +++ b/src/ftxui/dom/flexbox_helper.hpp @@ -7,8 +7,7 @@ #include #include "ftxui/dom/flexbox_config.hpp" -namespace ftxui { -namespace flexbox_helper { +namespace ftxui::flexbox_helper { struct Block { // Input: @@ -38,7 +37,6 @@ struct Global { void Compute(Global& global); -} // namespace flexbox_helper -} // namespace ftxui +} // namespace ftxui::flexbox_helper #endif /* end of include guard: FTXUI_DOM_FLEXBOX_HELPER_HPP*/ diff --git a/src/ftxui/dom/node_decorator.hpp b/src/ftxui/dom/node_decorator.hpp index 5d96d0dbb..a37751f4b 100644 --- a/src/ftxui/dom/node_decorator.hpp +++ b/src/ftxui/dom/node_decorator.hpp @@ -15,7 +15,7 @@ struct Box; // Helper class. class NodeDecorator : public Node { public: - NodeDecorator(Element child) : Node(unpack(std::move(child))) {} + explicit NodeDecorator(Element child) : Node(unpack(std::move(child))) {} void ComputeRequirement() override; void SetBox(Box box) override; }; diff --git a/src/ftxui/screen/string_internal.hpp b/src/ftxui/screen/string_internal.hpp index 8b58eb9be..048f32781 100644 --- a/src/ftxui/screen/string_internal.hpp +++ b/src/ftxui/screen/string_internal.hpp @@ -5,6 +5,8 @@ #define FTXUI_SCREEN_STRING_INTERNAL_HPP #include +#include +#include namespace ftxui { diff --git a/src/ftxui/screen/util.hpp b/src/ftxui/screen/util.hpp index 91a769b8a..0f2a5f27d 100644 --- a/src/ftxui/screen/util.hpp +++ b/src/ftxui/screen/util.hpp @@ -4,8 +4,7 @@ #ifndef FTXUI_SCREEN_UTIL_HPP #define FTXUI_SCREEN_UTIL_HPP -namespace ftxui { -namespace util { +namespace ftxui::util { // Similar to std::clamp, but allow hi to be lower than lo. template @@ -13,7 +12,6 @@ constexpr const T& clamp(const T& v, const T& lo, const T& hi) { return v < lo ? lo : hi < v ? hi : v; } -} // namespace util -} // namespace ftxui +} // namespace ftxui::util #endif /* end of include guard: FTXUI_SCREEN_UTIL_HPP */