aboutsummaryrefslogtreecommitdiff
path: root/cli/main.cpp
blob: 788f62071a150d9b3c1e09e881ff58c7986717c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#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;
}