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
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static HTTP_CLIENT: LazyLock<Client> = LazyLock::new(|| {
});
static WRITER: LazyLock<Writer> = LazyLock::new(Writer::default);
static LOCK: OnceLock<PathBuf> = OnceLock::new();
static LATENCY: OnceLock<Duration> = OnceLock::new();

#[derive(Debug, Args)]
pub struct GlobalOptions {
Expand Down Expand Up @@ -526,6 +527,8 @@ fn init_color_formatter(oma: &OhManagerAilurus, config: &Config) {
follow_term_color = true;
} else if let Ok(latency) = termbg::latency(Duration::from_millis(1000)) {
debug!("latency: {:?}", latency);
LATENCY.set(latency).expect("LATENCY must no set.");

if latency * 2 > timeout {
debug!(
"Terminal latency is too long, falling back to default terminal colors, latency: {:?}.",
Expand Down
16 changes: 15 additions & 1 deletion src/pb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use oma_console::{
use oma_fetch::{Event, SingleDownloadError};
use reqwest::StatusCode;

use crate::{WRITER, error::Chain, fl, install_progress::osc94_progress, msg, utils::is_root};
use crate::{
LATENCY, WRITER, error::Chain, fl, install_progress::osc94_progress, msg, utils::is_root,
};
use crate::{color_formatter, error::OutputError};
use oma_refresh::db::Event as RefreshEvent;
use oma_utils::human_bytes::HumanBytes;
Expand Down Expand Up @@ -281,6 +283,12 @@ impl OmaMultiProgressBar {
.insert(index + 1, ProgressBar::new(size).with_style(sty));
let total_width = total_width(total);
pb.set_message(format!("({:>total_width$}/{total}) {msg}", index + 1));
pb.enable_steady_tick(
LATENCY
.get()
.copied()
.unwrap_or_else(|| Duration::from_millis(100)),
);
self.pb_map.insert(index + 1, pb);
}
Event::ProgressInc { index, size } => {
Expand Down Expand Up @@ -313,6 +321,12 @@ impl OmaMultiProgressBar {
let pb = self
.mb
.insert(0, ProgressBar::new(total_size).with_style(sty));
pb.enable_steady_tick(
LATENCY
.get()
.copied()
.unwrap_or_else(|| Duration::from_millis(100)),
);
self.pb_map.insert(0, pb);
}
Event::Failed { file_name, error } => {
Expand Down
Loading