diff options
Diffstat (limited to 'cli/component.cpp')
| -rw-r--r-- | cli/component.cpp | 89 |
1 files changed, 0 insertions, 89 deletions
diff --git a/cli/component.cpp b/cli/component.cpp deleted file mode 100644 index 6735077..0000000 --- a/cli/component.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ -module; - -#include <optional> -#include <sstream> - -#include <ftxui/component/event.hpp> -#include <ftxui/component/component.hpp> -#include <ftxui/dom/elements.hpp> - -import katja.repository; - -export module katja.component; - -export namespace katja -{ - class PackageListBase : public ftxui::ComponentBase - { - std::string title; - const std::vector<package_identifier> packages; - std::optional<std::size_t> selected; - - public: - PackageListBase(const std::string& title, const std::vector<package_identifier>& packages = {}) - : title(title), packages(packages) - { - } - - ftxui::Element OnRender() override - { - std::vector<ftxui::Element> lines; - - for (const auto& package_identifier : this->packages) - { - auto line = ftxui::text(package_identifier.to_string()) | color(ftxui::Color::SkyBlue2); - lines.push_back(line); - } - if (this->selected.has_value() && this->selected.value() < lines.size()) - { - lines[this->selected.value()] |= ftxui::focus; - } - std::stringstream summary; - - summary << title << '(' << packages.size() << ')'; - - return ftxui::window(ftxui::text(summary.str()), ftxui::vbox(lines) | ftxui::yframe); - } - - bool OnEvent(ftxui::Event event) override - { - if (event == ftxui::Event::ArrowDown) - { - if (!this->selected.has_value() && !this->packages.empty()) - { - this->selected = std::make_optional<std::size_t>(0); - } - else if (this->selected.has_value() && this->selected.value() + 1 < this->packages.size()) - { - this->selected = std::make_optional<std::size_t>(this->selected.value() + 1); - } - return true; - } - else if (event == ftxui::Event::ArrowUp) - { - if (!this->selected.has_value() && !this->packages.empty()) - { - this->selected = std::make_optional<std::size_t>(0); - } - else if (this->selected.has_value() - && this->selected.value() < this->packages.size() - && this->selected.value() > 0) - { - this->selected = std::make_optional<std::size_t>(this->selected.value() - 1); - } - return true; - } - return false; - } - }; - - ftxui::Component PackageList(const std::string& title, const std::vector<package_identifier>& packages = {}) - { - return ftxui::Make<PackageListBase>(title, packages); - } -} |
