Skip to content

Commit 5be2aa2

Browse files
committed
feat(pb): use latency to render progress bar
1 parent 1774062 commit 5be2aa2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static HTTP_CLIENT: LazyLock<Client> = LazyLock::new(|| {
7575
});
7676
static WRITER: LazyLock<Writer> = LazyLock::new(Writer::default);
7777
static LOCK: OnceLock<PathBuf> = OnceLock::new();
78+
static LATENCY: OnceLock<Duration> = OnceLock::new();
7879

7980
#[derive(Debug, Args)]
8081
pub struct GlobalOptions {
@@ -526,6 +527,8 @@ fn init_color_formatter(oma: &OhManagerAilurus, config: &Config) {
526527
follow_term_color = true;
527528
} else if let Ok(latency) = termbg::latency(Duration::from_millis(1000)) {
528529
debug!("latency: {:?}", latency);
530+
LATENCY.set(latency).expect("LATENCY must no set.");
531+
529532
if latency * 2 > timeout {
530533
debug!(
531534
"Terminal latency is too long, falling back to default terminal colors, latency: {:?}.",

src/pb.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use oma_console::{
1515
use oma_fetch::{Event, SingleDownloadError};
1616
use reqwest::StatusCode;
1717

18-
use crate::{WRITER, error::Chain, fl, install_progress::osc94_progress, msg, utils::is_root};
18+
use crate::{
19+
LATENCY, WRITER, error::Chain, fl, install_progress::osc94_progress, msg, utils::is_root,
20+
};
1921
use crate::{color_formatter, error::OutputError};
2022
use oma_refresh::db::Event as RefreshEvent;
2123
use oma_utils::human_bytes::HumanBytes;
@@ -281,6 +283,12 @@ impl OmaMultiProgressBar {
281283
.insert(index + 1, ProgressBar::new(size).with_style(sty));
282284
let total_width = total_width(total);
283285
pb.set_message(format!("({:>total_width$}/{total}) {msg}", index + 1));
286+
pb.enable_steady_tick(
287+
LATENCY
288+
.get()
289+
.copied()
290+
.unwrap_or_else(|| Duration::from_millis(100)),
291+
);
284292
self.pb_map.insert(index + 1, pb);
285293
}
286294
Event::ProgressInc { index, size } => {
@@ -313,6 +321,12 @@ impl OmaMultiProgressBar {
313321
let pb = self
314322
.mb
315323
.insert(0, ProgressBar::new(total_size).with_style(sty));
324+
pb.enable_steady_tick(
325+
LATENCY
326+
.get()
327+
.copied()
328+
.unwrap_or_else(|| Duration::from_millis(100)),
329+
);
316330
self.pb_map.insert(0, pb);
317331
}
318332
Event::Failed { file_name, error } => {

0 commit comments

Comments
 (0)