aboutsummaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/component.cpp47
-rw-r--r--cli/component.hpp9
-rw-r--r--cli/main.cpp2
3 files changed, 50 insertions, 8 deletions
diff --git a/cli/component.cpp b/cli/component.cpp
index db29052..ef93e87 100644
--- a/cli/component.cpp
+++ b/cli/component.cpp
@@ -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)
{
- return this->search_input->OnEvent(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;
}
}
diff --git a/cli/component.hpp b/cli/component.hpp
index 226e7f7..c419020 100644
--- a/cli/component.hpp
+++ b/cli/component.hpp
@@ -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;
diff --git a/cli/main.cpp b/cli/main.cpp
index f145905..aa0394b 100644
--- a/cli/main.cpp
+++ b/cli/main.cpp
@@ -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);