diff options
| author | Eugen Wissner <belka@caraus.de> | 2025-04-11 21:45:05 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2025-04-11 21:45:05 +0200 |
| commit | 5a4c882d409e4051001cdd64cbcef9a98fc2c6cf (patch) | |
| tree | 426ff146466b72573dafe35850c114498cfbd4ee /cli/component.cpp | |
| parent | 68f64f20dd2f827f6076ec02d3eaa8961fd12022 (diff) | |
| download | kazbek-5a4c882d409e4051001cdd64cbcef9a98fc2c6cf.tar.gz | |
Katja: Allow the search by name in the TUI
Diffstat (limited to 'cli/component.cpp')
| -rw-r--r-- | cli/component.cpp | 47 |
1 files changed, 41 insertions, 6 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; } } |
