Skip to content

Commit

Permalink
Add packaging status icons
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
FedericoCeratto committed Jan 30, 2024
1 parent ada6cbb commit db90492
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 17 deletions.
53 changes: 53 additions & 0 deletions src/debian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,29 @@ pub struct Pkg {
pub debinfo: Option<DebianInfo>,
}

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 {
Expand Down Expand Up @@ -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)]
Expand Down
40 changes: 23 additions & 17 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,27 +186,33 @@ fn print_package<'a>(
visited_deps: &mut HashSet<&'a PackageId>,
levels_continue: &mut Vec<bool>,
) {
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;
Expand Down

0 comments on commit db90492

Please sign in to comment.