From db904920cc7b07b41e65beca82f036ff3bc2e826 Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Tue, 30 Jan 2024 14:09:07 +0100 Subject: [PATCH] Add packaging status icons Helps visually scan through large trees more quickly. Also introducing PackagingProgress. It allows splitting packging status analysis and visualization. This can be used in future to process the dependency tree and prune "uninteresting" parts before visualization. --- src/debian.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/tree.rs | 40 +++++++++++++++++++++----------------- 2 files changed, 76 insertions(+), 17 deletions(-) diff --git a/src/debian.rs b/src/debian.rs index 1bec3e3..917eb2e 100644 --- a/src/debian.rs +++ b/src/debian.rs @@ -23,6 +23,29 @@ pub struct Pkg { pub debinfo: Option, } +pub enum PackagingProgress { + Available, + AvailableInNew, + NeedsUpdate, + Missing, +} + +use std::fmt; + +impl fmt::Display for PackagingProgress { + //! Generate icons to display the packaging progress. + //! They should all take the same width when printed in a terminal + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let icon = match self { + PackagingProgress::Available => " ", + PackagingProgress::AvailableInNew => " N", + PackagingProgress::NeedsUpdate => "⌛", + PackagingProgress::Missing => "🔴", + }; + write!(f, "{}", icon) + } +} + impl Pkg { pub fn new(pkg: Package) -> Pkg { Pkg { @@ -57,6 +80,36 @@ impl Pkg { true } } + + pub fn packaging_status(&self) -> PackagingProgress { + if let Some(deb) = &self.debinfo { + if deb.in_unstable { + if deb.compatible { + // Available at an older yet compatible version + PackagingProgress::Available + } else if deb.outdated { + PackagingProgress::NeedsUpdate + } else { + PackagingProgress::Available + } + } else if deb.in_new { + if deb.compatible { + PackagingProgress::AvailableInNew + } else if deb.outdated { + // Outdated; in the NEW queue + PackagingProgress::NeedsUpdate + } else { + PackagingProgress::AvailableInNew + } + } else if deb.outdated { + PackagingProgress::NeedsUpdate + } else { + PackagingProgress::Missing + } + } else { + PackagingProgress::Missing + } + } } #[derive(Debug, Clone)] diff --git a/src/tree.rs b/src/tree.rs index 0b98677..8677b19 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -186,27 +186,33 @@ fn print_package<'a>( visited_deps: &mut HashSet<&'a PackageId>, levels_continue: &mut Vec, ) { - match prefix { - Prefix::Depth => print!("{}", levels_continue.len()), - Prefix::Indent => { - if let Some((last_continues, rest)) = levels_continue.split_last() { - for continues in rest { - let c = if *continues { symbols.down } else { " " }; - print!("{c} "); + let treeline = { + let mut line = "".to_string(); + line.push_str(&format!(" {} ", &package.packaging_status())); + match prefix { + Prefix::Depth => line.push_str(&format!("{}", levels_continue.len())), + Prefix::Indent => { + if let Some((last_continues, rest)) = levels_continue.split_last() { + for continues in rest { + let c = if *continues { symbols.down } else { " " }; + line.push_str(&format!("{c} ")); + } + + let c = if *last_continues { + symbols.tee + } else { + symbols.ell + }; + line.push_str(&format!("{0}{1}{1} ", c, symbols.right)); } - - let c = if *last_continues { - symbols.tee - } else { - symbols.ell - }; - print!("{0}{1}{1} ", c, symbols.right); } + Prefix::None => {} } - Prefix::None => {} - } + line + }; - println!("{}", format.display(package)); + let pkg_status_s = format.display(package).to_string(); + println!("{}{}", treeline, pkg_status_s); if !all && !package.show_dependencies() { return;