kazbek/cli/main.cpp

44 lines
1.5 KiB
C++

#include <filesystem>
#include <iostream>
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <ftxui/screen/string.hpp>
#include <toml.hpp>
#include "katja/sbo.hpp"
#include "katja/database.hpp"
int main(int argc, const char **argv)
{
auto configuration = toml::parse("config/katja.toml");
for (const auto& [repository_name, repository_value] : configuration.as_table())
{
std::multimap<std::string, katja::database_package> installed_database = katja::read_installed_database();
std::filesystem::path slackbuild_repository{ repository_value.at("path").as_string() };
katja::sbo_repository repository{ slackbuild_repository };
auto updates = repository.get_updates(installed_database);
std::vector<std::shared_ptr<ftxui::Node>> lines;
for (const auto& package_identifier : updates)
{
auto line = ftxui::text(package_identifier.to_string()) | color(ftxui::Color::SkyBlue2);
lines.push_back(line);
}
ftxui::Element summary = ftxui::text(" Updates (" + std::to_string(lines.size()) + ")");
auto document = ftxui::window(summary, ftxui::vbox(lines));
// Limit the size of the document to 80 char.
document = document | size(ftxui::WIDTH, ftxui::LESS_THAN, 80);
auto screen = ftxui::Screen::Create(ftxui::Dimension::Full(), ftxui::Dimension::Fit(document));
ftxui::Render(screen, document);
std::cout << screen.ToString() << '\0' << std::endl;
}
return EXIT_SUCCESS;
}