diff options
| author | pablu <me@pablu.de> | 2026-06-03 14:10:49 +0200 |
|---|---|---|
| committer | pablu <me@pablu.de> | 2026-06-03 14:10:49 +0200 |
| commit | eaa1b915da8480bf3a86960c94f3667f386aa0f4 (patch) | |
| tree | b85e1d2edb0a507ba480926d12fab074d52bb961 /src/gentoo | |
| parent | 81cc9a0b347255629d411323e7ff8fee4d5ec61d (diff) | |
wip: browser screen implementation
Diffstat (limited to 'src/gentoo')
| -rw-r--r-- | src/gentoo/package.rs | 24 | ||||
| -rw-r--r-- | src/gentoo/portage.rs | 19 |
2 files changed, 37 insertions, 6 deletions
diff --git a/src/gentoo/package.rs b/src/gentoo/package.rs index 1d41b8c..fcd86eb 100644 --- a/src/gentoo/package.rs +++ b/src/gentoo/package.rs @@ -4,12 +4,34 @@ use chrono::{DateTime, Utc}; use crate::gentoo::UseFlag; -#[derive(Debug, Clone, Hash, Eq, PartialEq)] +#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)] pub struct PackageKey { + // Field declaration matters because Ord, and PartialOrd check in order pub category: String, pub name: String, } +// impl Ord for PackageKey { +// fn cmp(&self, other: &Self) -> std::cmp::Ordering { +// let cat_ord = self.category.cmp(&other.category); +// if cat_ord == Ordering::Equal { +// return self.name.cmp(&other.name); +// } +// +// cat_ord +// } +// } +// +// impl PartialOrd for PackageKey { +// fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { +// match self.category.partial_cmp(&other.category) { +// Some(core::cmp::Ordering::Equal) => {} +// ord => return ord, +// } +// self.name.partial_cmp(&other.name) +// } +// } + impl PackageKey { pub fn from_atom(s: &str) -> Option<Self> { let (category, name) = s.split_once('/')?; diff --git a/src/gentoo/portage.rs b/src/gentoo/portage.rs index 935c1ce..6a1b797 100644 --- a/src/gentoo/portage.rs +++ b/src/gentoo/portage.rs @@ -41,16 +41,25 @@ impl Portage { .collect() } - pub fn get_installed_package(&self, index: usize) -> Option<&InstalledPackage> { - if self.installed.len() > index && index > 0 { - return Some(&self.installed[index]); + pub fn get_installed_package(&self, key: &PackageKey) -> Option<&InstalledPackage> { + let pkg = self.installed.iter().find(|pkg| pkg.atom == *key); + if let Some(pkg) = pkg { + return Some(pkg); } None } - pub fn get_installed_package_key(&self, key: &PackageKey) -> Option<&InstalledPackage> { - let pkg = self.installed.iter().find(|pkg| pkg.atom == *key); + pub fn available_packages(&self) -> Vec<&Package> { + let mut pkg: Vec<&Package> = self.available.iter().collect(); + + pkg.sort_by_key(|p| &p.atom); + + pkg + } + + pub fn get_available_package(&self, key: &PackageKey) -> Option<&Package> { + let pkg = self.available.iter().find(|pkg| pkg.atom == *key); if let Some(pkg) = pkg { return Some(pkg); } |
