Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Clang-tidy #918

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Checks: "*,
-readability-simplify-boolean-expr,
-readability-static-accessed-through-instance,
-readability-use-anyofallof,
-readability-avoid-nested-conditional-operator,
-zircon-*,
"
WarningsAsErrors: ''
Expand Down
4 changes: 2 additions & 2 deletions examples/component/homescreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ int main() {
},
&tab_index);

auto exit_button = Button(
"Exit", [&] { screen.Exit(); }, ButtonOption::Animated());
auto exit_button =
Button("Exit", [&] { screen.Exit(); }, ButtonOption::Animated());

auto main_container = Container::Vertical({
Container::Horizontal({
Expand Down
2 changes: 1 addition & 1 deletion include/ftxui/screen/pixel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ struct Pixel {

} // namespace ftxui

#endif // FTXUI_SCREEN_PIXEL_HPP
#endif // FTXUI_SCREEN_PIXEL_HPP
2 changes: 1 addition & 1 deletion src/ftxui/component/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Component Button(ButtonOption option) {
Component Button(ConstStringRef label,
std::function<void()> on_click,
ButtonOption option) {
option.label = label;
option.label = std::move(label);
option.on_click = std::move(on_click);
return Make<ButtonBase>(std::move(option));
}
Expand Down
2 changes: 1 addition & 1 deletion src/ftxui/component/collapsible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Component Collapsible(ConstStringRef label, Component child, Ref<bool> show) {
return hbox({prefix, t});
};
Add(Container::Vertical({
Checkbox(label, show_.operator->(), opt),
Checkbox(std::move(label), show_.operator->(), opt),
Maybe(std::move(child), show_.operator->()),
}));
}
Expand Down
1 change: 1 addition & 0 deletions src/ftxui/component/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <cassert> // for assert
#include <cstddef> // for size_t
#include <iterator> // for begin, end
#include <memory> // for unique_ptr, make_unique
#include <utility> // for move
#include <vector> // for vector, __alloc_traits<>::value_type

Expand Down
3 changes: 1 addition & 2 deletions src/ftxui/component/component_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
// the LICENSE file.
#include "ftxui/component/component_options.hpp"

#include <ftxui/dom/linear_gradient.hpp> // for LinearGradient
#include <ftxui/screen/color.hpp> // for Color, Color::White, Color::Black, Color::GrayDark, Color::Blue, Color::GrayLight, Color::Red
#include <memory> // for shared_ptr
#include <utility> // for move

#include "ftxui/component/animation.hpp" // for Function, Duration
#include "ftxui/dom/direction.hpp"
#include "ftxui/dom/elements.hpp" // for operator|=, Element, text, bgcolor, inverted, bold, dim, operator|, color, borderEmpty, hbox, automerge, border, borderLight

namespace ftxui {
Expand Down
5 changes: 3 additions & 2 deletions src/ftxui/component/dropdown.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2021 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#include <cstddef> // for size_t
#include <ftxui/component/event.hpp>
#include <functional> // for function
#include <string> // for string

#include <utility>
#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
Expand All @@ -21,14 +21,15 @@ namespace ftxui {
/// @param selected The index of the selected entry.
Component Dropdown(ConstStringListRef entries, int* selected) {
DropdownOption option;
option.radiobox.entries = entries;
option.radiobox.entries = std::move(entries);
option.radiobox.selected = selected;
return Dropdown(option);
}

/// @brief A dropdown menu.
/// @ingroup component
/// @param option The options for the dropdown.
// NOLINTNEXTLINE
Component Dropdown(DropdownOption option) {
class Impl : public ComponentBase, public DropdownOption {
public:
Expand Down
3 changes: 2 additions & 1 deletion src/ftxui/component/event.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// 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.
#include <map> // for map
#include <map> // for map
#include <string>
#include <utility> // for move

#include "ftxui/component/event.hpp"
Expand Down
5 changes: 2 additions & 3 deletions src/ftxui/component/hoverable.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#include <ftxui/component/captured_mouse.hpp> // for CapturedMouse
#include <functional> // for function
#include <utility> // for move
#include <functional> // for function
#include <utility> // for move

#include "ftxui/component/component.hpp" // for ComponentDecorator, Hoverable, Make
#include "ftxui/component/component_base.hpp" // for ComponentBase
Expand Down
8 changes: 4 additions & 4 deletions src/ftxui/component/hoverable_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ TEST(HoverableTest, BasicCallback) {
int on_enter_2 = 0;
int on_leave_1 = 0;
int on_leave_2 = 0;
auto c1 = Hoverable(
BasicComponent(), [&] { on_enter_1++; }, [&] { on_leave_1++; });
auto c2 = Hoverable(
BasicComponent(), [&] { on_enter_2++; }, [&] { on_leave_2++; });
auto c1 =
Hoverable(BasicComponent(), [&] { on_enter_1++; }, [&] { on_leave_1++; });
auto c2 =
Hoverable(BasicComponent(), [&] { on_enter_2++; }, [&] { on_leave_2++; });
auto layout = Container::Horizontal({c1, c2});
auto screen = Screen(8, 2);
Render(screen, layout->Render());
Expand Down
69 changes: 38 additions & 31 deletions src/ftxui/component/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
#include <cstddef> // for size_t
#include <cstdint> // for uint32_t
#include <functional> // for function
#include <memory> // for allocator, shared_ptr, allocator_traits<>::value_type
#include <sstream> // for basic_istream, stringstream
#include <string> // for string, basic_string, operator==, getline
#include <utility> // for move
#include <vector> // for vector
#include <sstream> // for basic_istream, stringstream
#include <string> // for string, basic_string, operator==, getline
#include <utility> // for move
#include <vector> // for vector

#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
#include "ftxui/component/component.hpp" // for Make, Input
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/component_options.hpp" // for InputOption
Expand Down Expand Up @@ -134,7 +132,7 @@ class InputBase : public ComponentBase, public InputOption {
break;
}

cursor_char_index -= line.size() + 1;
cursor_char_index -= static_cast<int>(line.size() + 1);
cursor_line++;
}

Expand Down Expand Up @@ -164,7 +162,7 @@ class InputBase : public ComponentBase, public InputOption {

// The cursor is on this line.
const int glyph_start = cursor_char_index;
const int glyph_end = GlyphNext(line, glyph_start);
const int glyph_end = static_cast<int>(GlyphNext(line, glyph_start));
const std::string part_before_cursor = line.substr(0, glyph_start);
const std::string part_at_cursor =
line.substr(glyph_start, glyph_end - glyph_start);
Expand Down Expand Up @@ -206,7 +204,7 @@ class InputBase : public ComponentBase, public InputOption {
const size_t start = GlyphPrevious(content(), cursor_position());
const size_t end = cursor_position();
content->erase(start, end - start);
cursor_position() = start;
cursor_position() = static_cast<int>(start);
on_change();
return true;
}
Expand Down Expand Up @@ -234,7 +232,8 @@ class InputBase : public ComponentBase, public InputOption {
return false;
}

cursor_position() = GlyphPrevious(content(), cursor_position());
cursor_position() =
static_cast<int>(GlyphPrevious(content(), cursor_position()));
return true;
}

Expand All @@ -243,7 +242,8 @@ class InputBase : public ComponentBase, public InputOption {
return false;
}

cursor_position() = GlyphNext(content(), cursor_position());
cursor_position() =
static_cast<int>(GlyphNext(content(), cursor_position()));
return true;
}

Expand All @@ -258,7 +258,7 @@ class InputBase : public ComponentBase, public InputOption {
if (content()[iter] == '\n') {
break;
}
width += GlyphWidth(content(), iter);
width += static_cast<int>(GlyphWidth(content(), iter));
}
return width;
}
Expand All @@ -271,8 +271,9 @@ class InputBase : public ComponentBase, public InputOption {
return;
}

columns -= GlyphWidth(content(), cursor_position());
cursor_position() = GlyphNext(content(), cursor_position());
columns -= static_cast<int>(GlyphWidth(content(), cursor_position()));
cursor_position() =
static_cast<int>(GlyphNext(content(), cursor_position()));
}
}

Expand All @@ -292,9 +293,10 @@ class InputBase : public ComponentBase, public InputOption {
if (content()[previous] == '\n') {
break;
}
cursor_position() = previous;
cursor_position() = static_cast<int>(previous);
}
cursor_position() = GlyphPrevious(content(), cursor_position());
cursor_position() =
static_cast<int>(GlyphPrevious(content(), cursor_position()));
while (true) {
if (cursor_position() == 0) {
break;
Expand All @@ -303,10 +305,10 @@ class InputBase : public ComponentBase, public InputOption {
if (content()[previous] == '\n') {
break;
}
cursor_position() = previous;
cursor_position() = static_cast<int>(previous);
}

MoveCursorColumn(columns);
MoveCursorColumn(static_cast<int>(columns));
return true;
}

Expand All @@ -322,14 +324,16 @@ class InputBase : public ComponentBase, public InputOption {
if (content()[cursor_position()] == '\n') {
break;
}
cursor_position() = GlyphNext(content(), cursor_position());
cursor_position() =
static_cast<int>(GlyphNext(content(), cursor_position()));
if (cursor_position() == (int)content().size()) {
return true;
}
}
cursor_position() = GlyphNext(content(), cursor_position());
cursor_position() =
static_cast<int>(GlyphNext(content(), cursor_position()));

MoveCursorColumn(columns);
MoveCursorColumn(static_cast<int>(columns));
return true;
}

Expand All @@ -339,7 +343,7 @@ class InputBase : public ComponentBase, public InputOption {
}

bool HandleEnd() {
cursor_position() = content->size();
cursor_position() = static_cast<int>(content->size());
return true;
}

Expand All @@ -357,7 +361,7 @@ class InputBase : public ComponentBase, public InputOption {
DeleteImpl();
}
content->insert(cursor_position(), character);
cursor_position() += character.size();
cursor_position() += static_cast<int>(character.size());
on_change();
return true;
}
Expand Down Expand Up @@ -421,15 +425,15 @@ class InputBase : public ComponentBase, public InputOption {
if (IsWordCharacter(content(), previous)) {
break;
}
cursor_position() = previous;
cursor_position() = static_cast<int>(previous);
}
// Move left, as long as left is a word character:
while (cursor_position()) {
const size_t previous = GlyphPrevious(content(), cursor_position());
if (!IsWordCharacter(content(), previous)) {
break;
}
cursor_position() = previous;
cursor_position() = static_cast<int>(previous);
}
return true;
}
Expand All @@ -441,7 +445,8 @@ class InputBase : public ComponentBase, public InputOption {

// Move right, until entering a word.
while (cursor_position() < (int)content().size()) {
cursor_position() = GlyphNext(content(), cursor_position());
cursor_position() =
static_cast<int>(GlyphNext(content(), cursor_position()));
if (IsWordCharacter(content(), cursor_position())) {
break;
}
Expand All @@ -452,7 +457,7 @@ class InputBase : public ComponentBase, public InputOption {
if (!IsWordCharacter(content(), cursor_position())) {
break;
}
cursor_position() = next;
cursor_position() = static_cast<int>(next);
}

return true;
Expand Down Expand Up @@ -489,7 +494,7 @@ class InputBase : public ComponentBase, public InputOption {
break;
}

cursor_char_index -= line.size() + 1;
cursor_char_index -= static_cast<int>(line.size() + 1);
cursor_line++;
}
const int cursor_column =
Expand All @@ -515,11 +520,13 @@ class InputBase : public ComponentBase, public InputOption {
// Convert back the new_cursor_{line,column} toward cursor_position:
cursor_position() = 0;
for (int i = 0; i < new_cursor_line; ++i) {
cursor_position() += lines[i].size() + 1;
cursor_position() += static_cast<int>(lines[i].size() + 1);
}
while (new_cursor_column > 0) {
new_cursor_column -= GlyphWidth(content(), cursor_position());
cursor_position() = GlyphNext(content(), cursor_position());
new_cursor_column -=
static_cast<int>(GlyphWidth(content(), cursor_position()));
cursor_position() =
static_cast<int>(GlyphNext(content(), cursor_position()));
}

on_change();
Expand Down
5 changes: 3 additions & 2 deletions src/ftxui/component/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ class MenuBase : public ComponentBase, public MenuOption {
/// entry 2
/// entry 3
/// ```
// NOLINTNEXTLINE
Component Menu(MenuOption option) {
return Make<MenuBase>(std::move(option));
}
Expand Down Expand Up @@ -543,7 +544,7 @@ Component Menu(MenuOption option) {
/// entry 3
/// ```
Component Menu(ConstStringListRef entries, int* selected, MenuOption option) {
option.entries = entries;
option.entries = std::move(entries);
option.selected = selected;
return Menu(option);
}
Expand All @@ -554,7 +555,7 @@ Component Menu(ConstStringListRef entries, int* selected, MenuOption option) {
/// See also |Menu|.
/// @ingroup component
Component Toggle(ConstStringListRef entries, int* selected) {
return Menu(entries, selected, MenuOption::Toggle());
return Menu(std::move(entries), selected, MenuOption::Toggle());
}

/// @brief A specific menu entry. They can be put into a Container::Vertical to
Expand Down
3 changes: 2 additions & 1 deletion src/ftxui/component/radiobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class RadioboxBase : public ComponentBase, public RadioboxOption {
/// ○ entry 2
/// ○ entry 3
/// ```
/// NOLINTNEXTLINE
Component Radiobox(RadioboxOption option) {
return Make<RadioboxBase>(std::move(option));
}
Expand Down Expand Up @@ -239,7 +240,7 @@ Component Radiobox(RadioboxOption option) {
Component Radiobox(ConstStringListRef entries,
int* selected,
RadioboxOption option) {
option.entries = entries;
option.entries = std::move(entries);
option.selected = selected;
return Make<RadioboxBase>(std::move(option));
}
Expand Down
Loading
Loading