diff --git a/.clang-tidy b/.clang-tidy index 130bda720..f5335f087 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -27,6 +27,7 @@ Checks: "*, -readability-simplify-boolean-expr, -readability-static-accessed-through-instance, -readability-use-anyofallof, + -readability-avoid-nested-conditional-operator, -zircon-*, " WarningsAsErrors: '' diff --git a/examples/component/homescreen.cpp b/examples/component/homescreen.cpp index de0b8cd6a..d650ba2e4 100644 --- a/examples/component/homescreen.cpp +++ b/examples/component/homescreen.cpp @@ -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({ diff --git a/include/ftxui/screen/pixel.hpp b/include/ftxui/screen/pixel.hpp index 8ab686b02..cbc7cc23a 100644 --- a/include/ftxui/screen/pixel.hpp +++ b/include/ftxui/screen/pixel.hpp @@ -49,4 +49,4 @@ struct Pixel { } // namespace ftxui -#endif // FTXUI_SCREEN_PIXEL_HPP +#endif // FTXUI_SCREEN_PIXEL_HPP diff --git a/src/ftxui/component/button.cpp b/src/ftxui/component/button.cpp index 03c7f4a03..e2be2afc1 100644 --- a/src/ftxui/component/button.cpp +++ b/src/ftxui/component/button.cpp @@ -205,7 +205,7 @@ Component Button(ButtonOption option) { Component Button(ConstStringRef label, std::function on_click, ButtonOption option) { - option.label = label; + option.label = std::move(label); option.on_click = std::move(on_click); return Make(std::move(option)); } diff --git a/src/ftxui/component/collapsible.cpp b/src/ftxui/component/collapsible.cpp index 380ead2f3..a79c85506 100644 --- a/src/ftxui/component/collapsible.cpp +++ b/src/ftxui/component/collapsible.cpp @@ -47,7 +47,7 @@ Component Collapsible(ConstStringRef label, Component child, Ref 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->()), })); } diff --git a/src/ftxui/component/component.cpp b/src/ftxui/component/component.cpp index 47d882511..6ed4cb267 100644 --- a/src/ftxui/component/component.cpp +++ b/src/ftxui/component/component.cpp @@ -5,6 +5,7 @@ #include // for assert #include // for size_t #include // for begin, end +#include // for unique_ptr, make_unique #include // for move #include // for vector, __alloc_traits<>::value_type diff --git a/src/ftxui/component/component_options.cpp b/src/ftxui/component/component_options.cpp index b89e65b4f..77b439f36 100644 --- a/src/ftxui/component/component_options.cpp +++ b/src/ftxui/component/component_options.cpp @@ -3,12 +3,11 @@ // the LICENSE file. #include "ftxui/component/component_options.hpp" -#include // for LinearGradient #include // for Color, Color::White, Color::Black, Color::GrayDark, Color::Blue, Color::GrayLight, Color::Red #include // for shared_ptr #include // 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 { diff --git a/src/ftxui/component/dropdown.cpp b/src/ftxui/component/dropdown.cpp index 28212829e..b268dd9f3 100644 --- a/src/ftxui/component/dropdown.cpp +++ b/src/ftxui/component/dropdown.cpp @@ -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 // for size_t #include #include // for function #include // for string +#include #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 @@ -21,7 +21,7 @@ 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); } @@ -29,6 +29,7 @@ Component Dropdown(ConstStringListRef entries, int* selected) { /// @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: diff --git a/src/ftxui/component/event.cpp b/src/ftxui/component/event.cpp index 5e663c903..25a505754 100644 --- a/src/ftxui/component/event.cpp +++ b/src/ftxui/component/event.cpp @@ -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 // for map +#include // for map +#include #include // for move #include "ftxui/component/event.hpp" diff --git a/src/ftxui/component/hoverable.cpp b/src/ftxui/component/hoverable.cpp index 304ebc172..85c8e0f2c 100644 --- a/src/ftxui/component/hoverable.cpp +++ b/src/ftxui/component/hoverable.cpp @@ -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 // for CapturedMouse -#include // for function -#include // for move +#include // for function +#include // for move #include "ftxui/component/component.hpp" // for ComponentDecorator, Hoverable, Make #include "ftxui/component/component_base.hpp" // for ComponentBase diff --git a/src/ftxui/component/hoverable_test.cpp b/src/ftxui/component/hoverable_test.cpp index e7ac66c7b..695b90a02 100644 --- a/src/ftxui/component/hoverable_test.cpp +++ b/src/ftxui/component/hoverable_test.cpp @@ -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()); diff --git a/src/ftxui/component/input.cpp b/src/ftxui/component/input.cpp index b0cf92d13..8f5d728c7 100644 --- a/src/ftxui/component/input.cpp +++ b/src/ftxui/component/input.cpp @@ -5,13 +5,11 @@ #include // for size_t #include // for uint32_t #include // for function -#include // for allocator, shared_ptr, allocator_traits<>::value_type -#include // for basic_istream, stringstream -#include // for string, basic_string, operator==, getline -#include // for move -#include // for vector +#include // for basic_istream, stringstream +#include // for string, basic_string, operator==, getline +#include // for move +#include // 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 @@ -134,7 +132,7 @@ class InputBase : public ComponentBase, public InputOption { break; } - cursor_char_index -= line.size() + 1; + cursor_char_index -= static_cast(line.size() + 1); cursor_line++; } @@ -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(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); @@ -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(start); on_change(); return true; } @@ -234,7 +232,8 @@ class InputBase : public ComponentBase, public InputOption { return false; } - cursor_position() = GlyphPrevious(content(), cursor_position()); + cursor_position() = + static_cast(GlyphPrevious(content(), cursor_position())); return true; } @@ -243,7 +242,8 @@ class InputBase : public ComponentBase, public InputOption { return false; } - cursor_position() = GlyphNext(content(), cursor_position()); + cursor_position() = + static_cast(GlyphNext(content(), cursor_position())); return true; } @@ -258,7 +258,7 @@ class InputBase : public ComponentBase, public InputOption { if (content()[iter] == '\n') { break; } - width += GlyphWidth(content(), iter); + width += static_cast(GlyphWidth(content(), iter)); } return width; } @@ -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(GlyphWidth(content(), cursor_position())); + cursor_position() = + static_cast(GlyphNext(content(), cursor_position())); } } @@ -292,9 +293,10 @@ class InputBase : public ComponentBase, public InputOption { if (content()[previous] == '\n') { break; } - cursor_position() = previous; + cursor_position() = static_cast(previous); } - cursor_position() = GlyphPrevious(content(), cursor_position()); + cursor_position() = + static_cast(GlyphPrevious(content(), cursor_position())); while (true) { if (cursor_position() == 0) { break; @@ -303,10 +305,10 @@ class InputBase : public ComponentBase, public InputOption { if (content()[previous] == '\n') { break; } - cursor_position() = previous; + cursor_position() = static_cast(previous); } - MoveCursorColumn(columns); + MoveCursorColumn(static_cast(columns)); return true; } @@ -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(GlyphNext(content(), cursor_position())); if (cursor_position() == (int)content().size()) { return true; } } - cursor_position() = GlyphNext(content(), cursor_position()); + cursor_position() = + static_cast(GlyphNext(content(), cursor_position())); - MoveCursorColumn(columns); + MoveCursorColumn(static_cast(columns)); return true; } @@ -339,7 +343,7 @@ class InputBase : public ComponentBase, public InputOption { } bool HandleEnd() { - cursor_position() = content->size(); + cursor_position() = static_cast(content->size()); return true; } @@ -357,7 +361,7 @@ class InputBase : public ComponentBase, public InputOption { DeleteImpl(); } content->insert(cursor_position(), character); - cursor_position() += character.size(); + cursor_position() += static_cast(character.size()); on_change(); return true; } @@ -421,7 +425,7 @@ class InputBase : public ComponentBase, public InputOption { if (IsWordCharacter(content(), previous)) { break; } - cursor_position() = previous; + cursor_position() = static_cast(previous); } // Move left, as long as left is a word character: while (cursor_position()) { @@ -429,7 +433,7 @@ class InputBase : public ComponentBase, public InputOption { if (!IsWordCharacter(content(), previous)) { break; } - cursor_position() = previous; + cursor_position() = static_cast(previous); } return true; } @@ -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(GlyphNext(content(), cursor_position())); if (IsWordCharacter(content(), cursor_position())) { break; } @@ -452,7 +457,7 @@ class InputBase : public ComponentBase, public InputOption { if (!IsWordCharacter(content(), cursor_position())) { break; } - cursor_position() = next; + cursor_position() = static_cast(next); } return true; @@ -489,7 +494,7 @@ class InputBase : public ComponentBase, public InputOption { break; } - cursor_char_index -= line.size() + 1; + cursor_char_index -= static_cast(line.size() + 1); cursor_line++; } const int cursor_column = @@ -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(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(GlyphWidth(content(), cursor_position())); + cursor_position() = + static_cast(GlyphNext(content(), cursor_position())); } on_change(); diff --git a/src/ftxui/component/menu.cpp b/src/ftxui/component/menu.cpp index 4de8ec818..4fc4d0b91 100644 --- a/src/ftxui/component/menu.cpp +++ b/src/ftxui/component/menu.cpp @@ -511,6 +511,7 @@ class MenuBase : public ComponentBase, public MenuOption { /// entry 2 /// entry 3 /// ``` +// NOLINTNEXTLINE Component Menu(MenuOption option) { return Make(std::move(option)); } @@ -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); } @@ -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 diff --git a/src/ftxui/component/radiobox.cpp b/src/ftxui/component/radiobox.cpp index 41f29b30d..bb775000f 100644 --- a/src/ftxui/component/radiobox.cpp +++ b/src/ftxui/component/radiobox.cpp @@ -204,6 +204,7 @@ class RadioboxBase : public ComponentBase, public RadioboxOption { /// ○ entry 2 /// ○ entry 3 /// ``` +/// NOLINTNEXTLINE Component Radiobox(RadioboxOption option) { return Make(std::move(option)); } @@ -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(std::move(option)); } diff --git a/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp index 997f690ab..ead776bd1 100644 --- a/src/ftxui/component/screen_interactive.cpp +++ b/src/ftxui/component/screen_interactive.cpp @@ -1,34 +1,38 @@ // 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 "ftxui/component/screen_interactive.hpp" #include // for copy, max, min #include // for array +#include #include // for operator-, milliseconds, operator>=, duration, common_type<>::type, time_point #include // for signal, SIGTSTP, SIGABRT, SIGWINCH, raise, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM, __sighandler_t, size_t -#include // for fileno, stdin +#include +#include // for fileno, stdin #include // for Task, Closure, AnimationTask #include // for Pixel, Screen::Cursor, Screen, Screen::Cursor::Hidden #include // for function #include // for initializer_list #include // for cout, ostream, operator<<, basic_ostream, endl, flush -#include // for stack -#include // for thread, sleep_for -#include // for _Swallow_assign, ignore +#include +#include // for stack +#include +#include // for thread, sleep_for +#include // for _Swallow_assign, ignore #include // for decay_t #include // for move, swap #include // for visit, variant #include // for vector - #include "ftxui/component/animation.hpp" // for TimePoint, Clock, Duration, Params, RequestAnimationFrame #include "ftxui/component/captured_mouse.hpp" // for CapturedMouse, CapturedMouseInterface #include "ftxui/component/component_base.hpp" // for ComponentBase #include "ftxui/component/event.hpp" // for Event #include "ftxui/component/loop.hpp" // for Loop #include "ftxui/component/receiver.hpp" // for ReceiverImpl, Sender, MakeReceiver, SenderImpl, Receiver -#include "ftxui/component/screen_interactive.hpp" #include "ftxui/component/terminal_input_parser.hpp" // for TerminalInputParser #include "ftxui/dom/node.hpp" // for Node, Render #include "ftxui/dom/requirement.hpp" // for Requirement +#include "ftxui/screen/pixel.hpp" // for Pixel #include "ftxui/screen/terminal.hpp" // for Dimensions, Size #if defined(_WIN32) @@ -42,6 +46,7 @@ #error Must be compiled in UNICODE mode #endif #else +#include #include // for select, FD_ISSET, FD_SET, FD_ZERO, fd_set, timeval #include // for tcsetattr, termios, tcgetattr, TCSANOW, cc_t, ECHO, ICANON, VMIN, VTIME #include // for STDIN_FILENO, read @@ -213,11 +218,11 @@ void RecordSignal(int signal) { break; #if !defined(_WIN32) - case SIGTSTP: + case SIGTSTP: // NOLINT g_signal_stop_count++; break; - case SIGWINCH: + case SIGWINCH: // NOLINT g_signal_resize_count++; break; #endif @@ -265,7 +270,7 @@ const std::string ST = "\x1b\\"; // NOLINT const std::string DECRQSS_DECSCUSR = DCS + "$q q" + ST; // NOLINT // DEC: Digital Equipment Corporation -enum class DECMode { +enum class DECMode : std::uint16_t { kLineWrap = 7, kCursor = 25, @@ -284,7 +289,7 @@ enum class DECMode { }; // Device Status Report (DSR) { -enum class DSRMode { +enum class DSRMode : std::uint8_t { kCursor = 6, }; @@ -543,7 +548,8 @@ void ScreenInteractive::PostMain() { // On final exit, keep the current drawing and reset cursor position one // line after it. if (!use_alternative_screen_) { - std::cout << std::endl; + std::cout << '\n'; + std::cout << std::flush; } } } @@ -597,7 +603,7 @@ void ScreenInteractive::Install() { // Request the terminal to report the current cursor shape. We will restore it // on exit. std::cout << DECRQSS_DECSCUSR; - on_exit_functions.emplace([=] { + on_exit_functions.emplace([cursor_reset_shape_ = cursor_reset_shape_] { std::cout << "\033[?25h"; // Enable cursor. std::cout << "\033[" + std::to_string(cursor_reset_shape_) + " q"; }); diff --git a/src/ftxui/component/terminal_input_parser.cpp b/src/ftxui/component/terminal_input_parser.cpp index f07afa977..2100d9edd 100644 --- a/src/ftxui/component/terminal_input_parser.cpp +++ b/src/ftxui/component/terminal_input_parser.cpp @@ -9,7 +9,7 @@ #include #include // for unique_ptr, allocator #include // for move - +#include #include "ftxui/component/event.hpp" // for Event #include "ftxui/component/task.hpp" // for Task diff --git a/src/ftxui/component/window.cpp b/src/ftxui/component/window.cpp index b2b96cebf..4f8e44e55 100644 --- a/src/ftxui/component/window.cpp +++ b/src/ftxui/component/window.cpp @@ -5,8 +5,14 @@ #include #include #include +#include #include // for ScreenInteractive -#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator +#include +#include +#include "ftxui/dom/elements.hpp" // for text, window, hbox, vbox, size, clear_under, reflect, emptyElement +#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator +#include "ftxui/screen/color.hpp" // for Color +#include "ftxui/screen/screen.hpp" // for Screen namespace ftxui { @@ -206,7 +212,7 @@ class WindowImpl : public ComponentBase, public WindowOptions { } // Clamp the window size. - width() = std::max(width(), title().size() + 2); + width() = std::max(width(), static_cast(title().size() + 2)); height() = std::max(height(), 2); return true; diff --git a/src/ftxui/dom/benchmark_test.cpp b/src/ftxui/dom/benchmark_test.cpp index fa90b8cde..062cb2349 100644 --- a/src/ftxui/dom/benchmark_test.cpp +++ b/src/ftxui/dom/benchmark_test.cpp @@ -2,7 +2,6 @@ // Use of this source code is governed by the MIT license that can be found in // the LICENSE file. #include -#include #include "ftxui/dom/elements.hpp" // for gauge, separator, operator|, text, Element, hbox, vbox, blink, border, inverted #include "ftxui/dom/node.hpp" // for Render diff --git a/src/ftxui/dom/border.cpp b/src/ftxui/dom/border.cpp index 5616a5603..b67569803 100644 --- a/src/ftxui/dom/border.cpp +++ b/src/ftxui/dom/border.cpp @@ -8,12 +8,12 @@ #include // for optional, nullopt #include // for basic_string, string #include // for move -#include // for __alloc_traits<>::value_type #include "ftxui/dom/elements.hpp" // for unpack, Element, Decorator, BorderStyle, ROUNDED, borderStyled, Elements, DASHED, DOUBLE, EMPTY, HEAVY, LIGHT, border, borderDashed, borderDouble, borderEmpty, borderHeavy, borderLight, borderRounded, borderWith, window #include "ftxui/dom/node.hpp" // for Node, Elements #include "ftxui/dom/requirement.hpp" // for Requirement #include "ftxui/screen/box.hpp" // for Box +#include "ftxui/screen/pixel.hpp" // for Pixel #include "ftxui/screen/screen.hpp" // for Pixel, Screen namespace ftxui { @@ -38,7 +38,8 @@ class Border : public Node { BorderStyle style, std::optional foreground_color = std::nullopt) : Node(std::move(children)), - charset_(simple_border_charset[style]), + charset_(simple_border_charset[style]) // NOLINT + , foreground_color_(foreground_color) {} // NOLINT const Charset& charset_; // NOLINT diff --git a/src/ftxui/dom/box_helper.cpp b/src/ftxui/dom/box_helper.cpp index a09b8e279..8284cf309 100644 --- a/src/ftxui/dom/box_helper.cpp +++ b/src/ftxui/dom/box_helper.cpp @@ -4,6 +4,7 @@ #include "ftxui/dom/box_helper.hpp" #include // for max +#include // for vector namespace ftxui::box_helper { diff --git a/src/ftxui/dom/canvas.cpp b/src/ftxui/dom/canvas.cpp index a78b8948b..ef726721b 100644 --- a/src/ftxui/dom/canvas.cpp +++ b/src/ftxui/dom/canvas.cpp @@ -8,6 +8,7 @@ #include // for uint8_t #include // for abs #include // for Color +#include // for function #include // for map #include // for make_shared #include // for move, pair @@ -17,6 +18,8 @@ #include "ftxui/dom/node.hpp" // for Node #include "ftxui/dom/requirement.hpp" // for Requirement #include "ftxui/screen/box.hpp" // for Box +#include "ftxui/screen/image.hpp" // for Image +#include "ftxui/screen/pixel.hpp" // for Pixel #include "ftxui/screen/screen.hpp" // for Pixel, Screen #include "ftxui/screen/string.hpp" // for Utf8ToGlyphs #include "ftxui/util/ref.hpp" // for ConstRef @@ -28,7 +31,7 @@ namespace { // Base UTF8 pattern: // 11100010 10100000 10000000 // empty -// Pattern for the individuel dots: +// Pattern for the individual dots: // ┌──────┬───────┐ // │dot1 │ dot4 │ // ├──────┼───────┤ diff --git a/src/ftxui/dom/dbox.cpp b/src/ftxui/dom/dbox.cpp index a75321550..c6e752e76 100644 --- a/src/ftxui/dom/dbox.cpp +++ b/src/ftxui/dom/dbox.cpp @@ -2,13 +2,16 @@ // Use of this source code is governed by the MIT license that can be found in // the LICENSE file. #include // for max +#include // for size_t #include // for __shared_ptr_access, shared_ptr, make_shared #include // for move +#include #include "ftxui/dom/elements.hpp" // for Element, Elements, dbox #include "ftxui/dom/node.hpp" // for Node, Elements #include "ftxui/dom/requirement.hpp" // for Requirement #include "ftxui/screen/box.hpp" // for Box +#include "ftxui/screen/pixel.hpp" // for Pixel namespace ftxui { @@ -49,12 +52,13 @@ class DBox : public Node { void Render(Screen& screen) override { if (children_.size() <= 1) { - return Node::Render(screen); + Node::Render(screen); + return; } const int width = box_.x_max - box_.x_min + 1; const int height = box_.y_max - box_.y_min + 1; - std::vector pixels(size_t(width * height)); + std::vector pixels(std::size_t(width * height)); for (auto& child : children_) { child->Render(screen); @@ -67,7 +71,7 @@ class DBox : public Node { acc->background_color = Color::Blend(acc->background_color, pixel.background_color); acc->automerge = pixel.automerge || acc->automerge; - if (pixel.character == "") { + if (pixel.character.empty()) { acc->foreground_color = Color::Blend(acc->foreground_color, pixel.background_color); } else { @@ -82,7 +86,7 @@ class DBox : public Node { acc->character = pixel.character; acc->foreground_color = pixel.foreground_color; } - ++acc; + ++acc; // NOLINT pixel = Pixel(); } @@ -93,7 +97,7 @@ class DBox : public Node { Pixel* acc = pixels.data(); for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { - screen.PixelAt(x + box_.x_min, y + box_.y_min) = *acc++; + screen.PixelAt(x + box_.x_min, y + box_.y_min) = *acc++; // NOLINT } } } diff --git a/src/ftxui/dom/flex.cpp b/src/ftxui/dom/flex.cpp index 992bb2dd0..2fd3adf67 100644 --- a/src/ftxui/dom/flex.cpp +++ b/src/ftxui/dom/flex.cpp @@ -3,7 +3,6 @@ // the LICENSE file. #include // for make_shared, __shared_ptr_access #include // for move -#include // for __alloc_traits<>::value_type #include "ftxui/dom/elements.hpp" // for Element, unpack, filler, flex, flex_grow, flex_shrink, notflex, xflex, xflex_grow, xflex_shrink, yflex, yflex_grow, yflex_shrink #include "ftxui/dom/node.hpp" // for Elements, Node diff --git a/src/ftxui/dom/flexbox_helper.cpp b/src/ftxui/dom/flexbox_helper.cpp index e1a0274e9..eb3e8134e 100644 --- a/src/ftxui/dom/flexbox_helper.cpp +++ b/src/ftxui/dom/flexbox_helper.cpp @@ -7,6 +7,7 @@ #include // for size_t #include // for FlexboxConfig, FlexboxConfig::Direction, FlexboxConfig::AlignContent, FlexboxConfig::JustifyContent, FlexboxConfig::Wrap, FlexboxConfig::Direction::RowInversed, FlexboxConfig::AlignItems, FlexboxConfig::Direction::Row, FlexboxConfig::Direction::Column, FlexboxConfig::Direction::ColumnInversed, FlexboxConfig::Wrap::WrapInversed, FlexboxConfig::AlignContent::Stretch, FlexboxConfig::JustifyContent::Stretch, FlexboxConfig::Wrap::Wrap, FlexboxConfig::AlignContent::Center, FlexboxConfig::AlignContent::FlexEnd, FlexboxConfig::AlignContent::FlexStart, FlexboxConfig::AlignContent::SpaceAround, FlexboxConfig::AlignContent::SpaceBetween, FlexboxConfig::AlignContent::SpaceEvenly, FlexboxConfig::AlignItems::Center, FlexboxConfig::AlignItems::FlexEnd, FlexboxConfig::AlignItems::FlexStart, FlexboxConfig::AlignItems::Stretch, FlexboxConfig::JustifyContent::Center, FlexboxConfig::JustifyContent::FlexEnd, FlexboxConfig::JustifyContent::FlexStart, FlexboxConfig::JustifyContent::SpaceAround, FlexboxConfig::JustifyContent::SpaceBetween, FlexboxConfig::JustifyContent::SpaceEvenly, FlexboxConfig::Wrap::NoWrap #include // for swap, move +#include #include "ftxui/dom/box_helper.hpp" // for Element, Compute @@ -330,8 +331,8 @@ void Compute3(Global& global) { line = Line(); } - block.line = lines.size(); - block.line_position = line.blocks.size(); + block.line = static_cast(lines.size()); + block.line_position = static_cast(line.blocks.size()); line.blocks.push_back(&block); x += block.min_size_x + global.config.gap_x; } diff --git a/src/ftxui/dom/reflect.cpp b/src/ftxui/dom/reflect.cpp index 3155ae8ee..5c5754fbb 100644 --- a/src/ftxui/dom/reflect.cpp +++ b/src/ftxui/dom/reflect.cpp @@ -32,7 +32,7 @@ class Reflect : public Node { void Render(Screen& screen) final { reflected_box_ = Box::Intersection(screen.stencil, reflected_box_); - return Node::Render(screen); + Node::Render(screen); } private: diff --git a/src/ftxui/dom/separator.cpp b/src/ftxui/dom/separator.cpp index dc902af86..4f68dbaea 100644 --- a/src/ftxui/dom/separator.cpp +++ b/src/ftxui/dom/separator.cpp @@ -11,6 +11,7 @@ #include "ftxui/dom/requirement.hpp" // for Requirement #include "ftxui/screen/box.hpp" // for Box #include "ftxui/screen/color.hpp" // for Color +#include "ftxui/screen/pixel.hpp" // for Pixel #include "ftxui/screen/screen.hpp" // for Pixel, Screen namespace ftxui { @@ -63,7 +64,8 @@ class SeparatorAuto : public Node { const bool is_column = (box_.x_max == box_.x_min); const bool is_line = (box_.y_min == box_.y_max); - const std::string c = charsets[style_][int(is_line && !is_column)]; + const std::string c = + charsets[style_][int(is_line && !is_column)]; // NOLINT for (int y = box_.y_min; y <= box_.y_max; ++y) { for (int x = box_.x_min; x <= box_.x_max; ++x) { diff --git a/src/ftxui/dom/table.cpp b/src/ftxui/dom/table.cpp index eb6325960..e87f500fe 100644 --- a/src/ftxui/dom/table.cpp +++ b/src/ftxui/dom/table.cpp @@ -6,6 +6,7 @@ #include // for max #include // for allocator, shared_ptr, allocator_traits<>::value_type #include // for move, swap +#include // for vector #include "ftxui/dom/elements.hpp" // for Element, operator|, text, separatorCharacter, Elements, BorderStyle, Decorator, emptyElement, size, gridbox, EQUAL, flex, flex_shrink, HEIGHT, WIDTH diff --git a/src/ftxui/screen/color.cpp b/src/ftxui/screen/color.cpp index 546241f73..14e2863c0 100644 --- a/src/ftxui/screen/color.cpp +++ b/src/ftxui/screen/color.cpp @@ -6,14 +6,12 @@ #include // for array #include #include +#include #include "ftxui/screen/color_info.hpp" // for GetColorInfo, ColorInfo #include "ftxui/screen/terminal.hpp" // for ColorSupport, Color, Palette256, TrueColor namespace ftxui { - -using namespace std::literals; - namespace { const std::array palette16code = { "30", "40", // @@ -46,22 +44,30 @@ bool Color::operator!=(const Color& rhs) const { } std::string Color::Print(bool is_background_color) const { - switch (type_) { - case ColorType::Palette1: - return is_background_color ? "49"s : "39"s; - - case ColorType::Palette16: - return palette16code[2 * red_ + is_background_color]; // NOLINT; - - case ColorType::Palette256: - return (is_background_color ? "48;5;"s : "38;5;"s) + std::to_string(red_); - - case ColorType::TrueColor: - default: - return (is_background_color ? "48;2;"s : "38;2;"s) // - + std::to_string(red_) + ";" // - + std::to_string(green_) + ";" // - + std::to_string(blue_); // + if (is_background_color) { + switch (type_) { + case ColorType::Palette1: + return "49"; + case ColorType::Palette16: + return palette16code[2 * red_ + 1]; // NOLINT + case ColorType::Palette256: + return "48;5;" + std::to_string(red_); + case ColorType::TrueColor: + return "48;2;" + std::to_string(red_) + ";" + std::to_string(green_) + + ";" + std::to_string(blue_); + } + } else { + switch (type_) { + case ColorType::Palette1: + return "39"; + case ColorType::Palette16: + return palette16code[2 * red_]; // NOLINT + case ColorType::Palette256: + return "38;5;" + std::to_string(red_); + case ColorType::TrueColor: + return "38;2;" + std::to_string(red_) + ";" + std::to_string(green_) + + ";" + std::to_string(blue_); + } } } diff --git a/src/ftxui/screen/image.cpp b/src/ftxui/screen/image.cpp index 3fa3fbefd..55e4b135f 100644 --- a/src/ftxui/screen/image.cpp +++ b/src/ftxui/screen/image.cpp @@ -2,8 +2,11 @@ // Use of this source code is governed by the MIT license that can be found in // the LICENSE file. #include // IWYU pragma: keep +#include +#include #include "ftxui/screen/image.hpp" +#include "ftxui/screen/pixel.hpp" namespace ftxui { diff --git a/src/ftxui/screen/screen.cpp b/src/ftxui/screen/screen.cpp index a04914a0a..7bd64e296 100644 --- a/src/ftxui/screen/screen.cpp +++ b/src/ftxui/screen/screen.cpp @@ -1,13 +1,16 @@ // 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 // for size_t +#include // for size_t +#include #include // for operator<<, stringstream, basic_ostream, flush, cout, ostream #include #include // for _Rb_tree_const_iterator, map, operator!=, operator== #include // IWYU pragma: keep #include // for pair +#include "ftxui/screen/image.hpp" // for Image +#include "ftxui/screen/pixel.hpp" // for Pixel #include "ftxui/screen/screen.hpp" #include "ftxui/screen/string.hpp" // for string_width #include "ftxui/screen/terminal.hpp" // for Dimensions, Size @@ -117,11 +120,11 @@ void UpdatePixelStyle(const Screen* screen, } struct TileEncoding { - uint8_t left : 2; - uint8_t top : 2; - uint8_t right : 2; - uint8_t down : 2; - uint8_t round : 1; + std::uint8_t left : 2; + std::uint8_t top : 2; + std::uint8_t right : 2; + std::uint8_t down : 2; + std::uint8_t round : 1; // clang-format off bool operator<(const TileEncoding& other) const { @@ -521,20 +524,20 @@ void Screen::ApplyShader() { } // clang-format on -uint8_t Screen::RegisterHyperlink(const std::string& link) { - for (size_t i = 0; i < hyperlinks_.size(); ++i) { +std::uint8_t Screen::RegisterHyperlink(const std::string& link) { + for (std::size_t i = 0; i < hyperlinks_.size(); ++i) { if (hyperlinks_[i] == link) { return i; } } - if (hyperlinks_.size() == std::numeric_limits::max()) { + if (hyperlinks_.size() == std::numeric_limits::max()) { return 0; } hyperlinks_.push_back(link); return hyperlinks_.size() - 1; } -const std::string& Screen::Hyperlink(uint8_t id) const { +const std::string& Screen::Hyperlink(std::uint8_t id) const { if (id >= hyperlinks_.size()) { return hyperlinks_[0]; } diff --git a/src/ftxui/screen/string.cpp b/src/ftxui/screen/string.cpp index 48012f0fc..f07b47a5d 100644 --- a/src/ftxui/screen/string.cpp +++ b/src/ftxui/screen/string.cpp @@ -16,6 +16,7 @@ #include // for uint32_t, uint8_t, uint16_t, int32_t #include // for string, basic_string, wstring #include // for _Swallow_assign, ignore +#include #include "ftxui/screen/deprecated.hpp" // for wchar_width, wstring_width #include "ftxui/screen/string_internal.hpp" // for WordBreakProperty, EatCodePoint, CodepointToWordBreakProperty, GlyphCount, GlyphIterate, GlyphNext, GlyphPrevious, IsCombining, IsControl, IsFullWidth, Utf8ToWordBreakProperty @@ -1355,7 +1356,6 @@ int string_width(const std::string& input) { std::vector Utf8ToGlyphs(const std::string& input) { std::vector out; - const std::string current; out.reserve(input.size()); size_t start = 0; size_t end = 0; diff --git a/src/ftxui/util/ref_test.cpp b/src/ftxui/util/ref_test.cpp index e21dc56e8..de9e1015a 100644 --- a/src/ftxui/util/ref_test.cpp +++ b/src/ftxui/util/ref_test.cpp @@ -1,3 +1,7 @@ +// Copyright 2023 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/util/ref.hpp" #include