diff --git a/.gitignore b/.gitignore index 1c6e0ce..6a90160 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /dist-newstyle/ -/config/tea-cleaner.toml +/config/*.toml /log/ /tmp/ CMakeCache.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index aef0836..129351e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 11f92ce..11dd7a0 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -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) diff --git a/cli/main.cpp b/cli/main.cpp index c257dbd..788f620 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -1,24 +1,43 @@ #include #include +#include +#include +#include +#include + #include "katja/sbo.hpp" #include "katja/database.hpp" int main(int argc, const char **argv) { - std::multimap installed_database = katja::read_installed_database(); + auto configuration = toml::parse("config/katja.toml"); - if (argc > 1) + for (const auto& [repository_name, repository_value] : configuration.as_table()) { - std::filesystem::path slackbuild_repository{ argv[1] }; + std::multimap 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> 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; } diff --git a/config/katja.conf.dist b/config/katja.conf.dist new file mode 100644 index 0000000..560e898 --- /dev/null +++ b/config/katja.conf.dist @@ -0,0 +1,2 @@ +[sbo] +path = "/home/path/to/local/repository"