From 96817ee672d509f867b2e9f5608ee3beaf7ff91e Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 1 Aug 2025 20:05:12 +0200 Subject: Use private and public instead of legacy LINK_ --- cli/component.cpp | 99 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 58 insertions(+), 41 deletions(-) (limited to 'cli/component.cpp') diff --git a/cli/component.cpp b/cli/component.cpp index 0419ad4..b33be7a 100644 --- a/cli/component.cpp +++ b/cli/component.cpp @@ -3,69 +3,86 @@ * 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/. */ -#include "component.hpp" +module; +#include #include -namespace katja -{ - PackageListBase::PackageListBase(const std::string& title, const std::vector& packages) - : title(title), packages(packages) - { - } +#include +#include +#include + +#include "katja/repository.hpp" + +export module component; - ftxui::Element PackageListBase::OnRender() +export namespace katja +{ + class PackageListBase : public ftxui::ComponentBase { - std::vector lines; + std::string title; + const std::vector packages; + std::optional selected; - 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()) + public: + PackageListBase(const std::string& title, const std::vector& packages = {}) + : title(title), packages(packages) { - 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 PackageListBase::OnEvent(ftxui::Event event) - { - if (event == ftxui::Event::ArrowDown) + ftxui::Element OnRender() override { - if (!this->selected.has_value() && !this->packages.empty()) + std::vector lines; + + for (const auto& package_identifier : this->packages) { - this->selected = std::make_optional(0); + auto line = ftxui::text(package_identifier.to_string()) | color(ftxui::Color::SkyBlue2); + lines.push_back(line); } - else if (this->selected.has_value() && this->selected.value() + 1 < this->packages.size()) + if (this->selected.has_value() && this->selected.value() < lines.size()) { - this->selected = std::make_optional(this->selected.value() + 1); + lines[this->selected.value()] |= ftxui::focus; } - return true; + std::stringstream summary; + + summary << title << '(' << packages.size() << ')'; + + return ftxui::window(ftxui::text(summary.str()), ftxui::vbox(lines) | ftxui::yframe); } - else if (event == ftxui::Event::ArrowUp) + + bool OnEvent(ftxui::Event event) override { - if (!this->selected.has_value() && !this->packages.empty()) + if (event == ftxui::Event::ArrowDown) { - this->selected = std::make_optional(0); + if (!this->selected.has_value() && !this->packages.empty()) + { + this->selected = std::make_optional(0); + } + else if (this->selected.has_value() && this->selected.value() + 1 < this->packages.size()) + { + this->selected = std::make_optional(this->selected.value() + 1); + } + return true; } - else if (this->selected.has_value() - && this->selected.value() < this->packages.size() - && this->selected.value() > 0) + else if (event == ftxui::Event::ArrowUp) { - this->selected = std::make_optional(this->selected.value() - 1); + if (!this->selected.has_value() && !this->packages.empty()) + { + this->selected = std::make_optional(0); + } + else if (this->selected.has_value() + && this->selected.value() < this->packages.size() + && this->selected.value() > 0) + { + this->selected = std::make_optional(this->selected.value() - 1); + } + return true; } - return true; + return false; } - return false; - } + }; - ftxui::Component PackageList(const std::string& title, const std::vector& packages) + ftxui::Component PackageList(const std::string& title, const std::vector& packages = {}) { return ftxui::Make(title, packages); } -- cgit v1.2.3