Skip to content

Commit

Permalink
better ui and update check
Browse files Browse the repository at this point in the history
  • Loading branch information
agrinman committed May 1, 2021
1 parent 0947924 commit 243a513
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 197 deletions.
63 changes: 61 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions tunnelto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tunnelto"
description = "expose your local web server to the internet with a public url"
version = "0.1.15"
version = "0.1.16"
authors = ["Alex Grinman <alex@tunnelto.dev>"]
edition = "2018"
license = "MIT"
Expand All @@ -13,7 +13,7 @@ name = "tunnelto"
path = "src/main.rs"

[dependencies]
tunnelto_lib = { version = "0.1.14", path = "../tunnelto_lib" }
tunnelto_lib = { version = "0.1.16", path = "../tunnelto_lib" }
tokio = { version = "1.0", features = ["full"] }
futures = "0.3"
serde = { version = "1.0", features = ["derive"] }
Expand All @@ -38,4 +38,6 @@ uuid = {version = "0.8.1", features = ["serde", "v4"] }
hyper = "0.14"
hyper-tls = "0.5"
http-body = "0.3.1"
serde_urlencoded = "0.6.1"
serde_urlencoded = "0.6.1"
reqwest = "0.11"
cli-table = "0.4"
100 changes: 100 additions & 0 deletions tunnelto/src/cli_ui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
use crate::introspect::IntrospectionAddrs;
use crate::Config;
use cli_table::format::Padding;
use cli_table::{format::Justify, print_stderr, Cell, Table};
use colored::Colorize;
use indicatif::{ProgressBar, ProgressStyle};

pub struct CliInterface {
spinner: ProgressBar,
config: Config,
introspect: IntrospectionAddrs,
}
impl CliInterface {
pub fn start(config: Config, introspect: IntrospectionAddrs) -> Self {
let spinner = new_spinner("Opening remote tunnel...");
Self {
spinner,
config,
introspect,
}
}

fn get_sub_domain_notice(&self, sub_domain: &str) -> Option<String> {
if self.config.sub_domain.is_some()
&& (self.config.sub_domain.as_ref().map(|s| s.as_str()) != Some(sub_domain))
{
if self.config.secret_key.is_some() {
Some(format!("{}",
"To use custom sub-domains feature, please upgrade your billing plan at https://dashboard.tunnelto.dev.".yellow()))
} else {
Some(format!("{}",
"To access the sub-domain feature, get your authentication key at https://dashboard.tunnelto.dev.".yellow()))
}
} else {
None
}
}

pub fn did_connect(&self, sub_domain: &str) {
self.spinner
.finish_with_message("Success! Remote tunnel is now open.\n".green().as_ref());

if !self.config.first_run {
return;
}

let public_url = self.config.activation_url(&sub_domain).bold().green();
let forward_url = self.config.forward_url();
let inspect = format!(
"http://localhost:{}",
self.introspect.web_explorer_address.port()
);

let table = vec![
vec![
"Public tunnel URL".green().cell(),
public_url
.green()
.cell()
.padding(Padding::builder().left(4).right(4).build())
.justify(Justify::Left),
],
vec![
"Local inspect dashboard".magenta().cell(),
inspect
.magenta()
.cell()
.padding(Padding::builder().left(4).build())
.justify(Justify::Left),
],
vec![
"Forwarding traffic to".cell(),
forward_url
.cell()
.padding(Padding::builder().left(4).build())
.justify(Justify::Left),
],
];

let table = table.table();
print_stderr(table).expect("failed to generate starting terminal user interface");

if let Some(notice) = self.get_sub_domain_notice(sub_domain) {
eprintln!("\n{}: {}\n", ">>> Notice".yellow(), notice);
}
}
}

fn new_spinner(message: &str) -> ProgressBar {
let pb = ProgressBar::new_spinner();
pb.enable_steady_tick(150);
pb.set_style(
ProgressStyle::default_spinner()
// .tick_strings(&["⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"])
.tick_strings(&["🌎", "🌍", "🌏"])
.template("{spinner:.blue} {msg}"),
);
pb.set_message(message);
pb
}
Loading

0 comments on commit 243a513

Please sign in to comment.