-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
329 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "bping" | ||
version = "2.0.5" | ||
version = "2.1.0" | ||
description = "A command line utility to ping a website from anywhere in the world!" | ||
authors = ["Firaenix <[email protected]>"] | ||
edition = "2021" | ||
|
@@ -52,7 +52,8 @@ bpaf = { version = "0.9.15", features = [ | |
"autocomplete", | ||
"batteries", | ||
] } | ||
tracing = "0.1.40" | ||
tracing-subscriber = "0.3.18" | ||
tracing = { version = "0.1", features = ["async-await"] } | ||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } | ||
rand = "0.8.5" | ||
regress = "0.10.1" | ||
tokio-retry = "0.3.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
mod ping_display; | ||
mod print; | ||
// mod progress_bar; | ||
|
||
pub use print::*; | ||
// pub use progress_bar::*; | ||
mod progress; | ||
pub use progress::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use color_eyre::eyre::Result; | ||
// progress.rs | ||
use indicatif::{ProgressBar, ProgressStyle}; | ||
use std::sync::atomic::{AtomicUsize, Ordering}; | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
use tokio::sync::mpsc::{self, Receiver, Sender}; | ||
use tokio::task::JoinHandle; | ||
|
||
use crate::display::display_job; | ||
use crate::models::types::PerformIcmpResponse; | ||
use crate::options::Opts; | ||
|
||
pub struct ProgressDisplay { | ||
bar: ProgressBar, | ||
config: &'static Opts, | ||
|
||
rx: Receiver<PerformIcmpResponse>, | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct ProgressUpdater { | ||
bar: ProgressBar, | ||
tx: Sender<PerformIcmpResponse>, | ||
} | ||
|
||
impl Drop for ProgressUpdater { | ||
fn drop(&mut self) { | ||
self.bar.finish_with_message("Completed"); | ||
} | ||
} | ||
|
||
impl ProgressUpdater { | ||
pub(crate) async fn display_job( | ||
&self, | ||
job: progenitor::progenitor_client::ResponseValue< | ||
crate::models::types::PerformIcmpResponse, | ||
>, | ||
) { | ||
let _ = self.tx.send(job.into_inner()).await; | ||
self.bar.inc(1); | ||
} | ||
} | ||
|
||
impl ProgressDisplay { | ||
pub fn new(config: &'static Opts) -> Result<(Self, ProgressUpdater)> { | ||
let mut spinner_style = ProgressStyle::default_spinner() | ||
.tick_chars("-\\|/") | ||
.template("{spinner:.green} {msg:.cyan/blue} [{elapsed_precise}] {pos}/{len}")?; | ||
|
||
let bar = ProgressBar::new((config.attempts * config.regions.len()) as u64); | ||
|
||
let world_ticker = format!("{}", console::Emoji("🌍🌍🌎🌎🌏🌏🌎🌎🌍🌍", "-\\|/")); | ||
spinner_style = spinner_style.tick_chars(&world_ticker); | ||
bar.enable_steady_tick(Duration::from_millis(350)); | ||
|
||
bar.set_style(spinner_style); | ||
|
||
let (tx, rx) = mpsc::channel(config.concurrency); | ||
|
||
Ok(( | ||
Self { | ||
bar: bar.clone(), | ||
config, | ||
rx, | ||
}, | ||
ProgressUpdater { bar, tx }, | ||
)) | ||
} | ||
|
||
pub async fn display_job_thread(&mut self) { | ||
while let Some(x) = self.rx.recv().await { | ||
display_job(&self.bar, self.config, x).await; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.