From 114cbfcffd86118597d7dd5998a6ea97bd2d1860 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Wed, 27 Apr 2022 11:33:42 +0200 Subject: [PATCH] Add coverage and remove deprecated WideInput. --- CHANGELOG.md | 2 + cmake/ftxui_test.cmake | 2 + include/ftxui/component/component.hpp | 3 -- include/ftxui/component/deprecated.hpp | 18 -------- include/ftxui/util/ref.hpp | 17 ------- src/ftxui/component/animation_test.cpp | 56 +++++++++++++++++++++++ src/ftxui/component/input.cpp | 62 +------------------------- 7 files changed, 61 insertions(+), 99 deletions(-) delete mode 100644 include/ftxui/component/deprecated.hpp create mode 100644 src/ftxui/component/animation_test.cpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 613a437..817f5b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,8 @@ current (development) - Add the `Maybe` decorator. - Add the `CatchEvent` decorator. - Add the `Renderer` decorator. +- **breaking** remove the "deprectated.hpp" header and Input support for wide + string. ### DOM: - **breaking**: The `inverted` decorator now toggle in the inverted attribute. diff --git a/cmake/ftxui_test.cmake b/cmake/ftxui_test.cmake index 4dafb7c..78a5336 100644 --- a/cmake/ftxui_test.cmake +++ b/cmake/ftxui_test.cmake @@ -23,6 +23,8 @@ if(NOT googletest_POPULATED) endif() add_executable(tests + src/ftxui/component/animation_test.cpp + src/ftxui/component/component_test.cpp src/ftxui/component/component_test.cpp src/ftxui/component/container_test.cpp src/ftxui/component/input_test.cpp diff --git a/include/ftxui/component/component.hpp b/include/ftxui/component/component.hpp index e36ab35..5f81ace 100644 --- a/include/ftxui/component/component.hpp +++ b/include/ftxui/component/component.hpp @@ -93,9 +93,6 @@ Component Collapsible(ConstStringRef label, Ref show = false); } // namespace ftxui -// Include component using the old deprecated wstring. -#include "ftxui/component/deprecated.hpp" - #endif /* end of include guard: FTXUI_COMPONENT_HPP */ // Copyright 2021 Arthur Sonzogni. All rights reserved. diff --git a/include/ftxui/component/deprecated.hpp b/include/ftxui/component/deprecated.hpp deleted file mode 100644 index 1f3b956..0000000 --- a/include/ftxui/component/deprecated.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef FTXUI_COMPONENT_DEPRECATED_HPP -#define FTXUI_COMPONENT_DEPRECATED_HPP - -#include "ftxui/component/component.hpp" - -namespace ftxui { - -[[deprecated("use Input with normal std::string instead.")]] Component Input( - WideStringRef content, - ConstStringRef placeholder, - Ref option = {}); -} // namespace ftxui - -#endif /* FTXUI_COMPONENT_DEPRECATED_HPP */ - -// 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. diff --git a/include/ftxui/util/ref.hpp b/include/ftxui/util/ref.hpp index e806200..d7eb64a 100644 --- a/include/ftxui/util/ref.hpp +++ b/include/ftxui/util/ref.hpp @@ -55,23 +55,6 @@ class StringRef { std::string* address_ = nullptr; }; -/// @brief An adapter. Own or reference a constant string. For convenience, this -/// class convert multiple mutable string toward a shared representation. -class WideStringRef { - public: - WideStringRef(std::wstring* ref) : address_(ref) {} - WideStringRef(std::wstring ref) : owned_(std::move(ref)) {} - WideStringRef(const wchar_t* ref) : WideStringRef(std::wstring(ref)) {} - WideStringRef(const char* ref) - : WideStringRef(to_wstring(std::string(ref))) {} - std::wstring& operator*() { return address_ ? *address_ : owned_; } - std::wstring* operator->() { return address_ ? address_ : &owned_; } - - private: - std::wstring owned_; - std::wstring* address_ = nullptr; -}; - /// @brief An adapter. Own or reference a constant string. For convenience, this /// class convert multiple immutable string toward a shared representation. class ConstStringRef { diff --git a/src/ftxui/component/animation_test.cpp b/src/ftxui/component/animation_test.cpp new file mode 100644 index 0000000..0ea1277 --- /dev/null +++ b/src/ftxui/component/animation_test.cpp @@ -0,0 +1,56 @@ +#include // for Message +#include // for TestPartResult +#include // for shared_ptr, __shared_ptr_access, allocator, make_shared + +#include "ftxui/component/captured_mouse.hpp" // for ftxui +#include "ftxui/component/component.hpp" // for Make +#include "ftxui/component/component_base.hpp" // for ComponentBase, Component +#include "gtest/gtest_pred_impl.h" // for EXPECT_EQ, Test, SuiteApiResolver, TEST, TestFactoryImpl + +namespace ftxui { + +TEST(AnimationTest, StartAndEnd) { + std::vector functions = { + animation::easing::Linear, + animation::easing::QuadraticIn, + animation::easing::QuadraticOut, + animation::easing::QuadraticInOut, + animation::easing::CubicIn, + animation::easing::CubicOut, + animation::easing::CubicInOut, + animation::easing::QuarticIn, + animation::easing::QuarticOut, + animation::easing::QuarticInOut, + animation::easing::QuinticIn, + animation::easing::QuinticOut, + animation::easing::QuinticInOut, + animation::easing::SineIn, + animation::easing::SineOut, + animation::easing::SineInOut, + animation::easing::CircularIn, + animation::easing::CircularOut, + animation::easing::CircularInOut, + animation::easing::ExponentialIn, + animation::easing::ExponentialOut, + animation::easing::ExponentialInOut, + animation::easing::ElasticIn, + animation::easing::ElasticOut, + animation::easing::ElasticInOut, + animation::easing::BackIn, + animation::easing::BackOut, + animation::easing::BackInOut, + animation::easing::BounceIn, + animation::easing::BounceOut, + animation::easing::BounceInOut, + }; + for (auto& it : functions) { + EXPECT_NEAR(0.f, it(0.f), 1.0e-4); + EXPECT_NEAR(1.f, it(1.f), 1.0e-4); + } +} + +} // namespace ftxui + +// 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. diff --git a/src/ftxui/component/input.cpp b/src/ftxui/component/input.cpp index a988cb1..0ff193e 100644 --- a/src/ftxui/component/input.cpp +++ b/src/ftxui/component/input.cpp @@ -10,7 +10,6 @@ #include "ftxui/component/component.hpp" // for Make, Input #include "ftxui/component/component_base.hpp" // for ComponentBase #include "ftxui/component/component_options.hpp" // for InputOption -#include "ftxui/component/deprecated.hpp" // for Input #include "ftxui/component/event.hpp" // for Event, Event::ArrowLeft, Event::ArrowRight, Event::Backspace, Event::Custom, Event::Delete, Event::End, Event::Home, Event::Return #include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Pressed #include "ftxui/component/screen_interactive.hpp" // for Component @@ -18,7 +17,7 @@ #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 +#include "ftxui/util/ref.hpp" // for StringRef, Ref, ConstStringRef namespace ftxui { @@ -236,36 +235,6 @@ class InputBase : public ComponentBase { Ref option_; }; -// An input box. The user can type text into it. -// For convenience, the std::wstring version of Input simply wrap a -// InputBase. -class WideInputBase : public InputBase { - public: - WideInputBase(WideStringRef content, - ConstStringRef placeholder, - Ref option) - : InputBase(&wrapped_content_, std::move(placeholder), std::move(option)), - content_(std::move(content)), - wrapped_content_(to_string(*content_)) {} - - Element Render() override { - wrapped_content_ = to_string(*content_); - return InputBase::Render(); - } - - bool OnEvent(Event event) override { - wrapped_content_ = to_string(*content_); - if (InputBase::OnEvent(event)) { - *content_ = to_wstring(wrapped_content_); - return true; - } - return false; - } - - WideStringRef content_; - std::string wrapped_content_; -}; - } // namespace /// @brief An input box for editing text. @@ -297,35 +266,6 @@ Component Input(StringRef content, std::move(option)); } -/// @brief . An input box for editing text. -/// @param content The editable content. -/// @param placeholder The text displayed when content is still empty. -/// @param option Additional optional parameters. -/// @ingroup component -/// @see InputBase -/// -/// ### Example -/// -/// ```cpp -/// auto screen = ScreenInteractive::FitComponent(); -/// std::string content= ""; -/// std::string placeholder = "placeholder"; -/// Component input = Input(&content, &placeholder); -/// screen.Loop(input); -/// ``` -/// -/// ### Output -/// -/// ```bash -/// placeholder -/// ``` -Component Input(WideStringRef content, - ConstStringRef placeholder, - Ref option) { - return Make(std::move(content), std::move(placeholder), - std::move(option)); -} - } // namespace ftxui // Copyright 2020 Arthur Sonzogni. All rights reserved.