From 344af3ff7c9493b4e2c6eee134b9b341eaabf736 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Tue, 7 Nov 2023 12:58:12 +0100 Subject: add ping support and readable output --- src/main.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 3e1388b..d7c985f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,9 @@ -use std::fmt::Display; +use std::{fmt::Display, time::Duration}; use clap::{Parser, Subcommand}; use config::SETTINGS; use error::CliError; +use indicatif::{ProgressBar, ProgressStyle, MultiProgress}; use requests::{start::start, device}; use reqwest::header::{HeaderMap, HeaderValue}; use serde::Deserialize; @@ -11,7 +12,15 @@ mod config; mod error; mod requests; -/// webol http client +static OVERVIEW_STYLE: &str = "{spinner:.green} {wide_msg}({elapsed})"; +static OVERVIEW_ERROR: &str = "✗ {wide_msg}({elapsed})"; +static OVERVIEW_DONE: &str = "✓ {wide_msg}({elapsed})"; +static DEFAULT_STYLE: &str = " {spinner:.green} {wide_msg}"; +static DONE_STYLE: &str = " ✓ {wide_msg}"; +static ERROR_STYLE: &str = " ✗ {wide_msg}"; +static TICK_SPEED: u64 = 1000 / 16; + +/// webol client #[derive(Parser)] #[command(author, version, about, long_about = None)] struct Args { @@ -103,6 +112,21 @@ fn format_url(path: &str, protocol: Protocols) -> Result { )) } +fn add_pb(mp: &MultiProgress, template: &str, message: String) -> ProgressBar { + let pb = mp.add(ProgressBar::new(1)); + pb.set_style(ProgressStyle::with_template(template).unwrap()); + pb.enable_steady_tick(Duration::from_millis(TICK_SPEED)); + pb.set_message(message); + + pb +} + +fn finish_pb(pb: ProgressBar, message: String, template: &str) { + pb.set_style(ProgressStyle::with_template(template).unwrap()); + pb.finish_with_message(message); + +} + enum Protocols { Http, Websocket, -- cgit v1.2.3