Skip to content

Commit faa544c

Browse files
committed
wip
1 parent 929d207 commit faa544c

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

cmd/soroban-cli/src/commands/snapshot/create.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ async fn get_history(
558558
.await
559559
.map_err(Error::ReadHistoryHttpStream)?;
560560

561+
print.clear_previous_line();
561562
print.globeln(format!("Downloaded history {}", &history_url));
562563

563564
serde_json::from_slice::<History>(&body).map_err(Error::JsonDecodingHistory)
@@ -616,6 +617,7 @@ async fn get_ledger_metadata_from_archive(
616617

617618
fs::rename(&dl_path, &cache_path).map_err(Error::RenameDownloadFile)?;
618619

620+
print.clear_previous_line();
619621
print.globeln(format!("Downloaded ledger headers for ledger {ledger}"));
620622

621623
// Now read the cached file
@@ -631,8 +633,6 @@ async fn get_ledger_metadata_from_archive(
631633
let close_time = header_entry.header.scp_value.close_time.0;
632634
let base_reserve = header_entry.header.base_reserve;
633635

634-
print.infoln(format!("Found ledger header for ledger {ledger}"));
635-
636636
return Ok((close_time, base_reserve));
637637
}
638638
}
@@ -655,7 +655,7 @@ async fn cache_bucket(
655655
let bucket_url =
656656
format!("{archive_url}/bucket/{bucket_0}/{bucket_1}/{bucket_2}/bucket-{bucket}.xdr.gz");
657657

658-
print.globe(format!("Downloading bucket {bucket_index} {bucket}…"));
658+
print.globeln(format!("Downloading bucket {bucket_index} {bucket}…"));
659659

660660
let bucket_url = Url::from_str(&bucket_url).map_err(Error::ParsingBucketUrl)?;
661661

@@ -671,15 +671,13 @@ async fn cache_bucket(
671671
}
672672

673673
if let Some(len) = response.content_length() {
674-
print.clear_line();
675-
print.globe(format!(
674+
print.clear_previous_line();
675+
print.globeln(format!(
676676
"Downloaded bucket {bucket_index} {bucket} ({})",
677677
ByteSize(len)
678678
));
679679
}
680680

681-
print.println("");
682-
683681
let stream = response
684682
.bytes_stream()
685683
.map(|result| result.map_err(std::io::Error::other));

cmd/soroban-cli/src/print.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::io::{self, Write};
12
use std::{env, fmt::Display};
23

34
use crate::xdr::{Error as XdrError, Transaction};
@@ -38,6 +39,18 @@ impl Print {
3839
}
3940
}
4041

42+
pub fn clear_previous_line(&self) {
43+
if !self.quiet {
44+
if cfg!(windows) {
45+
eprint!("\x1b[1A\x1b[2K\r");
46+
} else {
47+
// Move up one line, clear entire line, move to beginning
48+
eprint!("\x1b[1A\x1b[2K\r");
49+
}
50+
io::stderr().flush().unwrap();
51+
}
52+
}
53+
4154
// Some terminals like vscode's and macOS' default terminal will not render
4255
// the subsequent space if the emoji codepoints size is 2; in this case,
4356
// we need an additional space.

0 commit comments

Comments
 (0)