summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2023-11-07 12:58:12 +0100
committerFxQnLr <[email protected]>2023-11-07 12:58:12 +0100
commit344af3ff7c9493b4e2c6eee134b9b341eaabf736 (patch)
treea6b0af984ac4e0d799ae6991635ca1980872f1ce /src/main.rs
parentf4d3d921460b606a9ff6686c9bb9a79bf546f264 (diff)
downloadwebol-cli-344af3ff7c9493b4e2c6eee134b9b341eaabf736.tar
webol-cli-344af3ff7c9493b4e2c6eee134b9b341eaabf736.tar.gz
webol-cli-344af3ff7c9493b4e2c6eee134b9b341eaabf736.zip
add ping support and readable output
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs28
1 files changed, 26 insertions, 2 deletions
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 @@
1use std::fmt::Display; 1use std::{fmt::Display, time::Duration};
2 2
3use clap::{Parser, Subcommand}; 3use clap::{Parser, Subcommand};
4use config::SETTINGS; 4use config::SETTINGS;
5use error::CliError; 5use error::CliError;
6use indicatif::{ProgressBar, ProgressStyle, MultiProgress};
6use requests::{start::start, device}; 7use requests::{start::start, device};
7use reqwest::header::{HeaderMap, HeaderValue}; 8use reqwest::header::{HeaderMap, HeaderValue};
8use serde::Deserialize; 9use serde::Deserialize;
@@ -11,7 +12,15 @@ mod config;
11mod error; 12mod error;
12mod requests; 13mod requests;
13 14
14/// webol http client 15static OVERVIEW_STYLE: &str = "{spinner:.green} {wide_msg}({elapsed})";
16static OVERVIEW_ERROR: &str = "✗ {wide_msg}({elapsed})";
17static OVERVIEW_DONE: &str = "✓ {wide_msg}({elapsed})";
18static DEFAULT_STYLE: &str = " {spinner:.green} {wide_msg}";
19static DONE_STYLE: &str = " ✓ {wide_msg}";
20static ERROR_STYLE: &str = " ✗ {wide_msg}";
21static TICK_SPEED: u64 = 1000 / 16;
22
23/// webol client
15#[derive(Parser)] 24#[derive(Parser)]
16#[command(author, version, about, long_about = None)] 25#[command(author, version, about, long_about = None)]
17struct Args { 26struct Args {
@@ -103,6 +112,21 @@ fn format_url(path: &str, protocol: Protocols) -> Result<String, CliError> {
103 )) 112 ))
104} 113}
105 114
115fn add_pb(mp: &MultiProgress, template: &str, message: String) -> ProgressBar {
116 let pb = mp.add(ProgressBar::new(1));
117 pb.set_style(ProgressStyle::with_template(template).unwrap());
118 pb.enable_steady_tick(Duration::from_millis(TICK_SPEED));
119 pb.set_message(message);
120
121 pb
122}
123
124fn finish_pb(pb: ProgressBar, message: String, template: &str) {
125 pb.set_style(ProgressStyle::with_template(template).unwrap());
126 pb.finish_with_message(message);
127
128}
129
106enum Protocols { 130enum Protocols {
107 Http, 131 Http,
108 Websocket, 132 Websocket,