Skip to content

Commit 4002c74

Browse files
committed
added colored text for readability and transfer speed display
1 parent c00e94f commit 4002c74

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

cli/src/main.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ use std::{
99

1010
use async_std::sync::Arc;
1111
use clap::{Args, CommandFactory, Parser, Subcommand};
12-
use color_eyre::{eyre, eyre::Context};
12+
use color_eyre::{
13+
eyre::{self, Context},
14+
owo_colors::OwoColorize,
15+
};
1316
use completer::enter_code;
1417
use console::{style, Term};
1518
use futures::{future::Either, Future, FutureExt};
@@ -734,7 +737,7 @@ fn create_progress_bar(file_size: u64) -> ProgressBar {
734737
pb.set_style(
735738
ProgressStyle::default_bar()
736739
// .template("[{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})")
737-
.template("[{elapsed_precise}] [{wide_bar}] {bytes}/{total_bytes} ({eta})")
740+
.template("[{elapsed_precise:.yellow}] [{wide_bar}] {bytes:.blue}/{total_bytes:.blue} {decimal_bytes_per_sec:.cyan} ({eta:.yellow})")
738741
.unwrap()
739742
.progress_chars("#>-"),
740743
);
@@ -748,6 +751,7 @@ fn create_progress_handler(pb: ProgressBar) -> impl FnMut(u64, u64) {
748751
pb.set_length(total);
749752
pb.enable_steady_tick(std::time::Duration::from_millis(250));
750753
}
754+
751755
pb.set_position(sent);
752756
}
753757
}
@@ -1020,12 +1024,12 @@ async fn receive_inner_v1(
10201024
|| util::ask_user(
10211025
format!(
10221026
"Receive file '{}' ({})?",
1023-
req.file_name(),
1027+
req.file_name().green(),
10241028
match NumberPrefix::binary(req.file_size() as f64) {
10251029
NumberPrefix::Standalone(bytes) => format!("{} bytes", bytes),
1026-
NumberPrefix::Prefixed(prefix, n) =>
1027-
format!("{:.1} {}B in size", n, prefix.symbol()),
1028-
},
1030+
NumberPrefix::Prefixed(prefix, n) => format!("{:.1} {}B", n, prefix.symbol()),
1031+
}
1032+
.blue(),
10291033
),
10301034
true,
10311035
)
@@ -1060,7 +1064,7 @@ async fn receive_inner_v1(
10601064

10611065
/* If there is a collision, ask whether to overwrite */
10621066
if !util::ask_user(
1063-
format!("Override existing file {}?", file_path.display()),
1067+
format!("Override existing file {}?", file_path.display()).red(),
10641068
false,
10651069
)
10661070
.await
@@ -1184,6 +1188,14 @@ async fn receive_inner_v2(
11841188

11851189
fn transit_handler(info: TransitInfo) {
11861190
tracing::info!("{info}");
1191+
let mut term = Term::stdout();
1192+
1193+
let _ = writeln!(
1194+
term,
1195+
"Connecting {} to {}",
1196+
info.conn_type.bright_magenta(),
1197+
info.peer_addr.cyan()
1198+
);
11871199
}
11881200

11891201
#[cfg(test)]

src/transit.rs

+10
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,16 @@ pub enum ConnectionType {
665665
},
666666
}
667667

668+
impl std::fmt::Display for ConnectionType {
669+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
670+
match self {
671+
ConnectionType::Direct => write!(f, "directly"),
672+
ConnectionType::Relay { name: Some(name) } => write!(f, "via relay ({})", name),
673+
ConnectionType::Relay { name: None } => write!(f, "via relay"),
674+
}
675+
}
676+
}
677+
668678
/// Metadata for the established transit connection
669679
#[derive(Clone, Debug, Eq, PartialEq)]
670680
#[non_exhaustive]

0 commit comments

Comments
 (0)