Skip to content

Commit

Permalink
style: move instant speed readout to the right, remove %age
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyscot committed Nov 2, 2024
1 parent 2931cce commit d912a0d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ For example:

```bash
$ qcp my-server:/tmp/testfile /tmp/
⠂ Transferring data, instant rate: 2.1MB/s
testfile ████████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░ 1s @ 6.71 MB/s [60%/10.49 MB]
⠂ Transferring data 2.1MB/s (last 1s)
testfile ████████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░ 1s @ 6.71 MB/s [10.49 MB]
```

**The program uses the ssh binary on your system to connect to the target machine**.
Expand Down
3 changes: 2 additions & 1 deletion src/client/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// (c) 2024 Ross Younger

use crate::client::control::Channel;
use crate::client::progress::spinner_style;
use crate::protocol::session::Status;
use crate::protocol::session::{FileHeader, FileTrailer, Response};
use crate::protocol::{RawStreamPair, StreamPair};
Expand Down Expand Up @@ -70,7 +71,7 @@ pub async fn client_main(
let spinner = if options.quiet {
ProgressBar::hidden()
} else {
display.add(ProgressBar::new_spinner())
display.add(ProgressBar::new_spinner().with_style(spinner_style()?))
};
spinner.enable_steady_tick(Duration::from_millis(150));
spinner.set_message("Establishing data channel");
Expand Down
7 changes: 2 additions & 5 deletions src/client/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,8 @@ impl InstaMeterInner {
let elapsed = elapsed.as_secs_f64();
let rate = progress / elapsed;
self.previous_position = current;
let msg = format!(
"Transferring data, instant rate: {}",
rate.human_throughput_bytes()
);
self.destination.set_message(msg.clone());
let msg = format!("{} (last 1s)", rate.human_throughput_bytes());
self.destination.set_prefix(msg.clone());
self.destination
.enable_steady_tick(self.tick_calc.tick_time(progress));
msg
Expand Down
11 changes: 9 additions & 2 deletions src/client/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
pub const MAX_UPDATE_FPS: u8 = 20;

use console::Term;
use indicatif::ProgressStyle;

const PROGRESS_STYLE_COMPACT: &str =
"{msg:.dim} {wide_bar:.cyan} {eta} @ {decimal_bytes_per_sec} [{percent}%/{decimal_total_bytes:.dim}]";
"{msg:.dim} {wide_bar:.cyan} {eta} @ {decimal_bytes_per_sec} [{decimal_total_bytes:.dim}]";

// 11111111111111111111111111111111111111111111111111111111111111111111111111111111
// filename [========================== ] 2m30s @ 123.4MB/s [70%/1.24GB]
Expand All @@ -26,7 +27,7 @@ const DATA_AND_PROGRESS: usize = 55;
// 11111111111111111111111111111111111111111111111111111111111111111111111111111111

const PROGRESS_STYLE_OVERLONG: &str =
"{wide_msg:.dim} [{percent}%/{decimal_total_bytes:.dim}]\n{wide_bar:.cyan} {eta} @ {decimal_bytes_per_sec}";
"{wide_msg:.dim} [{decimal_total_bytes:.dim}]\n{wide_bar:.cyan} {eta} @ {decimal_bytes_per_sec}";

fn use_long_style(terminal: &Term, msg_size: usize) -> bool {
let term_width = terminal.size().1 as usize; // this returns a reasonable default if it can't detect
Expand All @@ -40,3 +41,9 @@ pub(crate) fn progress_style_for(terminal: &Term, msg_size: usize) -> &str {
PROGRESS_STYLE_COMPACT
}
}

pub(crate) const SPINNER_TEMPLATE: &str = "{spinner} {wide_msg} {prefix}";

pub(crate) fn spinner_style() -> anyhow::Result<ProgressStyle> {
Ok(ProgressStyle::with_template(SPINNER_TEMPLATE)?)
}

0 comments on commit d912a0d

Please sign in to comment.