katja: Load updatable list on demand
This commit is contained in:
parent
de94f3d355
commit
68f64f20dd
@ -32,18 +32,30 @@ namespace katja
|
||||
|
||||
bool ScreenContainer::OnEvent(ftxui::Event event)
|
||||
{
|
||||
if (event.character() == "q" && this->on_enter)
|
||||
if (event == ftxui::Event::CtrlQ && this->on_enter)
|
||||
{
|
||||
on_enter();
|
||||
return true;
|
||||
}
|
||||
int previously = this->menu_selected;
|
||||
bool result = menu->OnEvent(event);
|
||||
bool result{ false };
|
||||
|
||||
if (event == ftxui::Event::CtrlP)
|
||||
{
|
||||
result = menu->OnEvent(ftxui::Event::ArrowLeft);
|
||||
}
|
||||
else if (event == ftxui::Event::CtrlN)
|
||||
{
|
||||
result = menu->OnEvent(ftxui::Event::ArrowRight);
|
||||
}
|
||||
if (previously != this->menu_selected)
|
||||
{
|
||||
this->menu_pages.at(this->menu_selected)->Load();
|
||||
}
|
||||
if (!result)
|
||||
{
|
||||
result = this->menu_pages.at(this->menu_selected)->OnEvent(event);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -61,13 +73,14 @@ namespace katja
|
||||
{
|
||||
}
|
||||
|
||||
UpdatesPage::UpdatesPage(std::vector<package_identifier>&& updatable)
|
||||
: updatable(std::move(updatable))
|
||||
UpdatesPage::UpdatesPage(std::shared_ptr<struct repository> repository, package_database database)
|
||||
: repository(repository), database(database)
|
||||
{
|
||||
}
|
||||
|
||||
void UpdatesPage::Load()
|
||||
{
|
||||
this->updatable = repository->get_updates(this->database);
|
||||
}
|
||||
|
||||
ftxui::Element UpdatesPage::OnRender()
|
||||
@ -87,4 +100,18 @@ namespace katja
|
||||
void SearchPage::Load()
|
||||
{
|
||||
}
|
||||
|
||||
ftxui::Element SearchPage::OnRender()
|
||||
{
|
||||
return ftxui::vbox({
|
||||
ftxui::hbox({
|
||||
this->search_input->Render()
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
bool SearchPage::OnEvent(ftxui::Event event)
|
||||
{
|
||||
return this->search_input->OnEvent(event);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <ftxui/component/component.hpp>
|
||||
|
||||
#include "katja/repository.hpp"
|
||||
#include "katja/database.hpp"
|
||||
|
||||
namespace katja
|
||||
{
|
||||
@ -45,9 +46,11 @@ namespace katja
|
||||
class UpdatesPage final : public PageBase
|
||||
{
|
||||
std::vector<package_identifier> updatable;
|
||||
std::shared_ptr<struct repository> repository;
|
||||
package_database database;
|
||||
|
||||
public:
|
||||
explicit UpdatesPage(std::vector<package_identifier>&& updatable);
|
||||
UpdatesPage(std::shared_ptr<struct repository> repository, package_database database);
|
||||
|
||||
void Load() override;
|
||||
ftxui::Element OnRender() override;
|
||||
@ -55,7 +58,12 @@ namespace katja
|
||||
|
||||
class SearchPage final : public PageBase
|
||||
{
|
||||
std::string needle;
|
||||
ftxui::Component search_input = ftxui::Input(&this->needle, "Search");
|
||||
|
||||
public:
|
||||
void Load() override;
|
||||
ftxui::Element OnRender() override;
|
||||
bool OnEvent(ftxui::Event event) override;
|
||||
};
|
||||
}
|
||||
|
11
cli/main.cpp
11
cli/main.cpp
@ -11,20 +11,19 @@
|
||||
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();
|
||||
katja::package_database installed_database = katja::read_installed_database();
|
||||
|
||||
for (const auto& [repository_name, repository_value] : configuration.as_table())
|
||||
{
|
||||
std::filesystem::path slackbuild_repository{ repository_value.at("path").as_string() };
|
||||
katja::sbo_repository repository{ slackbuild_repository };
|
||||
auto updates = repository.get_updates(installed_database);
|
||||
auto repository = std::make_shared<katja::sbo_repository>(slackbuild_repository);
|
||||
|
||||
auto screen = ftxui::ScreenInteractive::Fullscreen();
|
||||
|
||||
auto container = Screen(std::vector<std::pair<std::string, katja::Page>>{
|
||||
{ "Home", std::make_shared<katja::WelcomePage>() },
|
||||
{ "Updates", std::make_shared<katja::UpdatesPage>(std::move(updates)) },
|
||||
{ "Search", std::make_shared<katja::SearchPage>() }
|
||||
{ "Home", ftxui::Make<katja::WelcomePage>() },
|
||||
{ "Updates", ftxui::Make<katja::UpdatesPage>(repository, std::move(installed_database)) },
|
||||
{ "Search", ftxui::Make<katja::SearchPage>() }
|
||||
}, screen.ExitLoopClosure());
|
||||
|
||||
screen.Loop(container);
|
||||
|
@ -82,9 +82,9 @@ namespace katja
|
||||
return package_string;
|
||||
}
|
||||
|
||||
std::multimap<std::string, database_package> read_installed_database()
|
||||
package_database read_installed_database()
|
||||
{
|
||||
std::multimap<std::string, database_package> result;
|
||||
package_database result;
|
||||
|
||||
for (const auto& entry : std::filesystem::directory_iterator(katja::database))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user