From 689d5dd299f6ce0de2fd074be953402dc21a07ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Du=C4=87ak?= <31933626+NikolaDucak@users.noreply.github.com> Date: Sat, 5 Feb 2022 15:03:45 +0100 Subject: [PATCH] Replace std::clamp with util::clamp and reformat the code (#321) * Replace std::clamp with util::clamp * Apply clang-format * Execute ./tools/iwyu.sh Co-authored-by: ArthurSonzogni --- examples/component/with_restored_io.cpp | 14 +++++++++++--- include/ftxui/dom/table.hpp | 2 +- src/ftxui/component/component_fuzzer.cpp | 2 +- src/ftxui/component/input.cpp | 7 ++++--- src/ftxui/component/menu.cpp | 8 ++++---- src/ftxui/component/radiobox.cpp | 6 +++--- src/ftxui/component/screen_interactive.cpp | 1 - src/ftxui/component/toggle.cpp | 6 +++--- src/ftxui/dom/table.cpp | 4 ++-- 9 files changed, 29 insertions(+), 21 deletions(-) diff --git a/examples/component/with_restored_io.cpp b/examples/component/with_restored_io.cpp index 938059bf..4ca089d5 100644 --- a/examples/component/with_restored_io.cpp +++ b/examples/component/with_restored_io.cpp @@ -1,5 +1,13 @@ -#include "ftxui/component/component.hpp" // for Menu +#include // for system, EXIT_SUCCESS +#include // for operator<<, basic_ostream, basic_ostream::operator<<, cout, endl, flush, ostream, basic_ostream<>::__ostream_type, cin +#include // for shared_ptr, __shared_ptr_access, allocator +#include // for getline, string + +#include "ftxui/component/captured_mouse.hpp" // for ftxui +#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer +#include "ftxui/component/component_base.hpp" // for ComponentBase #include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive +#include "ftxui/dom/elements.hpp" // for operator|, filler, Element, borderEmpty, hbox, size, paragraph, vbox, LESS_THAN, border, center, HEIGHT, WIDTH int main() { using namespace ftxui; @@ -10,14 +18,14 @@ int main() { // temporarily uninstall the terminal hook and execute the provided callback // function. This allow running the application in a non-interactive mode. auto btn_run = Button("Execute with restored IO", screen.WithRestoredIO([] { - std::system("bash"); + std::system("bash"); std::cout << "This is a child program using stdin/stdout." << std::endl; for (int i = 0; i < 10; ++i) { std::cout << "Please enter 10 strings (" << i << "/10)" << std::flush; std::string input; std::getline(std::cin, input); } - std::system("bash"); + std::system("bash"); })); auto btn_quit = Button("Quit", screen.ExitLoopClosure()); diff --git a/include/ftxui/dom/table.hpp b/include/ftxui/dom/table.hpp index 23e0fa45..7c0e5340 100644 --- a/include/ftxui/dom/table.hpp +++ b/include/ftxui/dom/table.hpp @@ -5,7 +5,7 @@ #include // for string #include // for vector -#include "ftxui/dom/elements.hpp" // for BorderStyle, LIGHT, Element, Decorator +#include "ftxui/dom/elements.hpp" // for Element, BorderStyle, LIGHT, Decorator namespace ftxui { diff --git a/src/ftxui/component/component_fuzzer.cpp b/src/ftxui/component/component_fuzzer.cpp index acab31f8..f3aa6983 100644 --- a/src/ftxui/component/component_fuzzer.cpp +++ b/src/ftxui/component/component_fuzzer.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include #include "ftxui/component/component.hpp" #include "ftxui/component/terminal_input_parser.hpp" diff --git a/src/ftxui/component/input.cpp b/src/ftxui/component/input.cpp index b04b9401..33f58239 100644 --- a/src/ftxui/component/input.cpp +++ b/src/ftxui/component/input.cpp @@ -1,5 +1,5 @@ #include // for size_t -#include // for clamp, max, min +#include // for max, min #include // for function #include // for shared_ptr, allocator #include // for string, wstring @@ -17,6 +17,7 @@ #include "ftxui/dom/elements.hpp" // for operator|, text, Element, reflect, inverted, Decorator, flex, focus, hbox, size, bold, dim, frame, select, EQUAL, HEIGHT #include "ftxui/screen/box.hpp" // for Box #include "ftxui/screen/string.hpp" // for GlyphPosition, GlyphCount, to_string, CellToGlyphIndex, to_wstring +#include "ftxui/screen/util.hpp" // for clamp #include "ftxui/util/ref.hpp" // for StringRef, Ref, WideStringRef, ConstStringRef namespace ftxui { @@ -189,7 +190,7 @@ class InputBase : public ComponentBase { auto mapping = CellToGlyphIndex(*content_); int original_glyph = cursor_position(); - original_glyph = std::clamp(original_glyph, 0, int(mapping.size())); + original_glyph = util::clamp(original_glyph, 0, int(mapping.size())); int original_cell = 0; for (size_t i = 0; i < mapping.size(); i++) { if (mapping[i] == original_glyph) { @@ -202,7 +203,7 @@ class InputBase : public ComponentBase { int target_cell = original_cell + event.mouse().x - cursor_box_.x_min; int target_glyph = target_cell < (int)mapping.size() ? mapping[target_cell] : (int)mapping.size(); - target_glyph = std::clamp(target_glyph, 0, GlyphCount(*content_)); + target_glyph = util::clamp(target_glyph, 0, GlyphCount(*content_)); if (cursor_position() != target_glyph) { cursor_position() = target_glyph; option_->on_change(); diff --git a/src/ftxui/component/menu.cpp b/src/ftxui/component/menu.cpp index 9b3b4259..3cd5218f 100644 --- a/src/ftxui/component/menu.cpp +++ b/src/ftxui/component/menu.cpp @@ -1,4 +1,4 @@ -#include // for clamp, max +#include // for max #include // for function #include // for shared_ptr, allocator_traits<>::value_type #include // for operator+, string @@ -13,9 +13,9 @@ #include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Released, Mouse::WheelDown, Mouse::WheelUp, Mouse::None #include "ftxui/component/screen_interactive.hpp" // for Component #include "ftxui/dom/elements.hpp" // for operator|, Element, reflect, text, nothing, select, vbox, Elements, focus -#include "ftxui/screen/box.hpp" // for Box -#include "ftxui/screen/util.hpp" -#include "ftxui/util/ref.hpp" // for Ref, ConstStringListRef, ConstStringRef +#include "ftxui/screen/box.hpp" // for Box +#include "ftxui/screen/util.hpp" // for clamp +#include "ftxui/util/ref.hpp" // for Ref, ConstStringListRef, ConstStringRef namespace ftxui { diff --git a/src/ftxui/component/radiobox.cpp b/src/ftxui/component/radiobox.cpp index f53cc411..720d2b33 100644 --- a/src/ftxui/component/radiobox.cpp +++ b/src/ftxui/component/radiobox.cpp @@ -1,4 +1,4 @@ -#include // for clamp, max +#include // for max #include // for function #include // for shared_ptr, allocator_traits<>::value_type #include // for string @@ -14,8 +14,8 @@ #include "ftxui/component/screen_interactive.hpp" // for Component #include "ftxui/dom/elements.hpp" // for operator|, reflect, text, Element, hbox, vbox, Elements, focus, nothing, select #include "ftxui/screen/box.hpp" // for Box -#include "ftxui/screen/util.hpp" -#include "ftxui/util/ref.hpp" // for Ref, ConstStringListRef +#include "ftxui/screen/util.hpp" // for clamp +#include "ftxui/util/ref.hpp" // for Ref, ConstStringListRef namespace ftxui { diff --git a/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp index f0436908..10177796 100644 --- a/src/ftxui/component/screen_interactive.cpp +++ b/src/ftxui/component/screen_interactive.cpp @@ -277,7 +277,6 @@ CapturedMouse ScreenInteractive::CaptureMouse() { } void ScreenInteractive::Loop(Component component) { - // Suspend previously active screen: if (g_active_screen) { std::swap(suspended_screen_, g_active_screen); diff --git a/src/ftxui/component/toggle.cpp b/src/ftxui/component/toggle.cpp index fb11a7fb..d654ca5f 100644 --- a/src/ftxui/component/toggle.cpp +++ b/src/ftxui/component/toggle.cpp @@ -1,4 +1,4 @@ -#include // for clamp, max +#include // for max #include // for function #include // for shared_ptr, allocator_traits<>::value_type #include // for move @@ -12,8 +12,8 @@ #include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Pressed #include "ftxui/dom/elements.hpp" // for operator|, Element, Elements, hbox, reflect, separator, text, focus, nothing, select #include "ftxui/screen/box.hpp" // for Box -#include "ftxui/screen/util.hpp" -#include "ftxui/util/ref.hpp" // for Ref, ConstStringListRef +#include "ftxui/screen/util.hpp" // for clamp +#include "ftxui/util/ref.hpp" // for Ref, ConstStringListRef namespace ftxui { diff --git a/src/ftxui/dom/table.cpp b/src/ftxui/dom/table.cpp index 8617f1a8..b36332a9 100644 --- a/src/ftxui/dom/table.cpp +++ b/src/ftxui/dom/table.cpp @@ -41,10 +41,10 @@ Table::Table() { Table::Table(std::vector> input) { std::vector> output; - for(auto& row : input) { + for (auto& row : input) { output.push_back({}); auto& output_row = output.back(); - for(auto& cell : row) { + for (auto& cell : row) { output_row.push_back(text(cell)); } }