Casting and documentation fixes (#608)

Add `-wDocumentation` option. Fix the documentation.
Fix c++20/c++17 confusion in tests.

Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
Marc 2023-03-31 17:13:48 +02:00 committed by GitHub
parent eed7e2ea70
commit 896c0f2f6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 96 additions and 82 deletions

View File

@ -1,5 +1,7 @@
---
Checks: "*,
-*-narrowing-conversions
-*-uppercase-literal-suffix,
-abseil-*,
-altera-*,
-android-*,
@ -7,7 +9,6 @@ Checks: "*,
-cppcoreguidelines-non-private-member-variables-in-classes,
-fuchsia-*,
-google-*,
-hicpp-uppercase-literal-suffix,
-llvm*,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
@ -19,7 +20,6 @@ Checks: "*,
-readability-implicit-bool-conversion,
-readability-non-const-parameter,
-readability-static-accessed-through-instance,
-readability-uppercase-literal-suffix,
-zircon-*,
"
WarningsAsErrors: ''

View File

@ -5,21 +5,18 @@ endif()
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
function(fuzz name)
function(fuzz source)
set(name "ftxui-${source}")
add_executable(${name}
src/ftxui/component/${name}.cpp
src/ftxui/component/${source}.cpp
)
target_include_directories(${name}
PRIVATE src
)
target_link_libraries(${name}
PRIVATE component
)
target_compile_options(${name}
PRIVATE -fsanitize=fuzzer,address
)
target_link_libraries(${name}
PRIVATE -fsanitize=fuzzer,address
target_include_directories(${name} PRIVATE src)
target_link_libraries(${name} PRIVATE component)
target_compile_options(${name} PRIVATE -fsanitize=fuzzer,address)
target_link_libraries(${name} PRIVATE -fsanitize=fuzzer,address)
set_target_properties(${name} PROPERTIES
CXX_STANDARD 20
CXX_EXTENSIONS OFF
)
endfunction(fuzz)

View File

@ -68,14 +68,25 @@ function(ftxui_set_options library)
target_compile_definitions(${library} PRIVATE UNICODE _UNICODE)
else()
target_compile_options(${library} PRIVATE "-Wall")
target_compile_options(${library} PRIVATE "-Wextra")
target_compile_options(${library} PRIVATE "-pedantic")
target_compile_options(${library} PRIVATE "-Werror")
target_compile_options(${library} PRIVATE "-Wmissing-declarations")
target_compile_options(${library} PRIVATE "-Wextra")
target_compile_options(${library} PRIVATE "-Wcast-align")
target_compile_options(${library} PRIVATE "-Wdeprecated")
target_compile_options(${library} PRIVATE "-Wmissing-declarations")
target_compile_options(${library} PRIVATE "-Wnon-virtual-dtor")
target_compile_options(${library} PRIVATE "-Wnull-dereference")
target_compile_options(${library} PRIVATE "-Woverloaded-virtual")
target_compile_options(${library} PRIVATE "-Wpedantic")
target_compile_options(${library} PRIVATE "-Wshadow")
target_compile_options(${library} PRIVATE "-Wunused")
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(${library} PRIVATE "-Wdocumentation")
endif()
if (FTXUI_MICROSOFT_TERMINAL_FALLBACK)
target_compile_definitions(${library}
PRIVATE "FTXUI_MICROSOFT_TERMINAL_FALLBACK")

View File

@ -57,8 +57,15 @@ target_link_libraries(ftxui-tests
target_include_directories(ftxui-tests
PRIVATE src
)
ftxui_set_options(ftxui-tests)
target_compile_features(ftxui-tests PUBLIC cxx_std_20)
set_target_properties(ftxui-tests PROPERTIES
CXX_STANDARD 20
CXX_EXTENSIONS OFF
)
if (FTXUI_MICROSOFT_TERMINAL_FALLBACK)
target_compile_definitions(ftxui-tests
PRIVATE "FTXUI_MICROSOFT_TERMINAL_FALLBACK")
endif()
include(GoogleTest)
gtest_discover_tests(ftxui-tests

View File

@ -9,7 +9,7 @@ function(example name)
file(RELATIVE_PATH dir ${EXAMPLES_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
set_property(GLOBAL APPEND PROPERTY FTXUI::EXAMPLES ${dir}/${name})
set_target_properties(ftxui_example_${name} PROPERTIES
CXX_STANDARD 20
CXX_STANDARD 17
)
endfunction(example)

View File

@ -110,7 +110,7 @@ bool ComponentBase::OnEvent(Event event) { // NOLINT
}
/// @brief Called in response to an animation event.
/// @param animation_params the parameters of the animation
/// @param params the parameters of the animation
/// The default implementation dispatch the event to every child.
/// @ingroup component
void ComponentBase::OnAnimation(animation::Params& params) {
@ -166,7 +166,7 @@ bool ComponentBase::Focused() const {
/// @brief Make the |child| to be the "active" one.
/// @param child the child to become active.
/// @ingroup component
void ComponentBase::SetActiveChild(ComponentBase* /*child*/) {}
void ComponentBase::SetActiveChild([[maybe_unused]] ComponentBase* child) {}
/// @brief Make the |child| to be the "active" one.
/// @param child the child to become active.
@ -187,7 +187,7 @@ void ComponentBase::TakeFocus() {
/// @brief Take the CapturedMouse if available. There is only one component of
/// them. It represents a component taking priority over others.
/// @param event
/// @param event The event
/// @ingroup component
CapturedMouse ComponentBase::CaptureMouse(const Event& event) { // NOLINT
if (event.screen_) {

View File

@ -96,8 +96,7 @@ MenuOption GeneratorMenuOption(const char* data, size_t size) {
MenuOption option;
option.underline = GeneratorUnderlineOption(data, size);
option.entries = GeneratorMenuEntryOption(data, size);
option.direction =
static_cast<MenuOption::Direction>(GeneratorInt(data, size) % 4);
option.direction = static_cast<Direction>(GeneratorInt(data, size) % 4);
return option;
}

View File

@ -39,7 +39,7 @@ Component Dropdown(ConstStringListRef entries, int* selected) {
}
Element Render() override {
*selected_ = util::clamp(*selected_, 0, (int)entries_.size() - 1);
*selected_ = util::clamp(*selected_, 0, int(entries_.size()) - 1);
title_ = entries_[static_cast<size_t>(*selected_)];
if (show_) {
const int max_height = 12;

View File

@ -26,8 +26,8 @@ void Post(std::function<void()> f) {
/// @brief Wrap a component. Gives the ability to know if it is hovered by the
/// mouse.
/// @param component: The wrapped component.
/// @param hover: The value to reflect whether the component is hovered or not.
/// @param component The wrapped component.
/// @param hover The value to reflect whether the component is hovered or not.
/// @ingroup component
///
/// ### Example
@ -68,10 +68,10 @@ Component Hoverable(Component component, bool* hover) {
return Make<Impl>(component, hover);
}
/// @brief Wrap a component. Gives the ability to know if it is hovered by the
/// mouse.
/// @param component: The wrapped component.
/// @param hover: The value to reflect whether the component is hovered or not.
/// @brief Wrap a component. Uses callbacks.
/// @param component The wrapped component.
/// @param on_enter Callback OnEnter
/// @param on_leave Callback OnLeave
/// @ingroup component
///
/// ### Example
@ -126,7 +126,7 @@ Component Hoverable(Component component,
/// @brief Wrap a component. Gives the ability to know if it is hovered by the
/// mouse.
/// @param hover: The value to reflect whether the component is hovered or not.
/// @param hover The value to reflect whether the component is hovered or not.
/// @ingroup component
///
/// ### Example

View File

@ -187,7 +187,7 @@ class InputBase : public ComponentBase {
}
if (event == Event::ArrowRight &&
cursor_position() < (int)content_->size()) {
cursor_position() < static_cast<int>(content_->size())) {
cursor_position()++;
return true;
}
@ -242,7 +242,7 @@ class InputBase : public ComponentBase {
void HandleRightCtrl() {
auto properties = Utf8ToWordBreakProperty(*content_);
const int max = (int)properties.size();
const int max = properties.size();
// Move right, as long as right is not a word character.
while (cursor_position() < max &&
@ -280,7 +280,7 @@ class InputBase : public ComponentBase {
size_t original_cell = 0;
for (size_t i = 0; i < mapping.size(); i++) {
if (mapping[i] == original_glyph) {
original_cell = (int)i;
original_cell = i;
break;
}
}
@ -289,8 +289,8 @@ class InputBase : public ComponentBase {
}
const int target_cell =
int(original_cell) + event.mouse().x - cursor_box_.x_min;
int target_glyph = target_cell < (int)mapping.size() ? mapping[target_cell]
: (int)mapping.size();
int target_glyph = target_cell < int(mapping.size()) ? mapping[target_cell]
: int(mapping.size());
target_glyph = util::clamp(target_glyph, 0, GlyphCount(*content_));
if (cursor_position() != target_glyph) {
cursor_position() = target_glyph;

View File

@ -356,7 +356,7 @@ class MenuBase : public ComponentBase {
}
void UpdateColorTarget() {
if (size() != (int)animation_background_.size()) {
if (size() != int(animation_background_.size())) {
animation_background_.resize(size());
animation_foreground_.resize(size());
animator_background_.clear();
@ -518,7 +518,7 @@ Component Menu(ConstStringListRef entries,
/// @brief An horizontal list of elements. The user can navigate through them.
/// @param entries The list of selectable entries to display.
/// @param selected Reference the selected entry.
/// @param See also |Menu|.
/// See also |Menu|.
/// @ingroup component
Component Toggle(ConstStringListRef entries, int* selected) {
return Menu(entries, selected, MenuOption::Toggle());

View File

@ -135,7 +135,7 @@ class ResizableSplitBase : public ComponentBase {
} // namespace
/// @brief A split in between two components.
/// @param options: all the parameters.
/// @param options all the parameters.
///
/// ### Example
///

View File

@ -309,7 +309,7 @@ Component Slider(ConstStringRef label,
}
/// @brief A slider in any direction.
/// @param option The options
/// @param options The options
/// ### Example
///
/// ```cpp

View File

@ -51,7 +51,7 @@ unsigned char TerminalInputParser::Current() {
bool TerminalInputParser::Eat() {
position_++;
return position_ < (int)pending_.size();
return position_ < static_cast<int>(pending_.size());
}
void TerminalInputParser::Send(TerminalInputParser::Output output) {

View File

@ -321,11 +321,11 @@ void Canvas::DrawPointEllipse(int x,
}
/// @brief Draw an ellipse made of braille dots.
/// @param x the x coordinate of the center of the ellipse.
/// @param y the y coordinate of the center of the ellipse.
/// @param x1 the x coordinate of the center of the ellipse.
/// @param y1 the y coordinate of the center of the ellipse.
/// @param r1 the radius of the ellipse along the x axis.
/// @param r2 the radius of the ellipse along the y axis.
/// @param style the style of the ellipse.
/// @param s the style of the ellipse.
void Canvas::DrawPointEllipse(int x1,
int y1,
int r1,
@ -361,8 +361,8 @@ void Canvas::DrawPointEllipse(int x1,
}
/// @brief Draw a filled ellipse made of braille dots.
/// @param x the x coordinate of the center of the ellipse.
/// @param y the y coordinate of the center of the ellipse.
/// @param x1 the x coordinate of the center of the ellipse.
/// @param y1 the y coordinate of the center of the ellipse.
/// @param r1 the radius of the ellipse along the x axis.
/// @param r2 the radius of the ellipse along the y axis.
void Canvas::DrawPointEllipseFilled(int x1, int y1, int r1, int r2) {
@ -370,8 +370,8 @@ void Canvas::DrawPointEllipseFilled(int x1, int y1, int r1, int r2) {
}
/// @brief Draw a filled ellipse made of braille dots.
/// @param x the x coordinate of the center of the ellipse.
/// @param y the y coordinate of the center of the ellipse.
/// @param x1 the x coordinate of the center of the ellipse.
/// @param y1 the y coordinate of the center of the ellipse.
/// @param r1 the radius of the ellipse along the x axis.
/// @param r2 the radius of the ellipse along the y axis.
/// @param color the color of the ellipse.
@ -385,11 +385,11 @@ void Canvas::DrawPointEllipseFilled(int x1,
}
/// @brief Draw a filled ellipse made of braille dots.
/// @param x the x coordinate of the center of the ellipse.
/// @param y the y coordinate of the center of the ellipse.
/// @param x1 the x coordinate of the center of the ellipse.
/// @param y1 the y coordinate of the center of the ellipse.
/// @param r1 the radius of the ellipse along the x axis.
/// @param r2 the radius of the ellipse along the y axis.
/// @param style the style of the ellipse.
/// @param s the style of the ellipse.
void Canvas::DrawPointEllipseFilled(int x1,
int y1,
int r1,
@ -410,11 +410,11 @@ void Canvas::DrawPointEllipseFilled(int x1,
e2 = 2 * err;
if (e2 >= dx) {
x++;
err += dx += 2 * (long)r2 * r2; // NOLINT
err += dx += 2 * r2 * r2;
}
if (e2 <= dy) {
y++;
err += dy += 2 * (long)r1 * r1; // NOLINT
err += dy += 2 * r1 * r1;
}
} while (x <= 0);
@ -631,7 +631,7 @@ void Canvas::DrawBlockCircleFilled(int x,
/// @param x the x coordinate of the center of the circle.
/// @param y the y coordinate of the center of the circle.
/// @param radius the radius of the circle.
/// @param style the style of the circle.
/// @param s the style of the circle.
void Canvas::DrawBlockCircleFilled(int x,
int y,
int radius,
@ -664,11 +664,11 @@ void Canvas::DrawBlockEllipse(int x,
}
/// @brief Draw an ellipse made of block characters.
/// @param x the x coordinate of the center of the ellipse.
/// @param y the y coordinate of the center of the ellipse.
/// @param x1 the x coordinate of the center of the ellipse.
/// @param y1 the y coordinate of the center of the ellipse.
/// @param r1 the radius of the ellipse along the x axis.
/// @param r2 the radius of the ellipse along the y axis.
/// @param style the style of the ellipse.
/// @param s the style of the ellipse.
void Canvas::DrawBlockEllipse(int x1,
int y1,
int r1,
@ -730,11 +730,11 @@ void Canvas::DrawBlockEllipseFilled(int x,
}
/// @brief Draw a filled ellipse made of block characters.
/// @param x the x coordinate of the center of the ellipse.
/// @param y the y coordinate of the center of the ellipse.
/// @param x1 the x coordinate of the center of the ellipse.
/// @param y1 the y coordinate of the center of the ellipse.
/// @param r1 the radius of the ellipse along the x axis.
/// @param r2 the radius of the ellipse along the y axis.
/// @param style the style of the ellipse.
/// @param s the style of the ellipse.
void Canvas::DrawBlockEllipseFilled(int x1,
int y1,
int r1,

View File

@ -328,8 +328,8 @@ void Compute3(Global& global) {
line = Line();
}
block.line = (int)lines.size();
block.line_position = (int)line.blocks.size();
block.line = lines.size();
block.line_position = line.blocks.size();
line.blocks.push_back(&block);
x += block.min_size_x + global.config.gap_x;
}

View File

@ -36,10 +36,10 @@ Decorator focusPositionRelative(float x, float y) {
requirement_.selection = Requirement::Selection::NORMAL;
Box& box = requirement_.selected_box;
box.x_min = (int)((float)requirement_.min_x * x_);
box.y_min = (int)((float)requirement_.min_y * y_);
box.x_max = (int)((float)requirement_.min_x * x_);
box.y_max = (int)((float)requirement_.min_y * y_);
box.x_min = int(float(requirement_.min_x) * x_);
box.y_min = int(float(requirement_.min_y) * y_);
box.x_max = int(float(requirement_.min_x) * x_);
box.y_max = int(float(requirement_.min_y) * y_);
}
private:

View File

@ -99,9 +99,9 @@ class Gauge : public Node {
// Draw the progress bar horizontally.
{
const float progress = invert ? 1.F - progress_ : progress_;
const float limit =
(float)box_.x_min + progress * (float)(box_.x_max - box_.x_min + 1);
const int limit_int = (int)limit;
const auto limit =
float(box_.x_min) + progress * float(box_.x_max - box_.x_min + 1);
const int limit_int = static_cast<int>(limit);
int x = box_.x_min;
while (x < limit_int) {
screen.at(x++, y) = charset_horizontal[9]; // NOLINT
@ -130,8 +130,8 @@ class Gauge : public Node {
{
const float progress = invert ? progress_ : 1.F - progress_;
const float limit =
(float)box_.y_min + progress * (float)(box_.y_max - box_.y_min + 1);
const int limit_int = (int)limit;
float(box_.y_min) + progress * float(box_.y_max - box_.y_min + 1);
const int limit_int = static_cast<int>(limit);
int y = box_.y_min;
while (y < limit_int) {
screen.at(x, y++) = charset_vertical[8]; // NOLINT

View File

@ -33,12 +33,12 @@ int Integrate(std::vector<int>& elements) {
class GridBox : public Node {
public:
explicit GridBox(std::vector<Elements> lines) : lines_(std::move(lines)) {
y_size = (int)lines_.size();
y_size = lines_.size();
for (const auto& line : lines_) {
x_size = std::max(x_size, (int)line.size());
x_size = std::max(x_size, int(line.size()));
}
for (auto& line : lines_) {
while (line.size() < (size_t)x_size) {
while (line.size() < size_t(x_size)) {
line.push_back(filler());
}
}

View File

@ -286,8 +286,8 @@ Element spinner(int charset_index, size_t image_index) {
}
return gauge(float(image_index) * 0.05F); // NOLINT
}
charset_index %= (int)elements.size();
image_index %= (int)elements[charset_index].size();
charset_index %= int(elements.size());
image_index %= int(elements[charset_index].size());
std::vector<Element> lines;
for (const auto& it : elements[charset_index][image_index]) {
lines.push_back(text(it));

View File

@ -59,10 +59,10 @@ Table::Table(std::vector<std::vector<Element>> input) {
}
void Table::Initialize(std::vector<std::vector<Element>> input) {
input_dim_y_ = (int)input.size();
input_dim_y_ = input.size();
input_dim_x_ = 0;
for (auto& row : input) {
input_dim_x_ = std::max(input_dim_x_, (int)row.size());
input_dim_x_ = std::max(input_dim_x_, int(row.size()));
}
dim_y_ = 2 * input_dim_y_ + 1;

View File

@ -73,7 +73,7 @@ Terminal::Color ComputeColorSupport() {
// colors: https://github.com/microsoft/terminal/issues/1040
// As a fallback, assume microsoft terminal are the ones not setting those
// variables, and enable true colors.
if (TERM == "" && COLORTERM == "") {
if (TERM.empty() && COLORTERM.empty()) {
return Terminal::Color::TrueColor;
}
#endif