Skip to content

Commit

Permalink
added colored text for readability and transfer speed display
Browse files Browse the repository at this point in the history
  • Loading branch information
kernelPanic0x committed Dec 9, 2024
1 parent c00e94f commit 4002c74
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
26 changes: 19 additions & 7 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use std::{

use async_std::sync::Arc;
use clap::{Args, CommandFactory, Parser, Subcommand};
use color_eyre::{eyre, eyre::Context};
use color_eyre::{
eyre::{self, Context},
owo_colors::OwoColorize,
};
use completer::enter_code;
use console::{style, Term};
use futures::{future::Either, Future, FutureExt};
Expand Down Expand Up @@ -734,7 +737,7 @@ fn create_progress_bar(file_size: u64) -> ProgressBar {
pb.set_style(
ProgressStyle::default_bar()
// .template("[{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})")
.template("[{elapsed_precise}] [{wide_bar}] {bytes}/{total_bytes} ({eta})")
.template("[{elapsed_precise:.yellow}] [{wide_bar}] {bytes:.blue}/{total_bytes:.blue} {decimal_bytes_per_sec:.cyan} ({eta:.yellow})")
.unwrap()
.progress_chars("#>-"),
);
Expand All @@ -748,6 +751,7 @@ fn create_progress_handler(pb: ProgressBar) -> impl FnMut(u64, u64) {
pb.set_length(total);
pb.enable_steady_tick(std::time::Duration::from_millis(250));
}

pb.set_position(sent);
}
}
Expand Down Expand Up @@ -1020,12 +1024,12 @@ async fn receive_inner_v1(
|| util::ask_user(
format!(
"Receive file '{}' ({})?",
req.file_name(),
req.file_name().green(),
match NumberPrefix::binary(req.file_size() as f64) {
NumberPrefix::Standalone(bytes) => format!("{} bytes", bytes),
NumberPrefix::Prefixed(prefix, n) =>
format!("{:.1} {}B in size", n, prefix.symbol()),
},
NumberPrefix::Prefixed(prefix, n) => format!("{:.1} {}B", n, prefix.symbol()),
}
.blue(),
),
true,
)
Expand Down Expand Up @@ -1060,7 +1064,7 @@ async fn receive_inner_v1(

/* If there is a collision, ask whether to overwrite */
if !util::ask_user(
format!("Override existing file {}?", file_path.display()),
format!("Override existing file {}?", file_path.display()).red(),
false,
)
.await
Expand Down Expand Up @@ -1184,6 +1188,14 @@ async fn receive_inner_v2(

fn transit_handler(info: TransitInfo) {
tracing::info!("{info}");
let mut term = Term::stdout();

let _ = writeln!(
term,
"Connecting {} to {}",
info.conn_type.bright_magenta(),
info.peer_addr.cyan()
);
}

#[cfg(test)]
Expand Down
10 changes: 10 additions & 0 deletions src/transit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,16 @@ pub enum ConnectionType {
},
}

impl std::fmt::Display for ConnectionType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ConnectionType::Direct => write!(f, "directly"),
ConnectionType::Relay { name: Some(name) } => write!(f, "via relay ({})", name),
ConnectionType::Relay { name: None } => write!(f, "via relay"),
}
}
}

/// Metadata for the established transit connection
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
Expand Down

0 comments on commit 4002c74

Please sign in to comment.