FTXUI/src/ftxui/dom/util.cpp

63 lines
1.4 KiB
C++
Raw Normal View History

2019-01-03 05:33:59 +08:00
#include "ftxui/dom/elements.hpp"
namespace ftxui {
2019-01-03 05:33:59 +08:00
2020-08-16 08:24:50 +08:00
namespace {
2019-01-03 07:35:59 +08:00
Decorator compose(Decorator a, Decorator b) {
2020-03-23 05:32:44 +08:00
return [a = std::move(a), b = std::move(b)](Element element) {
return b(a(std::move(element)));
2019-01-03 07:35:59 +08:00
};
}
2020-08-16 08:24:50 +08:00
} // namespace
/// @brief A decoration doing absolutely nothing.
/// @ingroup dom
Element nothing(Element element) {
return element;
}
2019-01-03 07:35:59 +08:00
2020-08-16 08:24:50 +08:00
/// @brief Compose two decorator into one.
/// @ingroup dom
///
/// ### Example
///
/// ```cpp
/// auto decorator = bold | blink;
/// ```
Decorator operator|(Decorator a, Decorator b) {
return compose(a, b);
}
2020-08-16 08:24:50 +08:00
/// @brief From a set of element, apply a decorator to every elements.
/// @return the set of decorated element.
/// @ingroup dom
Elements operator|(Elements elements, Decorator decorator) {
2019-01-27 04:52:55 +08:00
Elements output;
2020-08-16 08:24:50 +08:00
for (auto& it : elements)
output.push_back(std::move(it) | decorator);
2019-01-27 04:52:55 +08:00
return output;
}
2020-08-16 08:24:50 +08:00
/// @brief From an element, apply a decorator.
/// @return the decorated element.
/// @ingroup dom
///
/// ### Example
///
/// Both of these are equivalent:
/// ```cpp
/// bold(text(L"Hello"));
/// ```
/// ```cpp
/// text(L"Hello") | bold;
/// ```
Element operator|(Element element, Decorator decorator) {
return decorator(std::move(element));
}
} // namespace ftxui
// 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.