Skip to content

Commit

Permalink
feat: impl dpkg ProgressBar
Browse files Browse the repository at this point in the history
  • Loading branch information
eatradish committed Aug 17, 2024
1 parent 44c3aa7 commit d674d95
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
3 changes: 2 additions & 1 deletion oma-pm/src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ impl OmaAptInstallProgress {
debug!("Dpkg::Options:: is set to --force-all");
}

config.set("Dpkg::Use-Pty", "false");

if !is_terminal() || no_progress {
std::env::set_var("DEBIAN_FRONTEND", "noninteractive");
config.set("Dpkg::Use-Pty", "false");
}

if yes || force_yes || dpkg_force_all {
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn execute(
|count, event, total| {
let event = InstallPackageEvent::from(event);
if !no_progress {
pb!(event, mb, pb_map, count, total, global_is_set)
pb!(event, mb, pb_map, count, total, global_is_set);
} else {
handle_event_without_progressbar(event);
}
Expand Down
9 changes: 9 additions & 0 deletions src/subcommand/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ pub fn execute(
op,
) {
Ok(()) => {
if let Some(gpb) = pb_map.get(&0) {
gpb.finish_and_clear();
}
write_history_entry(
op_after,
typ,
Expand All @@ -171,6 +174,9 @@ pub fn execute(
OmaAptError::AptErrors(_)
| OmaAptError::AptError(_)
| OmaAptError::AptCxxException(_) => {
if let Some(gpb) = pb_map.get(&0) {
gpb.finish_and_clear();
}
if retry_times == 3 {
write_history_entry(
op_after,
Expand All @@ -196,6 +202,9 @@ pub fn execute(
retry_times += 1;
}
_ => {
if let Some(gpb) = pb_map.get(&0) {
gpb.finish_and_clear();
}
drop(fds);
return Err(OutputError::from(e));
}
Expand Down
6 changes: 5 additions & 1 deletion src/subcommand/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,18 @@ pub(crate) fn normal_commit(args: NormalCommitArgs, client: &Client) -> Result<(
&apt_args,
|count, event, total| {
if !no_progress {
pb!(event, mb, pb_map, count, total, global_is_set)
pb!(event, mb, pb_map, count, total, global_is_set);
} else {
handle_event_without_progressbar(event);
}
},
op,
);

if let Some(gpb) = pb_map.get(&0) {
gpb.finish_and_clear();
}

match res {
Ok(_) => {
success!("{}", fl!("history-tips-1"));
Expand Down
20 changes: 18 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,30 @@ macro_rules! pb {
if let Some(gpb) = $pb_map.get(&0) {
gpb.finish_and_clear();
}
$pb_map.remove(&0);
}
}
}
oma_pm::apt::InstallPackageEvent::DpkgEvent(event) => {
dbg!(event);
let gpb = $pb_map.get(&0);
if gpb.is_none() {
$global_is_set.store(true, std::sync::atomic::Ordering::SeqCst);
let sty =
oma_console::pb::oma_style_pb(oma_console::writer::Writer::default(), true);
let gpb = $mb.insert(
0,
oma_console::indicatif::ProgressBar::new(100).with_style(sty),
);
gpb.set_prefix("Progress");
gpb.set_position(event.percent);
$pb_map.insert(0, gpb);
return;
}
let gpb = gpb.unwrap();
gpb.set_position(event.percent);
}
oma_pm::apt::InstallPackageEvent::DpkgLine(line) => {
dbg!(line);
$mb.println(line).ok();
}
}

Expand Down

0 comments on commit d674d95

Please sign in to comment.