Skip to content

Commit b28da56

Browse files
author
Ludo Galabru
committed
fix: improve progress bar
1 parent 3c8ed28 commit b28da56

File tree

1 file changed

+14
-8
lines changed
  • components/hord-cli/src/archive

1 file changed

+14
-8
lines changed

components/hord-cli/src/archive/mod.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn default_sqlite_sha_file_path(_network: &BitcoinNetwork) -> String {
1818
format!("hord.sqlite.sha256").to_lowercase()
1919
}
2020

21-
pub async fn download_sqlite_file(config: &Config, ctx: &Context) -> Result<(), String> {
21+
pub async fn download_sqlite_file(config: &Config, _ctx: &Context) -> Result<(), String> {
2222
let mut destination_path = config.expected_cache_path();
2323
std::fs::create_dir_all(&destination_path).unwrap_or_else(|e| {
2424
println!("{}", e.to_string());
@@ -61,12 +61,13 @@ pub async fn download_sqlite_file(config: &Config, ctx: &Context) -> Result<(),
6161
});
6262

6363
if res.status() == reqwest::StatusCode::OK {
64-
let mut progress_bar = MappingBar::with_range(0i64, 4_800_001_704);
65-
progress_bar.set_len(40);
66-
info!(
67-
ctx.expect_logger(),
64+
let mut progress_bar = MappingBar::with_range(0i64, 5_400_000_000);
65+
progress_bar.set_len(60);
66+
let mut stdout = std::io::stdout();
67+
print!(
6868
"{}", progress_bar
6969
);
70+
let _ = stdout.flush();
7071
let mut stream = res.bytes_stream();
7172
let mut progress = 0;
7273
while let Some(item) = stream.next().await {
@@ -75,15 +76,20 @@ pub async fn download_sqlite_file(config: &Config, ctx: &Context) -> Result<(),
7576
progress_bar.set(progress);
7677
if progress_bar.has_progressed_significantly() {
7778
progress_bar.remember_significant_progress();
78-
info!(
79-
ctx.expect_logger(),
80-
"{}", progress_bar
79+
print!(
80+
"\r{}", progress_bar
8181
);
82+
let _ = stdout.flush();
8283
}
8384
tx.send_async(chunk.to_vec())
8485
.await
8586
.map_err(|e| format!("unable to download stacks event: {}", e.to_string()))?;
8687
}
88+
print!(
89+
"\r"
90+
);
91+
let _ = stdout.flush();
92+
println!();
8793
drop(tx);
8894
}
8995

0 commit comments

Comments
 (0)