Katja: Allow the search by name in the TUI
This commit is contained in:
		@@ -66,7 +66,7 @@ namespace katja
 | 
			
		||||
 | 
			
		||||
    ftxui::Element WelcomePage::OnRender()
 | 
			
		||||
    {
 | 
			
		||||
        return ftxui::text("Select an action in the menu.");
 | 
			
		||||
        return ftxui::paragraph("Select an action in the menu.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void WelcomePage::Load()
 | 
			
		||||
@@ -85,7 +85,7 @@ namespace katja
 | 
			
		||||
 | 
			
		||||
    ftxui::Element UpdatesPage::OnRender()
 | 
			
		||||
    {
 | 
			
		||||
        std::vector<std::shared_ptr<ftxui::Node>> lines;
 | 
			
		||||
        std::vector<ftxui::Element> lines;
 | 
			
		||||
 | 
			
		||||
        for (const auto& package_identifier : this->updatable)
 | 
			
		||||
        {
 | 
			
		||||
@@ -97,21 +97,56 @@ namespace katja
 | 
			
		||||
        return ftxui::window(summary, ftxui::vbox(lines));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SearchPage::SearchPage(std::shared_ptr<struct repository> repository, const std::string& architecture)
 | 
			
		||||
        : repository(repository), architecture(architecture)
 | 
			
		||||
    {
 | 
			
		||||
        ftxui::InputOption search_input_option = { .multiline = false };
 | 
			
		||||
        this->search_input = ftxui::Input(&this->needle, "Search", search_input_option);
 | 
			
		||||
        this->type_input = ftxui::Radiobox(std::vector<std::string>{ "Names", "Description" }, &this->search_type);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void SearchPage::Load()
 | 
			
		||||
    {
 | 
			
		||||
        this->needle.erase();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ftxui::Element SearchPage::OnRender()
 | 
			
		||||
    {
 | 
			
		||||
        std::vector<ftxui::Element> lines;
 | 
			
		||||
 | 
			
		||||
        for (const auto& package_identifier : this->search_results)
 | 
			
		||||
        {
 | 
			
		||||
            auto line = ftxui::text(package_identifier.to_string()) | color(ftxui::Color::SkyBlue2);
 | 
			
		||||
            lines.push_back(line);
 | 
			
		||||
        }
 | 
			
		||||
        ftxui::FlexboxConfig config;
 | 
			
		||||
        config.justify_content = ftxui::FlexboxConfig::JustifyContent::FlexStart;
 | 
			
		||||
        config.align_items = ftxui::FlexboxConfig::AlignItems::FlexStart;
 | 
			
		||||
        config.direction = ftxui::FlexboxConfig::Direction::Row;
 | 
			
		||||
 | 
			
		||||
        return ftxui::vbox({
 | 
			
		||||
            ftxui::hbox({
 | 
			
		||||
                this->search_input->Render()
 | 
			
		||||
            })
 | 
			
		||||
            ftxui::flexbox({
 | 
			
		||||
                this->search_input->Render(),
 | 
			
		||||
                ftxui::window(ftxui::text("Search in"), type_input->Render())
 | 
			
		||||
            }, config),
 | 
			
		||||
            ftxui::vbox(lines)
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool SearchPage::OnEvent(ftxui::Event event)
 | 
			
		||||
    {
 | 
			
		||||
        if (event == ftxui::Event::Return)
 | 
			
		||||
        {
 | 
			
		||||
            if (!this->needle.empty())
 | 
			
		||||
            {
 | 
			
		||||
                this->search_results = this->repository->search_names(this->architecture, this->needle);
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            return this->search_input->OnEvent(event);
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -59,9 +59,16 @@ namespace katja
 | 
			
		||||
    class SearchPage final : public PageBase
 | 
			
		||||
    {
 | 
			
		||||
        std::string needle;
 | 
			
		||||
        ftxui::Component search_input = ftxui::Input(&this->needle, "Search");
 | 
			
		||||
        ftxui::Component search_input;
 | 
			
		||||
        ftxui::Component type_input;
 | 
			
		||||
        std::shared_ptr<struct repository> repository;
 | 
			
		||||
        std::string architecture;
 | 
			
		||||
        std::vector<package_identifier> search_results;
 | 
			
		||||
        int search_type{ 0 };
 | 
			
		||||
 | 
			
		||||
    public:
 | 
			
		||||
        SearchPage(std::shared_ptr<struct repository> repository, const std::string& architecture);
 | 
			
		||||
 | 
			
		||||
        void Load() override;
 | 
			
		||||
        ftxui::Element OnRender() override;
 | 
			
		||||
        bool OnEvent(ftxui::Event event) override;
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,7 @@ int main(int argc, const char **argv)
 | 
			
		||||
        auto container = Screen(std::vector<std::pair<std::string, katja::Page>>{
 | 
			
		||||
            { "Home", ftxui::Make<katja::WelcomePage>() },
 | 
			
		||||
            { "Updates", ftxui::Make<katja::UpdatesPage>(repository, std::move(installed_database)) },
 | 
			
		||||
            { "Search", ftxui::Make<katja::SearchPage>() }
 | 
			
		||||
            { "Search", ftxui::Make<katja::SearchPage>(repository, "x86-64") }
 | 
			
		||||
        }, screen.ExitLoopClosure());
 | 
			
		||||
 | 
			
		||||
        screen.Loop(container);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user