Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add packaging status icons #37

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading