katja: Make an interactive loop
This commit is contained in:
parent
7906bd3ecb
commit
86ea47342b
@ -14,12 +14,13 @@ FetchContent_Declare(toml11
|
||||
)
|
||||
FetchContent_MakeAvailable(toml11)
|
||||
|
||||
add_executable(katja-cli main.cpp)
|
||||
add_executable(katja-cli main.cpp component.hpp component.cpp)
|
||||
target_include_directories(katja-cli PRIVATE ${Boost_INCLUDE_DIR})
|
||||
target_link_libraries(katja-cli
|
||||
LINK_PUBLIC katja
|
||||
LINK_PRIVATE ftxui::screen
|
||||
LINK_PRIVATE ftxui::dom
|
||||
LINK_PRIVATE ftxui::component
|
||||
LINK_PRIVATE toml11::toml11
|
||||
)
|
||||
set_target_properties(katja-cli PROPERTIES RUNTIME_OUTPUT_NAME katja)
|
||||
|
0
cli/component.cpp
Normal file
0
cli/component.cpp
Normal file
33
cli/component.hpp
Normal file
33
cli/component.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <ftxui/component/component_base.hpp>
|
||||
|
||||
#include "katja/repository.hpp"
|
||||
|
||||
namespace katja
|
||||
{
|
||||
class UpdatesPage : public ftxui::ComponentBase
|
||||
{
|
||||
std::vector<package_identifier> updatable;
|
||||
|
||||
public:
|
||||
explicit UpdatesPage(std::vector<package_identifier>&& updatable)
|
||||
: updatable(std::move(updatable))
|
||||
{
|
||||
}
|
||||
|
||||
ftxui::Element Render() override
|
||||
{
|
||||
std::vector<std::shared_ptr<ftxui::Node>> lines;
|
||||
|
||||
for (const auto& package_identifier : this->updatable)
|
||||
{
|
||||
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()) + ")");
|
||||
|
||||
return ftxui::window(summary, ftxui::vbox(lines));
|
||||
}
|
||||
};
|
||||
}
|
41
cli/main.cpp
41
cli/main.cpp
@ -1,43 +1,42 @@
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
||||
#include <ftxui/component/component.hpp>
|
||||
#include <ftxui/component/screen_interactive.hpp>
|
||||
#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"
|
||||
#include "component.hpp"
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
auto configuration = toml::parse("config/katja.toml");
|
||||
std::multimap<std::string, katja::database_package> installed_database = katja::read_installed_database();
|
||||
|
||||
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;
|
||||
auto screen = ftxui::ScreenInteractive::Fullscreen();
|
||||
std::vector<std::string> menu_entries = {
|
||||
"Updates",
|
||||
"Search",
|
||||
"Quit"
|
||||
};
|
||||
int menu_selected = 0;
|
||||
ftxui::MenuOption menu_option = ftxui::MenuOption::Horizontal();
|
||||
menu_option.on_enter = screen.ExitLoopClosure();
|
||||
ftxui::Component menu = ftxui::Menu(&menu_entries, &menu_selected, menu_option);
|
||||
|
||||
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;
|
||||
auto custom_component = std::make_shared<katja::UpdatesPage>(std::move(updates));
|
||||
ftxui::Component renderer = ftxui::Container::Vertical({
|
||||
menu,
|
||||
custom_component
|
||||
});
|
||||
screen.Loop(renderer);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user