diff options
author | FxQnLr <[email protected]> | 2023-11-07 12:58:12 +0100 |
---|---|---|
committer | FxQnLr <[email protected]> | 2023-11-07 12:58:12 +0100 |
commit | 344af3ff7c9493b4e2c6eee134b9b341eaabf736 (patch) | |
tree | a6b0af984ac4e0d799ae6991635ca1980872f1ce /src/main.rs | |
parent | f4d3d921460b606a9ff6686c9bb9a79bf546f264 (diff) | |
download | webol-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.rs | 28 |
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 @@ | |||
1 | use std::fmt::Display; | 1 | use std::{fmt::Display, time::Duration}; |
2 | 2 | ||
3 | use clap::{Parser, Subcommand}; | 3 | use clap::{Parser, Subcommand}; |
4 | use config::SETTINGS; | 4 | use config::SETTINGS; |
5 | use error::CliError; | 5 | use error::CliError; |
6 | use indicatif::{ProgressBar, ProgressStyle, MultiProgress}; | ||
6 | use requests::{start::start, device}; | 7 | use requests::{start::start, device}; |
7 | use reqwest::header::{HeaderMap, HeaderValue}; | 8 | use reqwest::header::{HeaderMap, HeaderValue}; |
8 | use serde::Deserialize; | 9 | use serde::Deserialize; |
@@ -11,7 +12,15 @@ mod config; | |||
11 | mod error; | 12 | mod error; |
12 | mod requests; | 13 | mod requests; |
13 | 14 | ||
14 | /// webol http client | 15 | static OVERVIEW_STYLE: &str = "{spinner:.green} {wide_msg}({elapsed})"; |
16 | static OVERVIEW_ERROR: &str = "✗ {wide_msg}({elapsed})"; | ||
17 | static OVERVIEW_DONE: &str = "✓ {wide_msg}({elapsed})"; | ||
18 | static DEFAULT_STYLE: &str = " {spinner:.green} {wide_msg}"; | ||
19 | static DONE_STYLE: &str = " ✓ {wide_msg}"; | ||
20 | static ERROR_STYLE: &str = " ✗ {wide_msg}"; | ||
21 | static 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)] |
17 | struct Args { | 26 | struct Args { |
@@ -103,6 +112,21 @@ fn format_url(path: &str, protocol: Protocols) -> Result<String, CliError> { | |||
103 | )) | 112 | )) |
104 | } | 113 | } |
105 | 114 | ||
115 | fn 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 | |||
124 | fn 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 | |||
106 | enum Protocols { | 130 | enum Protocols { |
107 | Http, | 131 | Http, |
108 | Websocket, | 132 | Websocket, |