summaryrefslogtreecommitdiff
path: root/cli/component.cpp
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2025-08-01 20:05:12 +0200
committerEugen Wissner <belka@caraus.de>2025-08-01 20:05:12 +0200
commit96817ee672d509f867b2e9f5608ee3beaf7ff91e (patch)
tree10955534faa627f002259fb2ac5eae0b15384fd4 /cli/component.cpp
parentc1367e494e195999fc3e868ca16df2037ac6899a (diff)
downloadkatja-96817ee672d509f867b2e9f5608ee3beaf7ff91e.tar.gz
Use private and public instead of legacy LINK_
Diffstat (limited to 'cli/component.cpp')
-rw-r--r--cli/component.cpp99
1 files changed, 58 insertions, 41 deletions
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 <optional>
#include <sstream>
-namespace katja
-{
- PackageListBase::PackageListBase(const std::string& title, const std::vector<package_identifier>& packages)
- : title(title), packages(packages)
- {
- }
+#include <ftxui/component/event.hpp>
+#include <ftxui/component/component.hpp>
+#include <ftxui/dom/elements.hpp>
+
+#include "katja/repository.hpp"
+
+export module component;
- ftxui::Element PackageListBase::OnRender()
+export namespace katja
+{
+ class PackageListBase : public ftxui::ComponentBase
{
- std::vector<ftxui::Element> lines;
+ std::string title;
+ const std::vector<package_identifier> packages;
+ std::optional<std::size_t> 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<package_identifier>& 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<ftxui::Element> lines;
+
+ for (const auto& package_identifier : this->packages)
{
- this->selected = std::make_optional<std::size_t>(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<std::size_t>(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<std::size_t>(0);
+ 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 (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<std::size_t>(this->selected.value() - 1);
+ 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 true;
+ return false;
}
- return false;
- }
+ };
- ftxui::Component PackageList(const std::string& title, const std::vector<package_identifier>& packages)
+ ftxui::Component PackageList(const std::string& title, const std::vector<package_identifier>& packages = {})
{
return ftxui::Make<PackageListBase>(title, packages);
}