diff options
| author | pablu <me@pablu.de> | 2026-05-07 13:07:32 +0200 |
|---|---|---|
| committer | pablu <me@pablu.de> | 2026-05-07 13:07:32 +0200 |
| commit | cc8e924ce828d237d7cdd245b794c532a4ee80d8 (patch) | |
| tree | 5fc7c118879eb0107fe20a12ff6c3096a3a36926 /src/app.rs | |
| parent | 3346222550bc18edc457d9b509f00d0eba9d0f4f (diff) | |
working search
Diffstat (limited to 'src/app.rs')
| -rw-r--r-- | src/app.rs | 32 |
1 files changed, 30 insertions, 2 deletions
@@ -1,24 +1,52 @@ use ratatui::widgets::ListState; +use ratatui_textarea::TextArea; use crate::gentoo::{Package, portage::Portage}; #[derive(Debug)] #[allow(dead_code)] -pub struct App { +pub struct App<'a> { portage: Portage, pub list_state: ListState, + pub showing_search_window: bool, + pub textarea: TextArea<'a>, + pub search_found: Option<bool>, } #[allow(dead_code)] -impl App { +impl<'a> App<'a> { pub fn new(portage: Portage) -> Self { App { portage, list_state: ListState::default().with_selected(Some(0)), + showing_search_window: false, + textarea: TextArea::default(), + search_found: None, } } pub fn installed_packages(&self) -> Vec<Package> { self.portage.installed_packages.clone() } + + pub fn toggle_search_window(&mut self) { + self.showing_search_window = !self.showing_search_window; + self.textarea.clear(); + self.search_found = None; + } + + pub fn search(&mut self) -> bool { + let index = self.portage.installed_packages.iter().position(|s| { + s.name + .to_lowercase() + .contains(&self.textarea.lines()[0].to_lowercase()) + }); + + if let Some(index) = index { + self.list_state.select(Some(index)); + return true; + } + + return false; + } } |
