Skip to content
Draft
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
8 changes: 6 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ pub struct Colors {
pub error: Style,
pub warning: Style,
pub bold: Style,
pub upgrade: Style,
pub upgrade_major: Style,
pub upgrade_minor: Style,
pub upgrade_patch: Style,
//pub base: Style,
pub action: Style,
pub sl_repo: Style,
Expand Down Expand Up @@ -119,7 +121,9 @@ impl Colors {
error: Style::new().fg(Red),
warning: Style::new().fg(Yellow),
bold: Style::new().bold(),
upgrade: Style::new().fg(Green).bold(),
upgrade_major: Style::new().fg(Purple).bold(),
upgrade_minor: Style::new().fg(Green).bold(),
upgrade_patch: Style::new().fg(Cyan).bold(),
//base: Style::new().fg(Blue),
action: Style::new().fg(Blue).bold(),
sl_repo: Style::new().fg(Purple).bold(),
Expand Down
58 changes: 52 additions & 6 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,63 @@ pub async fn print_upgrade_list(config: &mut Config) -> Result<i32> {
}

fn print_upgrade(config: &Config, name: &str, local_ver: &str, new_ver: &str) {
let bold = config.color.bold;
let upgrade = config.color.upgrade;

if config.args.has_arg("q", "quiet") {
println!("{}", name);
} else {
let mut br = 0;
let mut dots = 0;
let mut n = 0;
let mut pkgver_match = false;

let mut local_ver_iter = local_ver.chars();
let mut new_ver_iter = new_ver.chars();
while let Some(local) = local_ver_iter.next() {
if let Some(new) = new_ver_iter.next() {
if local != new {
break;
}
n += local.len_utf8();
match local {
'.' => {
dots += 1;
br = n;
}
':' => {
br = n;
}
'-' => {
pkgver_match = true;
br = n;
break;
}
_ => {}
}
} else {
break;
}
}

let (common_ver, local_diff) = local_ver.split_at(br);
let (_, new_diff) = new_ver.split_at(br);

let bold = config.color.bold;
let upgrade = if pkgver_match {
config.color.bold
} else {
match dots {
0 => config.color.upgrade_major,
1 => config.color.upgrade_minor,
_ => config.color.upgrade_patch,
}
};

print!(
"{} {} -> {}",
"{} {}{} -> {}{}",
bold.paint(name),
upgrade.paint(local_ver),
upgrade.paint(new_ver)
common_ver,
upgrade.paint(local_diff),
common_ver,
upgrade.paint(new_diff)
);
if config.alpm.localdb().pkg(name).unwrap().should_ignore() {
print!("{}", tr!(" [ignored]"));
Expand Down