From 441bcfe1a41a3a3b150bb9ad4eeeef9ecb434cca Mon Sep 17 00:00:00 2001 From: dcodesdev <101001810+dcodesdev@users.noreply.github.com> Date: Sat, 11 May 2024 14:52:20 +0300 Subject: [PATCH] progress bar --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/scp.rs | 13 +++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e3c42d2..8ee04dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -211,7 +211,7 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "fast-scp" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 1f8df0b..97f3c94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fast-scp" -version = "0.1.0" +version = "0.1.1" description = "A fast and simple scp CLI tool" license = "MIT" repository = "https://github.com/dcodesdev/fast-scp" diff --git a/src/scp.rs b/src/scp.rs index 0f6bfd5..6b8e10e 100644 --- a/src/scp.rs +++ b/src/scp.rs @@ -1,11 +1,12 @@ use futures::future::join_all; -use indicatif::ProgressBar; +use indicatif::{ProgressBar, ProgressStyle}; use ssh2::Session; use std::{ fs::{self, File}, io::{Read, Write}, net::TcpStream, path::PathBuf, + time::Duration, }; use crate::{error::ScpError, utils::with_retry}; @@ -32,6 +33,14 @@ impl Connect { let files = self.list(from)?; let pb = ProgressBar::new(files.len() as u64); + pb.set_style( + ProgressStyle::with_template( + "{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {pos}/{len} ({eta})", + ) + .unwrap() + .progress_chars("#>-"), + ); + pb.enable_steady_tick(Duration::from_millis(100)); let mut handles = Vec::new(); for item in files { @@ -53,7 +62,7 @@ impl Connect { let items = join_all(handles).await; if items.iter().all(|x| x.is_ok()) { - println!("Done in {:.2?}", start.elapsed()); + println!("\nDone in {:.2?}", start.elapsed()); Ok(()) } else { Err(std::io::Error::new(