katja: Add TUI and TOML libraries

This commit is contained in:
Eugen Wissner 2025-03-22 20:32:47 +01:00
parent 9bec46cc1f
commit 69bf515582
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
5 changed files with 51 additions and 8 deletions

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
/dist-newstyle/
/config/tea-cleaner.toml
/config/*.toml
/log/
/tmp/
CMakeCache.txt

View File

@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.21)
project(Katja)
include(CTest)
include(FetchContent)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

View File

@ -1,4 +1,25 @@
FetchContent_Declare(ftxui
GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
GIT_TAG v5.0.0
GIT_PROGRESS TRUE
GIT_SHALLOW TRUE
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(ftxui)
FetchContent_Declare(toml11
GIT_REPOSITORY https://github.com/ToruNiina/toml11.git
GIT_TAG v4.4.0
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(toml11)
add_executable(katja-cli main.cpp)
target_include_directories(katja-cli PRIVATE ${Boost_INCLUDE_DIR})
target_link_libraries(katja-cli LINK_PUBLIC katja)
target_link_libraries(katja-cli
LINK_PUBLIC katja
LINK_PRIVATE ftxui::screen
LINK_PRIVATE ftxui::dom
LINK_PRIVATE toml11::toml11
)
set_target_properties(katja-cli PROPERTIES RUNTIME_OUTPUT_NAME katja)

View File

@ -1,24 +1,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();
if (argc > 1)
{
std::filesystem::path slackbuild_repository{ argv[1] };
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)
{
std::cout << package_identifier.to_string() << std::endl;
auto line = ftxui::text(package_identifier.to_string()) | color(ftxui::Color::SkyBlue2);
lines.push_back(line);
}
std::cout << "SlackBuilds found: " << updates.size() << std::endl;
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 0;
return EXIT_SUCCESS;
}

2
config/katja.conf.dist Normal file
View File

@ -0,0 +1,2 @@
[sbo]
path = "/home/path/to/local/repository"