Generate compile commands for clangd.

Fix all the diagnostics reported.

Bug: https://github.com/ArthurSonzogni/FTXUI/issues/828
This commit is contained in:
ArthurSonzogni 2024-05-01 11:37:21 +02:00
parent 6a755f3760
commit 789a600f72
No known key found for this signature in database
GPG Key ID: 41D98248C074CD6C
21 changed files with 98 additions and 65 deletions

View File

@ -27,6 +27,8 @@ else()
${FTXUI_MICROSOFT_TERMINAL_FALLBACK_HELP_TEXT} OFF) ${FTXUI_MICROSOFT_TERMINAL_FALLBACK_HELP_TEXT} OFF)
endif() endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(cmake/ftxui_message.cmake) include(cmake/ftxui_message.cmake)
add_library(screen add_library(screen

View File

@ -9,9 +9,7 @@
#include "ftxui/component/event.hpp" #include "ftxui/component/event.hpp"
namespace ftxui { namespace ftxui::animation {
namespace animation {
// Components who haven't completed their animation can call this function to // Components who haven't completed their animation can call this function to
// request a new frame to be drawn later. // request a new frame to be drawn later.
// //
@ -26,7 +24,7 @@ using Duration = std::chrono::duration<float>;
// Parameter of Component::OnAnimation(param). // Parameter of Component::OnAnimation(param).
class Params { class Params {
public: public:
Params(Duration duration) : duration_(duration) {} explicit Params(Duration duration) : duration_(duration) {}
/// The duration this animation step represents. /// The duration this animation step represents.
Duration duration() const { return duration_; } Duration duration() const { return duration_; }
@ -93,11 +91,11 @@ float BounceInOut(float p);
class Animator { class Animator {
public: public:
Animator(float* from, explicit Animator(float* from,
float to = 0.f, float to = 0.f,
Duration duration = std::chrono::milliseconds(250), Duration duration = std::chrono::milliseconds(250),
easing::Function easing_function = easing::Linear, easing::Function easing_function = easing::Linear,
Duration delay = std::chrono::milliseconds(0)); Duration delay = std::chrono::milliseconds(0));
void OnAnimation(Params&); void OnAnimation(Params&);
@ -112,7 +110,6 @@ class Animator {
Duration current_; Duration current_;
}; };
} // namespace animation } // namespace ftxui::animation
} // namespace ftxui
#endif /* end of include guard: FTXUI_ANIMATION_HPP */ #endif /* end of include guard: FTXUI_ANIMATION_HPP */

View File

@ -9,6 +9,11 @@
namespace ftxui { namespace ftxui {
class CapturedMouseInterface { class CapturedMouseInterface {
public: public:
CapturedMouseInterface() = default;
CapturedMouseInterface(const CapturedMouseInterface&) = default;
CapturedMouseInterface(CapturedMouseInterface&&) = delete;
CapturedMouseInterface& operator=(const CapturedMouseInterface&) = default;
CapturedMouseInterface& operator=(CapturedMouseInterface&&) = delete;
virtual ~CapturedMouseInterface() = default; virtual ~CapturedMouseInterface() = default;
}; };
using CapturedMouse = std::unique_ptr<CapturedMouseInterface>; using CapturedMouse = std::unique_ptr<CapturedMouseInterface>;

View File

@ -96,9 +96,9 @@ Component Slider(ConstStringRef label,
ConstRef<float> increment = 5.f); ConstRef<float> increment = 5.f);
Component Slider(ConstStringRef label, Component Slider(ConstStringRef label,
Ref<long> value, Ref<long> value,
ConstRef<long> min = 0l, ConstRef<long> min = 0L,
ConstRef<long> max = 100l, ConstRef<long> max = 100L,
ConstRef<long> increment = 5l); ConstRef<long> increment = 5L);
Component ResizableSplit(ResizableSplitOption options); Component ResizableSplit(ResizableSplitOption options);
Component ResizableSplitLeft(Component main, Component back, int* main_size); Component ResizableSplitLeft(Component main, Component back, int* main_size);

View File

@ -29,14 +29,16 @@ using Components = std::vector<Component>;
/// @ingroup component /// @ingroup component
class ComponentBase { class ComponentBase {
public: public:
// virtual Destructor. explicit ComponentBase(Components children)
: children_(std::move(children)) {}
virtual ~ComponentBase(); virtual ~ComponentBase();
ComponentBase() = default; ComponentBase() = default;
// A component is not copiable. // A component is not copyable/movable.
ComponentBase(const ComponentBase&) = delete; ComponentBase(const ComponentBase&) = delete;
void operator=(const ComponentBase&) = delete; ComponentBase(ComponentBase&&) = delete;
ComponentBase& operator=(const ComponentBase&) = delete;
ComponentBase& operator=(ComponentBase&&) = delete;
// Component hierarchy: // Component hierarchy:
ComponentBase* Parent() const; ComponentBase* Parent() const;

View File

@ -24,11 +24,14 @@ class Loop {
void RunOnceBlocking(); void RunOnceBlocking();
void Run(); void Run();
private: // This class is non copyable/movable.
// This class is non copyable. Loop(const Loop&) = default;
Loop(Loop&&) = delete;
Loop& operator=(Loop&&) = delete;
Loop(const ScreenInteractive&) = delete; Loop(const ScreenInteractive&) = delete;
Loop& operator=(const Loop&) = delete; Loop& operator=(const Loop&) = delete;
private:
ScreenInteractive* screen_; ScreenInteractive* screen_;
Component component_; Component component_;
}; };

View File

@ -54,6 +54,10 @@ template<class T> Receiver<T> MakeReceiver();
template <class T> template <class T>
class SenderImpl { class SenderImpl {
public: 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)); } void Send(T t) { receiver_->Receive(std::move(t)); }
~SenderImpl() { receiver_->ReleaseSender(); } ~SenderImpl() { receiver_->ReleaseSender(); }
@ -61,7 +65,7 @@ class SenderImpl {
private: private:
friend class ReceiverImpl<T>; friend class ReceiverImpl<T>;
SenderImpl(ReceiverImpl<T>* consumer) : receiver_(consumer) {} explicit SenderImpl(ReceiverImpl<T>* consumer) : receiver_(consumer) {}
ReceiverImpl<T>* receiver_; ReceiverImpl<T>* receiver_;
}; };
@ -73,15 +77,17 @@ class ReceiverImpl {
senders_++; senders_++;
return std::unique_ptr<SenderImpl<T>>(new SenderImpl<T>(this)); return std::unique_ptr<SenderImpl<T>>(new SenderImpl<T>(this));
} }
ReceiverImpl() { senders_ = 0; } ReceiverImpl() = default;
bool Receive(T* t) { bool Receive(T* t) {
while (senders_ || !queue_.empty()) { while (senders_ || !queue_.empty()) {
std::unique_lock<std::mutex> lock(mutex_); std::unique_lock<std::mutex> lock(mutex_);
if (queue_.empty()) if (queue_.empty()) {
notifier_.wait(lock); notifier_.wait(lock);
if (queue_.empty()) }
if (queue_.empty()) {
continue; continue;
}
*t = std::move(queue_.front()); *t = std::move(queue_.front());
queue_.pop(); queue_.pop();
return true; return true;
@ -91,8 +97,9 @@ class ReceiverImpl {
bool ReceiveNonBlocking(T* t) { bool ReceiveNonBlocking(T* t) {
std::unique_lock<std::mutex> lock(mutex_); std::unique_lock<std::mutex> lock(mutex_);
if (queue_.empty()) if (queue_.empty()) {
return false; return false;
}
*t = queue_.front(); *t = queue_.front();
queue_.pop(); queue_.pop();
return true; return true;
@ -127,7 +134,7 @@ class ReceiverImpl {
std::mutex mutex_; std::mutex mutex_;
std::queue<T> queue_; std::queue<T> queue_;
std::condition_variable notifier_; std::condition_variable notifier_;
std::atomic<int> senders_; std::atomic<int> senders_{0};
}; };
template <class T> template <class T>

View File

@ -80,9 +80,7 @@ Decorator borderStyled(BorderStyle);
Decorator borderStyled(BorderStyle, Color); Decorator borderStyled(BorderStyle, Color);
Decorator borderStyled(Color); Decorator borderStyled(Color);
Decorator borderWith(const Pixel&); Decorator borderWith(const Pixel&);
Element window(Element title, Element window(Element title, Element content, BorderStyle border = ROUNDED);
Element content,
BorderStyle border = ROUNDED);
Element spinner(int charset_index, size_t image_index); Element spinner(int charset_index, size_t image_index);
Element paragraph(const std::string& text); Element paragraph(const std::string& text);
Element paragraphAlignLeft(const std::string& text); Element paragraphAlignLeft(const std::string& text);

View File

@ -22,7 +22,7 @@ using Elements = std::vector<Element>;
class Node { class Node {
public: public:
Node(); Node();
Node(Elements children); explicit Node(Elements children);
Node(const Node&) = delete; Node(const Node&) = delete;
Node(const Node&&) = delete; Node(const Node&&) = delete;
Node& operator=(const Node&) = delete; Node& operator=(const Node&) = delete;

View File

@ -37,8 +37,8 @@ class TableSelection;
class Table { class Table {
public: public:
Table(); Table();
Table(std::vector<std::vector<std::string>>); explicit Table(std::vector<std::vector<std::string>>);
Table(std::vector<std::vector<Element>>); explicit Table(std::vector<std::vector<Element>>);
TableSelection SelectAll(); TableSelection SelectAll();
TableSelection SelectCell(int column, int row); TableSelection SelectCell(int column, int row);
TableSelection SelectRow(int row_index); TableSelection SelectRow(int row_index);

View File

@ -5,6 +5,7 @@
#define FTXUI_DOM_TAKE_ANY_ARGS_HPP #define FTXUI_DOM_TAKE_ANY_ARGS_HPP
// IWYU pragma: private, include "ftxui/dom/elements.hpp" // IWYU pragma: private, include "ftxui/dom/elements.hpp"
#include <ftxui/dom/node.hpp>
#include <type_traits> #include <type_traits>
namespace ftxui { namespace ftxui {
@ -19,8 +20,9 @@ inline void Merge(Elements& container, Element element) {
template <> template <>
inline void Merge(Elements& container, Elements elements) { inline void Merge(Elements& container, Elements elements) {
for (auto& element : elements) for (auto& element : elements) {
container.push_back(std::move(element)); container.push_back(std::move(element));
}
} }
// Turn a set of arguments into a vector. // Turn a set of arguments into a vector.

View File

@ -24,10 +24,12 @@ class Color {
enum Palette16 : uint8_t; enum Palette16 : uint8_t;
enum Palette256 : uint8_t; enum Palette256 : uint8_t;
// NOLINTBEGIN
Color(); // Transparent. Color(); // Transparent.
Color(Palette1 index); // Transparent. Color(Palette1 index); // Transparent.
Color(Palette16 index); // Implicit conversion from index to Color. Color(Palette16 index); // Implicit conversion from index to Color.
Color(Palette256 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); Color(uint8_t red, uint8_t green, uint8_t blue);
static Color RGB(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); static Color HSV(uint8_t hue, uint8_t saturation, uint8_t value);

View File

@ -4,10 +4,10 @@
#ifndef FTXUI_SCREEN_STRING_HPP #ifndef FTXUI_SCREEN_STRING_HPP
#define FTXUI_SCREEN_STRING_HPP #define FTXUI_SCREEN_STRING_HPP
#include <stddef.h> // for size_t #include <cstddef> // for size_t
#include <cstdint> // for uint8_t #include <cstdint> // for uint8_t
#include <string> // for string, wstring, to_string #include <string> // for string, wstring, to_string
#include <vector> // for vector #include <vector> // for vector
namespace ftxui { namespace ftxui {
std::string to_string(const std::wstring& s); std::string to_string(const std::wstring& s);

View File

@ -16,6 +16,10 @@ class AutoReset {
: variable_(variable), previous_value_(std::move(*variable)) { : variable_(variable), previous_value_(std::move(*variable)) {
*variable_ = std::move(new_value); *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_); } ~AutoReset() { *variable_ = std::move(previous_value_); }
private: private:

View File

@ -15,10 +15,12 @@ template <typename T>
class ConstRef { class ConstRef {
public: public:
ConstRef() = default; 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<T>&) = default; ConstRef(const ConstRef<T>&) = default;
ConstRef(ConstRef<T>&&) = default; ConstRef(ConstRef<T>&&) noexcept = default;
ConstRef(T t) : variant_(std::move(t)) {} ~ConstRef() = default;
ConstRef(const T* t) : variant_(t) {}
// Make a "reseatable" reference // Make a "reseatable" reference
ConstRef<T>& operator=(const ConstRef<T>&) = default; ConstRef<T>& operator=(const ConstRef<T>&) = default;
@ -42,10 +44,12 @@ template <typename T>
class Ref { class Ref {
public: public:
Ref() = default; 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<T>&) = default; Ref(const Ref<T>&) = default;
Ref(Ref<T>&&) = default; Ref(Ref<T>&&) noexcept = default;
Ref(T t) : variant_(std::move(t)) {}
Ref(T* t) : variant_(t) {}
// Make a "reseatable" reference. // Make a "reseatable" reference.
Ref<T>& operator=(const Ref<T>&) = default; Ref<T>& operator=(const Ref<T>&) = default;
@ -77,8 +81,10 @@ class StringRef : public Ref<std::string> {
public: public:
using Ref<std::string>::Ref; using Ref<std::string>::Ref;
StringRef(const wchar_t* ref) : StringRef(to_string(std::wstring(ref))) {} StringRef(const wchar_t* ref) // NOLINT
StringRef(const char* ref) : StringRef(std::string(ref)) {} : 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 /// @brief An adapter. Own or reference a constant string. For convenience, this
@ -87,19 +93,27 @@ class ConstStringRef : public ConstRef<std::string> {
public: public:
using ConstRef<std::string>::ConstRef; using ConstRef<std::string>::ConstRef;
ConstStringRef(const std::wstring* ref) : ConstStringRef(to_string(*ref)) {} ConstStringRef(const std::wstring* ref) // NOLINT
ConstStringRef(const std::wstring ref) : ConstStringRef(to_string(ref)) {} : ConstStringRef(to_string(*ref)) {}
ConstStringRef(const wchar_t* ref) ConstStringRef(const std::wstring ref) // NOLINT
: ConstStringRef(to_string(ref)) {}
ConstStringRef(const wchar_t* ref) // NOLINT
: ConstStringRef(to_string(std::wstring(ref))) {} : 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. /// @brief An adapter. Reference a list of strings.
class ConstStringListRef { class ConstStringListRef {
public: public:
ConstStringListRef() = default; ConstStringListRef() = default;
ConstStringListRef(const std::vector<std::string>* ref) : ref_(ref) {} ~ConstStringListRef() = default;
ConstStringListRef(const std::vector<std::wstring>* ref) : ref_wide_(ref) {} ConstStringListRef(ConstStringListRef&&) = delete;
ConstStringListRef& operator=(ConstStringListRef&&) = delete;
ConstStringListRef(const std::vector<std::string>* ref) // NOLINT
: ref_(ref) {}
ConstStringListRef(const std::vector<std::wstring>* ref) // NOLINT
: ref_wide_(ref) {}
ConstStringListRef(const ConstStringListRef& other) = default; ConstStringListRef(const ConstStringListRef& other) = default;
ConstStringListRef& operator=(const ConstStringListRef& other) = default; ConstStringListRef& operator=(const ConstStringListRef& other) = default;

View File

@ -11,8 +11,9 @@ using namespace ftxui;
namespace { namespace {
bool GeneratorBool(const char*& data, size_t& size) { bool GeneratorBool(const char*& data, size_t& size) {
if (size == 0) if (size == 0) {
return false; return false;
}
auto out = bool(data[0] % 2); auto out = bool(data[0] % 2);
data++; data++;

View File

@ -6,8 +6,7 @@
#include <vector> #include <vector>
namespace ftxui { namespace ftxui::box_helper {
namespace box_helper {
struct Element { struct Element {
// Input: // Input:
@ -21,7 +20,6 @@ struct Element {
void Compute(std::vector<Element>* elements, int target_size); void Compute(std::vector<Element>* elements, int target_size);
} // namespace box_helper } // namespace ftxui::box_helper
} // namespace ftxui
#endif /* end of include guard: FTXUI_DOM_BOX_HELPER_HPP */ #endif /* end of include guard: FTXUI_DOM_BOX_HELPER_HPP */

View File

@ -7,8 +7,7 @@
#include <vector> #include <vector>
#include "ftxui/dom/flexbox_config.hpp" #include "ftxui/dom/flexbox_config.hpp"
namespace ftxui { namespace ftxui::flexbox_helper {
namespace flexbox_helper {
struct Block { struct Block {
// Input: // Input:
@ -38,7 +37,6 @@ struct Global {
void Compute(Global& global); void Compute(Global& global);
} // namespace flexbox_helper } // namespace ftxui::flexbox_helper
} // namespace ftxui
#endif /* end of include guard: FTXUI_DOM_FLEXBOX_HELPER_HPP*/ #endif /* end of include guard: FTXUI_DOM_FLEXBOX_HELPER_HPP*/

View File

@ -15,7 +15,7 @@ struct Box;
// Helper class. // Helper class.
class NodeDecorator : public Node { class NodeDecorator : public Node {
public: public:
NodeDecorator(Element child) : Node(unpack(std::move(child))) {} explicit NodeDecorator(Element child) : Node(unpack(std::move(child))) {}
void ComputeRequirement() override; void ComputeRequirement() override;
void SetBox(Box box) override; void SetBox(Box box) override;
}; };

View File

@ -5,6 +5,8 @@
#define FTXUI_SCREEN_STRING_INTERNAL_HPP #define FTXUI_SCREEN_STRING_INTERNAL_HPP
#include <cstdint> #include <cstdint>
#include <string>
#include <vector>
namespace ftxui { namespace ftxui {

View File

@ -4,8 +4,7 @@
#ifndef FTXUI_SCREEN_UTIL_HPP #ifndef FTXUI_SCREEN_UTIL_HPP
#define FTXUI_SCREEN_UTIL_HPP #define FTXUI_SCREEN_UTIL_HPP
namespace ftxui { namespace ftxui::util {
namespace util {
// Similar to std::clamp, but allow hi to be lower than lo. // Similar to std::clamp, but allow hi to be lower than lo.
template <class T> template <class T>
@ -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; return v < lo ? lo : hi < v ? hi : v;
} }
} // namespace util } // namespace ftxui::util
} // namespace ftxui
#endif /* end of include guard: FTXUI_SCREEN_UTIL_HPP */ #endif /* end of include guard: FTXUI_SCREEN_UTIL_HPP */