mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-12-16 01:48:56 +08:00
Compare commits
2 Commits
9f4b2bcf96
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
170c1b94dd | ||
|
|
942ab6a82d |
12
flake.lock
generated
12
flake.lock
generated
@@ -5,11 +5,11 @@
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1694529238,
|
||||
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -20,11 +20,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1697915759,
|
||||
"narHash": "sha256-WyMj5jGcecD+KC8gEs+wFth1J1wjisZf8kVZH13f1Zo=",
|
||||
"lastModified": 1765644376,
|
||||
"narHash": "sha256-yqHBL2wYGwjGL2GUF2w3tofWl8qO9tZEuI4wSqbCrtE=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "51d906d2341c9e866e48c2efcaac0f2d70bfd43e",
|
||||
"rev": "23735a82a828372c4ef92c660864e82fbe2f5fbe",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
12
flake.nix
12
flake.nix
@@ -12,15 +12,9 @@
|
||||
let llvm = pkgs.llvmPackages_latest; in
|
||||
{
|
||||
packages = rec {
|
||||
default = pkgs.stdenv.mkDerivation rec {
|
||||
pname = "ftxui";
|
||||
version = "v4.0.0";
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "ArthurSonzogni";
|
||||
repo = "FTXUI";
|
||||
rev = version;
|
||||
sha256 = "sha256-3kAhHDUwzwdvHc8JZAcA14tGqa6w69qrN1JXhSxNBQY=";
|
||||
};
|
||||
default = pkgs.stdenv.mkDerivation {
|
||||
name = "ftxui";
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = [
|
||||
pkgs.cmake
|
||||
|
||||
@@ -18,8 +18,13 @@ template <typename T>
|
||||
class ConstRef {
|
||||
public:
|
||||
ConstRef() = default;
|
||||
|
||||
// Owning constructors:
|
||||
ConstRef(T t) : variant_(std::move(t)) {} // NOLINT
|
||||
|
||||
// Referencing constructors:
|
||||
ConstRef(const T* t) : variant_(t) {} // NOLINT
|
||||
|
||||
ConstRef& operator=(ConstRef&&) noexcept = default;
|
||||
ConstRef(const ConstRef<T>&) = default;
|
||||
ConstRef(ConstRef<T>&&) noexcept = default;
|
||||
@@ -47,8 +52,13 @@ template <typename T>
|
||||
class Ref {
|
||||
public:
|
||||
Ref() = default;
|
||||
|
||||
// Owning constructors:
|
||||
Ref(T t) : variant_(std::move(t)) {} // NOLINT
|
||||
//
|
||||
// Referencing constructors:
|
||||
Ref(T* t) : variant_(t) {} // NOLINT
|
||||
//
|
||||
~Ref() = default;
|
||||
Ref& operator=(Ref&&) noexcept = default;
|
||||
Ref(const Ref<T>&) = default;
|
||||
@@ -84,10 +94,15 @@ class StringRef : public Ref<std::string> {
|
||||
public:
|
||||
using Ref<std::string>::Ref;
|
||||
|
||||
// Owning constructors:
|
||||
StringRef(const wchar_t* ref) // NOLINT
|
||||
: StringRef(to_string(std::wstring(ref))) {}
|
||||
StringRef(const char* ref) // NOLINT
|
||||
: StringRef(std::string(ref)) {}
|
||||
StringRef(std::string_view ref) // NOLINT
|
||||
: StringRef(std::string(ref)) {}
|
||||
StringRef(std::wstring_view ref) // NOLINT
|
||||
: StringRef(to_string(ref)) {}
|
||||
};
|
||||
|
||||
/// @brief An adapter. Own or reference a constant string. For convenience, this
|
||||
@@ -96,14 +111,21 @@ class ConstStringRef : public ConstRef<std::string> {
|
||||
public:
|
||||
using ConstRef<std::string>::ConstRef;
|
||||
|
||||
// Referencing constructors:
|
||||
ConstStringRef(const std::wstring* ref) // NOLINT
|
||||
: ConstStringRef(to_string(*ref)) {}
|
||||
|
||||
// Owning constructors:
|
||||
ConstStringRef(const std::wstring ref) // NOLINT
|
||||
: ConstStringRef(to_string(ref)) {}
|
||||
ConstStringRef(std::wstring_view ref) // NOLINT
|
||||
: ConstStringRef(to_string(ref)) {}
|
||||
ConstStringRef(const wchar_t* ref) // NOLINT
|
||||
: ConstStringRef(to_string(std::wstring(ref))) {}
|
||||
ConstStringRef(const char* ref) // NOLINT
|
||||
: ConstStringRef(std::string(ref)) {}
|
||||
ConstStringRef(std::string_view ref) // NOLINT
|
||||
: ConstStringRef(std::string(ref)) {}
|
||||
};
|
||||
|
||||
/// @brief An adapter. Reference a list of strings.
|
||||
@@ -144,33 +166,26 @@ class ConstStringListRef {
|
||||
ConstStringListRef(ConstStringListRef&&) = default;
|
||||
ConstStringListRef(const ConstStringListRef&) = default;
|
||||
|
||||
ConstStringListRef(std::vector<std::string> value) // NOLINT
|
||||
{
|
||||
ConstStringListRef(std::vector<std::string> value) { // NOLINT
|
||||
variant_ = std::make_shared<Variant>(value);
|
||||
}
|
||||
ConstStringListRef(const std::vector<std::string>* value) // NOLINT
|
||||
{
|
||||
ConstStringListRef(const std::vector<std::string>* value) {// NOLINT
|
||||
variant_ = std::make_shared<Variant>(value);
|
||||
}
|
||||
ConstStringListRef(std::vector<std::string_view> value) // NOLINT
|
||||
{
|
||||
ConstStringListRef(std::vector<std::string_view> value) { // NOLINT
|
||||
variant_ = std::make_shared<Variant>(value);
|
||||
}
|
||||
ConstStringListRef(const std::vector<std::string_view>* value) // NOLINT
|
||||
{
|
||||
ConstStringListRef(const std::vector<std::string_view>* value) { // NOLINT
|
||||
variant_ = std::make_shared<Variant>(value);
|
||||
}
|
||||
ConstStringListRef(const std::vector<std::wstring>* value) // NOLINT
|
||||
{
|
||||
ConstStringListRef(const std::vector<std::wstring>* value) { // NOLINT
|
||||
variant_ = std::make_shared<Variant>(value);
|
||||
}
|
||||
ConstStringListRef(Adapter* adapter) // NOLINT
|
||||
{
|
||||
ConstStringListRef(Adapter* adapter) { // NOLINT
|
||||
variant_ = std::make_shared<Variant>(adapter);
|
||||
}
|
||||
template <typename AdapterType>
|
||||
ConstStringListRef(std::unique_ptr<AdapterType> adapter) // NOLINT
|
||||
{
|
||||
ConstStringListRef(std::unique_ptr<AdapterType> adapter) { // NOLINT
|
||||
variant_ = std::make_shared<Variant>(
|
||||
static_cast<std::unique_ptr<Adapter>>(std::move(adapter)));
|
||||
}
|
||||
@@ -179,66 +194,34 @@ class ConstStringListRef {
|
||||
return variant_ ? std::visit(SizeVisitor(), *variant_) : 0;
|
||||
}
|
||||
|
||||
std::string operator[](size_t i) const {
|
||||
if (!variant_) {
|
||||
return "";
|
||||
}
|
||||
auto& v = *variant_;
|
||||
if (std::holds_alternative<const std::vector<std::string>>(v)) {
|
||||
return std::get<const std::vector<std::string>>(v)[i];
|
||||
}
|
||||
if (std::holds_alternative<const std::vector<std::string>*>(v)) {
|
||||
return (*std::get<const std::vector<std::string>*>(v))[i];
|
||||
}
|
||||
if (std::holds_alternative<const std::vector<std::string_view>>(v)) {
|
||||
return std::string(std::get<const std::vector<std::string_view>>(v)[i]);
|
||||
}
|
||||
if (std::holds_alternative<const std::vector<std::string_view>*>(v)) {
|
||||
return std::string(
|
||||
(*std::get<const std::vector<std::string_view>*>(v))[i]);
|
||||
}
|
||||
if (std::holds_alternative<const std::vector<std::wstring>*>(v)) {
|
||||
return to_string((*std::get<const std::vector<std::wstring>*>(v))[i]);
|
||||
}
|
||||
if (std::holds_alternative<Adapter*>(v)) {
|
||||
return std::string((*std::get<Adapter*>(v))[i]);
|
||||
}
|
||||
if (std::holds_alternative<std::unique_ptr<Adapter>>(v)) {
|
||||
return std::string((*std::get<std::unique_ptr<Adapter>>(v))[i]);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string_view at(size_t i) const {
|
||||
if (!variant_) {
|
||||
return "";
|
||||
}
|
||||
auto& v = *variant_;
|
||||
if (std::holds_alternative<const std::vector<std::string>>(v)) {
|
||||
return std::get<const std::vector<std::string>>(v)[i];
|
||||
}
|
||||
if (std::holds_alternative<const std::vector<std::string>*>(v)) {
|
||||
return (*std::get<const std::vector<std::string>*>(v))[i];
|
||||
}
|
||||
if (std::holds_alternative<const std::vector<std::string_view>>(v)) {
|
||||
return std::get<const std::vector<std::string_view>>(v)[i];
|
||||
}
|
||||
if (std::holds_alternative<const std::vector<std::string_view>*>(v)) {
|
||||
return (*std::get<const std::vector<std::string_view>*>(v))[i];
|
||||
}
|
||||
if (std::holds_alternative<const std::vector<std::wstring>*>(v)) {
|
||||
return {};
|
||||
}
|
||||
if (std::holds_alternative<Adapter*>(v)) {
|
||||
return (*std::get<Adapter*>(v))[i];
|
||||
}
|
||||
if (std::holds_alternative<std::unique_ptr<Adapter>>(v)) {
|
||||
return (*std::get<std::unique_ptr<Adapter>>(v))[i];
|
||||
}
|
||||
return {};
|
||||
std::string_view operator[](size_t i) const {
|
||||
return variant_ ? std::visit(IndexedGetter{i}, *variant_) : "";
|
||||
}
|
||||
|
||||
private:
|
||||
struct IndexedGetter {
|
||||
size_t i;
|
||||
std::string_view operator()(const std::vector<std::string>& v) const {
|
||||
return v[i];
|
||||
}
|
||||
std::string_view operator()(const std::vector<std::string>* v) const {
|
||||
return (*v)[i];
|
||||
}
|
||||
std::string_view operator()(const std::vector<std::string_view>& v) const {
|
||||
return std::string(v[i]);
|
||||
}
|
||||
std::string_view operator()(const std::vector<std::string_view>* v) const {
|
||||
return std::string((*v)[i]);
|
||||
}
|
||||
std::string_view operator()(const std::vector<std::wstring>* v) const {
|
||||
return to_string((*v)[i]);
|
||||
}
|
||||
std::string_view operator()(Adapter* v) const { return std::string((*v)[i]); }
|
||||
std::string_view operator()(const std::unique_ptr<Adapter>& v) const {
|
||||
return (*v)[i];
|
||||
}
|
||||
};
|
||||
|
||||
struct SizeVisitor {
|
||||
size_t operator()(const std::vector<std::string>& v) const {
|
||||
return v.size();
|
||||
|
||||
@@ -123,7 +123,7 @@ class MenuBase : public ComponentBase, public MenuOption {
|
||||
const bool is_selected = (selected() == i);
|
||||
|
||||
const EntryState state = {
|
||||
entries[i], false, is_selected, is_focused, i,
|
||||
std::string(entries[i]), false, is_selected, is_focused, i,
|
||||
};
|
||||
|
||||
Element element = (entries_option.transform ? entries_option.transform
|
||||
|
||||
@@ -37,7 +37,7 @@ class RadioboxBase : public ComponentBase, public RadioboxOption {
|
||||
const bool is_focused = (focused_entry() == i) && is_menu_focused;
|
||||
const bool is_selected = (hovered_ == i);
|
||||
auto state = EntryState{
|
||||
entries[i], selected() == i, is_selected, is_focused, i,
|
||||
std::string(entries[i]), selected() == i, is_selected, is_focused, i,
|
||||
};
|
||||
auto element =
|
||||
(transform ? transform : RadioboxOption::Simple().transform)(state);
|
||||
|
||||
Reference in New Issue
Block a user